Sha256: a6f4004a8e5b1d8038d7661ae49604a2be6b0de296983cb91bfc6ff0ce34818f

Contents?: true

Size: 877 Bytes

Versions: 5

Compression:

Stored size: 877 Bytes

Contents

module ShopDiscounts
  module Models
    module ShopOrder
      
      def self.included(base)
        base.class_eval do
                    
          # Assigns discounts based off the customers discounts
          def apply_customer_discounts
            if customer.present?
              customer.discounts.each do |discount|
                ShopDiscountable.create(:discount_id => discount.id, :discounted_id => self.id, :discounted_type => self.class.name)
              end
            end
          end
          
          class << self
            alias_method :original_find_by_session, :find_by_session
            def find_by_session(session)
              if order = original_find_by_session(session)
                order.apply_customer_discounts
              end
              order
            end
          end
        end
      end
      
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
radiant-shop_discounts-extension-0.0.11 lib/shop_discounts/models/shop_order.rb
radiant-shop_discounts-extension-0.0.10 lib/shop_discounts/models/shop_order.rb
radiant-shop_discounts-extension-0.0.9 lib/shop_discounts/models/shop_order.rb
radiant-shop_discounts-extension-0.0.8 lib/shop_discounts/models/shop_order.rb
radiant-shop_discounts-extension-0.0.7 lib/shop_discounts/models/shop_order.rb