mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Add a product with variants to the cart with max quantity for a group buy
This commit is contained in:
@@ -16,14 +16,18 @@ Spree::OrdersController.class_eval do
|
||||
end
|
||||
|
||||
def populate_variant_attributes
|
||||
puts "params: #{params.inspect}"
|
||||
puts "Has key variant_attributes? #{params.key?(:variant_attributes)}"
|
||||
if params.key? :variant_attributes
|
||||
params[:variant_attributes].each do |variant_id, attributes|
|
||||
puts "Setting variant attributes for variant #{variant_id}, attributes: #{attributes.inspect}"
|
||||
@order.set_variant_attributes(Spree::Variant.find(variant_id), attributes)
|
||||
end
|
||||
end
|
||||
|
||||
if params.key? :quantity
|
||||
params[:products].each do |product_id, variant_id|
|
||||
max_quantity = params[:max_quantity].to_i
|
||||
@order.set_variant_attributes(Spree::Variant.find(variant_id), {:max_quantity => max_quantity})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -125,6 +125,26 @@ feature %q{
|
||||
li.max_quantity.should == 3
|
||||
end
|
||||
|
||||
scenario "adding a product with variants to the cart for a group buy" do
|
||||
# Given a group buy product with variants and a distributor
|
||||
d = create(:distributor)
|
||||
p = create(:product, :distributors => [d], :group_buy => true)
|
||||
create(:variant, :product => p)
|
||||
|
||||
# When I add the item to my cart
|
||||
visit spree.product_path p
|
||||
fill_in "quantity", :with => 2
|
||||
fill_in "max_quantity", :with => 3
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then the item should be in my cart with correct quantities
|
||||
order = Spree::Order.last
|
||||
li = order.line_items.first
|
||||
li.product.should == p
|
||||
li.quantity.should == 2
|
||||
li.max_quantity.should == 3
|
||||
end
|
||||
|
||||
scenario "adding a product to cart that is not a group buy does not show max quantity field" do
|
||||
# Given a group buy product and a distributor
|
||||
d = create(:distributor)
|
||||
|
||||
Reference in New Issue
Block a user