Sha256: 8e690103e5db2765222c1ef06ddb5f4b29add98197ff1f18fd6d4bd690726076

Contents?: true

Size: 1.14 KB

Versions: 12

Compression:

Stored size: 1.14 KB

Contents

module Shop
  module Models
    module FormExtension
      
      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(@page.request.session[:shop_order])
            @order.update_attribute(:customer_id, (current_customer.id rescue nil)) # either assign it to a user, or don't
          end

          # Uses the page session data to find or create the current order
          def find_or_create_current_order
            begin
              find_current_order
            rescue
              @order = ShopOrder.create
              @result[:session] = { :shop_order => @order.id }
              @order.update_attribute(:customer_id, (current_customer.id rescue nil)) # either assign it to a user, or don't
            end
          end
          
          # Returns the current logged in ShopCustomer (if it exists)
          def current_customer
            return @shop_customer if @shop_customer.present?
            @shop_customer = current_user if current_user.present?
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
radiant-shop-extension-0.92.3 lib/shop/models/form_extension.rb
radiant-shop-extension-0.92.2 lib/shop/models/form_extension.rb
radiant-shop-extension-0.92.1 lib/shop/models/form_extension.rb
radiant-shop-extension-0.92.0 lib/shop/models/form_extension.rb
radiant-shop-extension-0.91.7 lib/shop/models/form_extension.rb
radiant-shop-extension-0.91.4 lib/shop/models/form_extension.rb
radiant-shop-extension-0.91.3 lib/shop/models/form_extension.rb
radiant-shop-extension-0.91.2 lib/shop/models/form_extension.rb
radiant-shop-extension-0.90.4 lib/shop/models/form_extension.rb
radiant-shop-extension-0.90.2 lib/shop/models/form_extension.rb
radiant-shop-extension-0.90.1 lib/shop/models/form_extension.rb
radiant-shop-extension-0.90.0 lib/shop/models/form_extension.rb