mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Change set_variant_attribute to set_variant_attributes, implement it on Order
This commit is contained in:
@@ -18,9 +18,7 @@ Spree::OrdersController.class_eval do
|
||||
def populate_variant_attributes
|
||||
if params.key? :variant_attributes
|
||||
params[:variant_attributes].each do |variant_id, attributes|
|
||||
attributes.each do |k, v|
|
||||
@order.set_variant_attribute(Spree::Variant.find(variant_id), k, v)
|
||||
end
|
||||
@order.set_variant_attributes(Spree::Variant.find(variant_id), attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
Spree::LineItem.class_eval do
|
||||
attr_accessible :max_quantity
|
||||
|
||||
def shipping_method
|
||||
self.product.shipping_method_for_distributor(self.order.distributor)
|
||||
end
|
||||
|
||||
@@ -15,6 +15,13 @@ Spree::Order.class_eval do
|
||||
can_change_distributor? || product.distributors.include?(distributor)
|
||||
end
|
||||
|
||||
def set_variant_attributes(variant, attributes)
|
||||
line_item = contains?(variant)
|
||||
|
||||
line_item.assign_attributes(attributes)
|
||||
line_item.save!
|
||||
end
|
||||
|
||||
|
||||
|
||||
before_validation :shipping_address_from_distributor
|
||||
|
||||
@@ -116,7 +116,7 @@ describe Spree::OrdersController do
|
||||
p = create(:product, :distributors => [distributor_product], :group_buy => true)
|
||||
|
||||
order = current_order(true)
|
||||
order.should_receive(:set_variant_attribute).with(p.master, 'max_quantity', '3')
|
||||
order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'})
|
||||
controller.stub(:current_order).and_return(order)
|
||||
|
||||
expect do
|
||||
|
||||
@@ -46,4 +46,17 @@ describe Spree::Order do
|
||||
# And cannot be added if it does not match
|
||||
subject.can_add_product_to_cart?(p_subsequent_other_dist).should be_false
|
||||
end
|
||||
|
||||
it "sets attributes on line items for variants" do
|
||||
subject.save!
|
||||
d = create(:distributor)
|
||||
p = create(:product, :distributors => [d])
|
||||
|
||||
subject.distributor = d
|
||||
subject.add_variant(p.master, 1)
|
||||
subject.set_variant_attributes(p.master, {'max_quantity' => '3'})
|
||||
|
||||
li = Spree::LineItem.last
|
||||
li.max_quantity.should == 3
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user