Permalink
Browse files

check for presence of user before processing save validations

  • Loading branch information...
jsqu99 committed Oct 22, 2011
1 parent c5159ef commit 6f0a28c3aca9c205851b675aa0f145d6e700e141
Showing with 6 additions and 3 deletions.
  1. +6 −3 app/models/order_decorator.rb
@@ -1,9 +1,12 @@
Order.class_eval do
attr_accessible :store_credit_amount, :remove_store_credits
attr_accessor :store_credit_amount, :remove_store_credits
- before_save :process_store_credit, :if => "@store_credit_amount"
- before_save :remove_store_credits
- after_save :ensure_sufficient_credit
+ # the check for user? below is to ensure we don't break the
+ # admin app when creating a new order from the admin console
+ # In that case, we create an order before assigning a user
+ before_save :process_store_credit, :if => "self.user? && @store_credit_amount"
+ before_save :remove_store_credits, :if => "self.user?"
+ after_save :ensure_sufficient_credit, :if => "self.user?"
has_many :store_credits, :class_name => 'StoreCreditAdjustment', :conditions => "source_type='StoreCredit'"

0 comments on commit 6f0a28c

Please sign in to comment.