Add a product with variants to the cart with max quantity for a group buy

This commit is contained in:
Rohan Mitchell
2012-08-03 18:05:45 +10:00
parent 2d89640271
commit f3ffba378a
2 changed files with 27 additions and 3 deletions

View File

@@ -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

View File

@@ -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)