Skip to content

Instantly share code, notes, and snippets.

@alininja
Created September 3, 2012 17:51
Show Gist options
  • Save alininja/3611336 to your computer and use it in GitHub Desktop.
Save alininja/3611336 to your computer and use it in GitHub Desktop.
Validate Promotions
Spree::CheckoutController.class_eval do
require_dependency 'spree/order_decorator'
rescue_from Spree::Order::CouldNotValidateMailingListPromoCode do |exception|
flash[:error] = t(exception.message)
redirect_to checkout_state_path(@order.state)
end
end
Spree::Order.class_eval do
def validate_coupons
multiple_promos = false
adjustments.reorder('amount ASC').promo.each_with_index do |adjustment, index|
unless index == 0
adjustment.destroy
save!
multiple_promos = true
end
end
raise CouldNotValidateMailingListPromoCode, 'promotion_rule_types.on_mailing_list.used_promo' if multiple_promos
end
def process_payments!
validate_coupons #this method call should be placed elsewhere
ret = payments.each(&:process!)
end
class Spree::Order::CouldNotValidateMailingListPromoCode < StandardError
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment