mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add method to remove a variant from an order
This commit is contained in:
@@ -102,6 +102,13 @@ Spree::Order.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def remove_variant(variant)
|
||||
line_items(:reload)
|
||||
current_item = find_line_item_by_variant(variant)
|
||||
current_item.destroy
|
||||
end
|
||||
|
||||
|
||||
# Overridden to support max_quantity
|
||||
def add_variant(variant, quantity = 1, max_quantity = nil, currency = nil)
|
||||
line_items(:reload)
|
||||
|
||||
@@ -329,6 +329,22 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
|
||||
describe "removing an item from the order" do
|
||||
let(:order) { create(:order) }
|
||||
let(:v1) { create(:variant) }
|
||||
let(:v2) { create(:variant) }
|
||||
|
||||
before do
|
||||
order.add_variant v1
|
||||
order.add_variant v2
|
||||
end
|
||||
|
||||
it "removes the variant's line item" do
|
||||
order.remove_variant v1
|
||||
order.line_items(:reload).map(&:variant).should == [v2]
|
||||
end
|
||||
end
|
||||
|
||||
describe "emptying the order" do
|
||||
it "removes shipping method" do
|
||||
subject.shipping_method = create(:shipping_method)
|
||||
|
||||
Reference in New Issue
Block a user