Skip to content

Instantly share code, notes, and snippets.

@bsodmike
Created July 11, 2014 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsodmike/21a6e0fab7e5a967560f to your computer and use it in GitHub Desktop.
Save bsodmike/21a6e0fab7e5a967560f to your computer and use it in GitHub Desktop.
Spree - Promotion adjustment action beyond first ignored #3262
=begin
Tested in Spree 1.2.5
Ref: https://github.com/spree/spree/issues/3262
https://github.com/spree/spree/commit/bdd4db95eb2cce3e87f3991dbeca22e275862fc3
=end
::Spree::Order.class_eval do
# Tells us if there if the specified promotion is already associated with the order
# regardless of whether or not its currently eligible. Useful because generally
# you would only want a promotion to apply to order no more than once.
#
# Receives an adjustment +originator+ (here a PromotionAction object) and tells
# if the order has adjustments from that already
def promotion_credit_exists?(originator)
!! adjustments.promotion.reload.detect { |credit| credit.originator.id == originator.id }
end
end
::Spree::Promotion::Actions::CreateAdjustment.class_eval do
# Creates the adjustment related to a promotion for the order passed
# through options hash
def perform(options = {})
order = options[:order]
return if order.promotion_credit_exists?(self)
self.create_adjustment("#{I18n.t(:promotion)} (#{promotion.name})", order, order)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment