Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Per-item calculator now only applies to products matching the promotion

Fixes #1526
  • Loading branch information...
commit 1399730032951ad1ad1d98863bc96fa9144cbeb1 1 parent 2f1c30a
Andrea Schiavini authored radar committed
Showing with 53 additions and 0 deletions.
  1. +53 −0 promo/spec/requests/promotion_adjustments_spec.rb
View
53 promo/spec/requests/promotion_adjustments_spec.rb
@@ -482,5 +482,58 @@ def do_checkout
fill_in "card_code", :with => "123"
click_button "Save and Continue"
end
+
+ def create_per_product_promotion product_name, discount_amount
+ visit spree.admin_path
+ click_link "Promotions"
+ click_link "New Promotion"
+ fill_in "Name", :with => "Bundle"
+ select "Add to cart", :from => "Event"
+ click_button "Create"
+ page.should have_content("Editing Promotion")
+
+ # add product_name to last promotion
+ promotion = Spree::Promotion.last
+ promotion.rules << Spree::Promotion::Rules::Product.new()
+ product = Spree::Product.find_by_name(product_name)
+ rule = promotion.rules.last
+ rule.products << product
+ if rule.save
+ puts "Created promotion: new price for #{product_name} is #{product.price - discount_amount} (was #{product.price})"
+ else
+ puts "Failed to create promotion: price for #{product_name} is still #{product.price}"
+ end
+
+ select "Create adjustment", :from => "Add action of type"
+ within('#action_fields') { click_button "Add" }
+ select "Flat Rate (per item)", :from => "Calculator"
+ within('#actions_container') { click_button "Update" }
+ within('.calculator-fields') { fill_in "Amount", :with => discount_amount.to_s }
+ within('#actions_container') { click_button "Update" }
+ end
+
+ def add_to_cart product_name
+ visit spree.root_path
+ click_link product_name
+ click_button "Add To Cart"
+ end
+
+ def do_checkout
+ click_link "Checkout"
+ str_addr = "bill_address"
+ select "United States", :from => "order_#{str_addr}_attributes_country_id"
+ ['firstname', 'lastname', 'address1', 'city', 'zipcode', 'phone'].each do |field|
+ fill_in "order_#{str_addr}_attributes_#{field}", :with => "#{address.send(field)}"
+ end
+ select "#{address.state.name}", :from => "order_#{str_addr}_attributes_state_id"
+ check "order_use_billing"
+ click_button "Save and Continue"
+ click_button "Save and Continue"
+ choose('Credit Card')
+ fill_in "card_number", :with => "4111111111111111"
+ fill_in "card_code", :with => "123"
+ click_button "Save and Continue"
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.