Do not show deleted products on shopfront

This commit is contained in:
Rohan Mitchell
2014-04-02 14:13:06 +11:00
parent 87a43fc36e
commit 19ca8e142a
2 changed files with 9 additions and 2 deletions

View File

@@ -10,7 +10,7 @@ class Shop::ShopController < BaseController
def products
unless @products = current_order_cycle.andand
.valid_products_distributed_by(current_distributor).andand
.select { |p| p.has_stock_for_distribution?(current_order_cycle, current_distributor) }.andand
.select { |p| !p.deleted? && p.has_stock_for_distribution?(current_order_cycle, current_distributor) }.andand
.sort_by {|p| p.name }
render json: "", status: 404

View File

@@ -143,13 +143,14 @@ feature "As a consumer I want to shop with a distributor", js: true do
end
end
describe "filtering on hand and on demand products" do
describe "filtering products" do
let(:oc) { create(:simple_order_cycle, distributors: [distributor]) }
let(:p1) { create(:simple_product, on_demand: false) }
let(:p2) { create(:simple_product, on_demand: true) }
let(:p3) { create(:simple_product, on_demand: false) }
let(:p4) { create(:simple_product, on_demand: false) }
let(:p5) { create(:simple_product, on_demand: false) }
let(:p6) { create(:simple_product, on_demand: false) }
let(:v1) { create(:variant, product: p4, unit_value: 2) }
let(:v2) { create(:variant, product: p4, unit_value: 3, on_demand: false) }
let(:v3) { create(:variant, product: p4, unit_value: 4, on_demand: true) }
@@ -162,6 +163,8 @@ feature "As a consumer I want to shop with a distributor", js: true do
p1.master.update_attribute(:count_on_hand, 1)
p2.master.update_attribute(:count_on_hand, 0)
p3.master.update_attribute(:count_on_hand, 0)
p6.master.update_attribute(:count_on_hand, 1)
p6.delete
v1.update_attribute(:count_on_hand, 1)
v2.update_attribute(:count_on_hand, 0)
v3.update_attribute(:count_on_hand, 0)
@@ -172,6 +175,7 @@ feature "As a consumer I want to shop with a distributor", js: true do
exchange.variants << p1.master
exchange.variants << p2.master
exchange.variants << p3.master
exchange.variants << p6.master
exchange.variants << v1
exchange.variants << v2
exchange.variants << v3
@@ -203,6 +207,9 @@ feature "As a consumer I want to shop with a distributor", js: true do
# It does not show products that have no available variants in this distribution
page.should_not have_content p5.name
# It does not show deleted products
page.should_not have_content p6.name
end
end