Module: Shop::Models::FormExtension

Included in:
FormAddress, FormCheckout, FormLineItem
Defined in:
lib/shop/models/form_extension.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shop/models/form_extension.rb', line 5

def self.included(base)
  base.class_eval do
    # Uses the page session data to find the current order
    def find_current_order
      @order = ShopOrder.find_by_session(@page.request.session[:shop_order])
    end
    
    # Uses the page session data to find or create the current order
    def find_or_create_current_order
      begin
        @order = find_current_order
      rescue
        @order = ShopOrder.create
        @result[:session] = { :shop_order => @order.id }
      end
      
      if current_user
        @order.update_attribute(:customer_id, (current_user.id))
      end
      
      @order
    end
  end
end