Created
November 25, 2013 18:58
-
-
Save bryanmtl/7646690 to your computer and use it in GitHub Desktop.
Spree store credit fix
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 | |
checkout_flow do | |
go_to_state :address | |
go_to_state :delivery | |
go_to_state :payment, :if => lambda { |order| order.payment_required? } | |
go_to_state :confirm, :if => lambda { |order| order.confirmation_required? } | |
go_to_state :complete, :if => lambda { |order| (order.payment_required? && order.has_unprocessed_payments?) || !order.payment_required? } | |
remove_transition :from => :delivery, :to => :confirm | |
end | |
def consume_users_credit | |
credit_used = self.store_credit_amount | |
user.store_credits.each do |store_credit| | |
break if credit_used == 0 | |
if store_credit.remaining_amount > 0 | |
if store_credit.remaining_amount > credit_used | |
store_credit.remaining_amount -= credit_used | |
store_credit.save! | |
credit_used = 0 | |
else | |
credit_used -= store_credit.remaining_amount | |
store_credit.update_attribute(:remaining_amount, 0) | |
end | |
end | |
end | |
end | |
def finalize_with_consume_users_credit! | |
consume_users_credit | |
finalize_without_consume_users_credit! | |
end | |
alias_method_chain :finalize!, :consume_users_credit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment