Created
September 3, 2012 17:51
-
-
Save alininja/3611336 to your computer and use it in GitHub Desktop.
Validate Promotions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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