Sha256: ec5d56a88bb220c7d62165ceb31c83c038d782e2a5cb996d7fed0a0de81af7d1

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module Shop
  module Controllers
    module ApplicationController
      
      def self.included(base)
        base.class_eval do
          def current_shop_order
            return @current_shop_order if defined?(@current_shop_order)
            @current_shop_order = find_shop_order
          end
          
          def find_shop_order
            shop_order = nil
            
            if request.session[:shop_order]
              shop_order = ShopOrder.find(request.session[:shop_order])
            end
                        
            shop_order
          end
          
          def find_or_create_shop_order
            shop_order = nil
            
            if find_shop_order and find_shop_order.status != 'paid'
              shop_order = find_shop_order
            else
              shop_order = ShopOrder.create({ :customer_id => (current_user.id rescue nil) })
              request.session[:shop_order] = shop_order.id
            end
            
            shop_order
          end
        end
      end
      
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
radiant-shop-extension-0.11.6 lib/shop/controllers/application_controller.rb
radiant-shop-extension-0.11.5 lib/shop/controllers/application_controller.rb
radiant-shop-extension-0.11.4 lib/shop/controllers/application_controller.rb
radiant-shop-extension-0.11.3 lib/shop/controllers/application_controller.rb
radiant-shop-extension-0.11.1 lib/shop/controllers/application_controller.rb
radiant-shop-extension-0.11.0 lib/shop/controllers/application_controller.rb