Skip to content

Instantly share code, notes, and snippets.

@bryanmtl
Created November 25, 2013 18:58
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 bryanmtl/7646690 to your computer and use it in GitHub Desktop.
Save bryanmtl/7646690 to your computer and use it in GitHub Desktop.
Spree store credit fix
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