Sha256: 6312d204cbebacc782e7e6588f888777bea930ce4a21121789ff467a6fddd68a

Contents?: true

Size: 846 Bytes

Versions: 106

Compression:

Stored size: 846 Bytes

Contents

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

    belongs_to :cart, counter_cache: true
    belongs_to :purchasable, polymorphic: true

    effective_resource do
      unique      :string
      quantity    :integer

      timestamps
    end

    validates :purchasable, presence: true
    validates :quantity, presence: true

    def to_s
      name || 'New Cart Item'
    end

    def name
      purchasable&.purchasable_name
    end

    def price
      if (purchasable.price || 0).kind_of?(Integer)
        purchasable.price || 0
      else
        raise 'expected price to be an Integer representing the number of cents.'
      end
    end

    def tax_exempt
      purchasable&.tax_exempt || false
    end

    def subtotal
      price * quantity
    end

  end
end

Version data entries

106 entries across 106 versions & 1 rubygems

Version Path
effective_orders-6.4.2 app/models/effective/cart_item.rb
effective_orders-6.4.1 app/models/effective/cart_item.rb
effective_orders-6.4.0 app/models/effective/cart_item.rb
effective_orders-6.3.2 app/models/effective/cart_item.rb
effective_orders-6.3.1 app/models/effective/cart_item.rb
effective_orders-6.3.0 app/models/effective/cart_item.rb
effective_orders-6.2.1 app/models/effective/cart_item.rb
effective_orders-6.2.0 app/models/effective/cart_item.rb
effective_orders-6.1.5 app/models/effective/cart_item.rb
effective_orders-6.1.4 app/models/effective/cart_item.rb
effective_orders-6.1.3 app/models/effective/cart_item.rb
effective_orders-6.1.2 app/models/effective/cart_item.rb
effective_orders-6.1.1 app/models/effective/cart_item.rb
effective_orders-6.1.0 app/models/effective/cart_item.rb
effective_orders-6.0.1 app/models/effective/cart_item.rb
effective_orders-6.0.0 app/models/effective/cart_item.rb
effective_orders-5.9.4 app/models/effective/cart_item.rb
effective_orders-5.9.3 app/models/effective/cart_item.rb
effective_orders-5.9.2 app/models/effective/cart_item.rb
effective_orders-5.9.1 app/models/effective/cart_item.rb