When loading distributors for sidebar, only show those that have active products on hand

This commit is contained in:
Rohan Mitchell
2012-08-04 17:51:08 +10:00
parent f0ec3080e4
commit 9f013f0e37
3 changed files with 3 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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