Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove only_one_promotion_per_product validate form #3

Open
wants to merge 1 commit into
base: 1-3-stableish
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions promo/app/models/spree/promotion/rules/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Promotion
module Rules
class Product < PromotionRule
has_and_belongs_to_many :products, :class_name => '::Spree::Product', :join_table => 'spree_products_promotion_rules', :foreign_key => 'promotion_rule_id'
validate :only_one_promotion_per_product

MATCH_POLICIES = %w(any all)
preference :match_policy, :string, :default => MATCH_POLICIES.first
Expand All @@ -33,13 +32,6 @@ def product_ids_string=(s)
self.product_ids = s.to_s.split(',').map(&:strip)
end

private

def only_one_promotion_per_product
if Spree::Promotion::Rules::Product.all.map(&:products).flatten.uniq!
errors[:base] << "You can't create two promotions for the same product"
end
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions promo/spec/requests/promotion_adjustments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,20 @@
Spree::Order.last.total.to_f.should == 54.00
end

it "should pick the best promotion when two promotions exist for the same product" do
create_per_product_promotion("RoR Mug", 5.0)
add_to_cart "RoR Mug"
Spree::Order.last.total.to_f.should == 35.00

create_per_product_promotion("RoR Mug", 10.0)
Spree::Activator.active.event_name_starts_with('spree.cart.add').size.should == 2

update_first_item_quantity 0
add_to_cart "RoR Mug"

Spree::Order.last.total.to_f.should == 30.00
end

def add_to_cart product_name
visit spree.root_path
click_link product_name
Expand Down