Sha256: ed299ce016e56b5fece429f7ff2fc5fc7092dd516c74f115cb7a07620d1cc328

Contents?: true

Size: 1.02 KB

Versions: 59

Compression:

Stored size: 1.02 KB

Contents

module Effective
  class CartItem < ActiveRecord::Base
    self.table_name = EffectiveOrders.cart_items_table_name.to_s

    belongs_to :cart
    belongs_to :purchasable, :polymorphic => true

    structure do
      quantity    :integer, :validates => [:presence]
      timestamps
    end

    validates_presence_of :purchasable

    delegate :title, :tax_exempt, :tax_rate, :to => :purchasable

    default_scope -> { order(:updated_at) }

    def price
      if (purchasable.price || 0).kind_of?(Integer)
        purchasable.price || 0
      else
        ActiveSupport::Deprecation.warn('price is a non-integer. It should be an Integer representing the number of cents.  Continuing with (price * 100.0).round(0).to_i conversion') unless EffectiveOrders.silence_deprecation_warnings
        (purchasable.price * 100.0).round(0).to_i rescue 0
      end
    end

    def subtotal
      price * quantity
    end

    def tax
      tax_exempt ? 0 : (subtotal * tax_rate).round(0).to_i
    end

    def total
      subtotal + tax
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
effective_orders-1.8.1 app/models/effective/cart_item.rb
effective_orders-1.8.0 app/models/effective/cart_item.rb
effective_orders-1.7.5 app/models/effective/cart_item.rb
effective_orders-1.7.4 app/models/effective/cart_item.rb
effective_orders-1.7.3 app/models/effective/cart_item.rb
effective_orders-1.7.2 app/models/effective/cart_item.rb
effective_orders-1.7.1 app/models/effective/cart_item.rb
effective_orders-1.7.0 app/models/effective/cart_item.rb
effective_orders-1.6.6 app/models/effective/cart_item.rb
effective_orders-1.6.5 app/models/effective/cart_item.rb
effective_orders-1.6.4 app/models/effective/cart_item.rb
effective_orders-1.6.3 app/models/effective/cart_item.rb
effective_orders-1.6.1 app/models/effective/cart_item.rb
effective_orders-1.6.0 app/models/effective/cart_item.rb
effective_orders-1.5.9 app/models/effective/cart_item.rb
effective_orders-1.5.8 app/models/effective/cart_item.rb
effective_orders-1.5.7 app/models/effective/cart_item.rb
effective_orders-1.5.5 app/models/effective/cart_item.rb
effective_orders-1.5.4 app/models/effective/cart_item.rb
effective_orders-1.5.3 app/models/effective/cart_item.rb