Created
March 5, 2014 21:52
-
-
Save HoyaBoya/9377392 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## | |
# This is spree 2-1-stable specific logic to re-apply a promotion code. It will not work for 2-2-stable because promotions are being revamped. | |
# https://github.com/spree/spree/issues/4398 | |
# | |
def reapply_coupon_codes | |
codes = [] | |
# Go through the adjustments to find promotions that are not eligible | |
adjustments.each do |a| | |
if a.eligible == false && a.originator.respond_to?(:promotion) && a.originator.promotion.code | |
codes << a.originator.promotion.code | |
end | |
end | |
# Re-apply each code...depend on Spree to use the best one. | |
# https://github.com/spree/spree/blob/2-1-stable/api/app/controllers/spree/api/orders_controller.rb#L85 | |
codes.each do |c| | |
coupon_code = c | |
save | |
Spree::Promo::CouponApplicator.new(self).apply | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment