Skip to content
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
11 changes: 10 additions & 1 deletion promo/app/controllers/spree/store_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)} <a href='#{spree.cart_path}'>#{t(:shopping_cart)}</a> #{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
Expand Down
6 changes: 6 additions & 0 deletions promo/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down