mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Only show distributors in sidebar that have products in stock
This commit is contained in:
@@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base
|
||||
private
|
||||
def load_data_for_sidebar
|
||||
@suppliers = Spree::Supplier.all
|
||||
@distributors = Spree::Distributor.with_products
|
||||
@distributors = Spree::Distributor.with_products_on_hand
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ module Spree
|
||||
validates_associated :pickup_address
|
||||
|
||||
scope :by_name, order('name')
|
||||
scope :with_products, joins(:products).group('distributors.id')
|
||||
scope :with_products_on_hand, joins(:products).where('spree_products.count_on_hand > 0').group('distributors.id')
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
@@ -40,6 +40,7 @@ end
|
||||
FactoryGirl.modify do
|
||||
factory :simple_product do
|
||||
supplier { Spree::Supplier.first || FactoryGirl.create(:supplier) }
|
||||
on_hand 3
|
||||
|
||||
# before(:create) do |product, evaluator|
|
||||
# product.product_distributions = [FactoryGirl.create(:product_distribution, :product => product)]
|
||||
|
||||
@@ -19,14 +19,16 @@ module Spree
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
it "returns distributors with products" do
|
||||
it "returns distributors with products in stock" do
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d3 = create(:distributor)
|
||||
create(:product, :distributors => [d1, d2])
|
||||
create(:product, :distributors => [d1])
|
||||
d4 = create(:distributor)
|
||||
create(:product, :distributors => [d1, d2], :on_hand => 5)
|
||||
create(:product, :distributors => [d1], :on_hand => 5)
|
||||
create(:product, :distributors => [d3], :on_hand => 0)
|
||||
|
||||
Distributor.with_products.sort.should == [d1, d2]
|
||||
Distributor.with_products_on_hand.sort.should == [d1, d2]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user