diff --git a/promo/app/controllers/spree/store_controller_decorator.rb b/promo/app/controllers/spree/store_controller_decorator.rb index aabe1c233e3..9a32c3e6561 100644 --- a/promo/app/controllers/spree/store_controller_decorator.rb +++ b/promo/app/controllers/spree/store_controller_decorator.rb @@ -26,14 +26,23 @@ def apply_coupon_code previous_promo = @order.adjustments.promotion.eligible.first fire_event(event_name, :coupon_code => @order.coupon_code) + exclusion_rule = promotion.rules.select{|rule| rule.kind_of? Spree::Promotion::Rules::ProductExclusion}.first + exclusion_eligible_products = exclusion_rule.eligible_products.map(&:name) if exclusion_rule.present? promo = @order.adjustments.promotion.detect { |p| p.originator.promotion.code == @order.coupon_code } - if promo.present? and promo.eligible flash[:success] = t(:coupon_code_applied) true elsif previous_promo.present? and promo.present? flash[:error] = t(:coupon_code_better_exists) false + elsif (exclusion_rule.present? and !exclusion_rule.eligible?(@order)) + items = exclusion_eligible_products && @order.products.map(&:name) + if promo.id == 89 + flash["product-exclusion-preorder-warning"] = "#{t(:coupon_code_not_for_preorders)}, #{t(:go_back_to)} #{t(:shopping_cart)} #{t(:remove_items)}: #{items.join(', ')}".html_safe + else + flash["product-exclusion-warning"] = "#{t(:product_exclusion_rule_warning)} #{t(:listed_items)}: #{items.join(', ')}" + end + false elsif promo.present? flash[:error] = t(:coupon_code_not_eligible) false diff --git a/promo/config/locales/en.yml b/promo/config/locales/en.yml index 894bfe46e52..6a2b0e946ca 100644 --- a/promo/config/locales/en.yml +++ b/promo/config/locales/en.yml @@ -22,10 +22,16 @@ en: coupon_code_already_applied: The coupon code has already been applied to this order coupon_code_better_exists: The previously applied coupon code results in a better deal coupon_code_not_found: The coupon code you entered doesn't exist. Please try again. + coupon_code_not_for_preorders: Oops! The Free Shipping coupon doesn't apply to the new pre-order items in your cart. You will need to place a separate order for the pre-order items. To get the Free Shipping discount on this order coupon_code_max_usage: Coupon code usage limit exceeded coupon_code_not_eligible: This coupon code is not eligible for this order + product_exclusion_rule_warning: Oops! Your cart contains item(s) that will not work with this promotion. + listed_items: The listed item(s) must be removed before the discount can apply editing_promotion: Editing Promotion current_promotion_usage: 'Current Usage: %{count}' + go_back_to: please go back to the + remove_items: and remove the following items + shopping_cart: Shopping Cart events: spree: checkout: