mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
When loading distributors for sidebar, only show those that have active products on hand
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_on_hand.by_name
|
||||
@distributors = Spree::Distributor.with_active_products_on_hand.by_name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ module Spree
|
||||
validates_associated :pickup_address
|
||||
|
||||
scope :by_name, order('name')
|
||||
scope :with_products_on_hand, joins(:products).where('spree_products.count_on_hand > 0').select('distinct(distributors.*)')
|
||||
scope :with_active_products_on_hand, lambda { joins(:products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(distributors.*)') }
|
||||
|
||||
after_initialize :initialize_country
|
||||
before_validation :set_unused_address_fields
|
||||
|
||||
@@ -28,7 +28,7 @@ module Spree
|
||||
create(:product, :distributors => [d1], :on_hand => 5)
|
||||
create(:product, :distributors => [d3], :on_hand => 0)
|
||||
|
||||
Distributor.with_products_on_hand.sort.should == [d1, d2]
|
||||
Distributor.with_active_products_on_hand.sort.should == [d1, d2]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user