Remove variant from cart when it becomes out of stock

This commit is contained in:
Rohan Mitchell
2016-04-08 11:19:34 +10:00
parent 792e17c385
commit 8695dea0a5
2 changed files with 15 additions and 0 deletions

View File

@@ -60,6 +60,8 @@ Spree::OrderPopulator.class_eval do
if quantity_to_add > 0
@order.add_variant(variant, quantity_to_add, max_quantity_to_add, currency)
else
@order.remove_variant variant
end
end
end

View File

@@ -177,6 +177,19 @@ module Spree
op.attempt_cart_add(333, quantity.to_s, quantity.to_s)
end
it "removes variants which have become out of stock" do
op.should_receive(:quantities_to_add).with(variant, 123, 123).
and_return([0, 0])
op.stub(:check_order_cycle_provided_for) { true }
op.stub(:check_variant_available_under_distribution) { true }
order.should_receive(:remove_variant).with(variant)
order.should_receive(:add_variant).never
op.attempt_cart_add(333, quantity.to_s, quantity.to_s)
end
end
describe "quantities_to_add" do