Sha256: a913ddd78b468971e027c5b7da9df7bcd916a0cd38003355f4e4be455871a0ef

Contents?: true

Size: 800 Bytes

Versions: 18

Compression:

Stored size: 800 Bytes

Contents

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

    belongs_to :cart, counter_cache: true, class_name: 'Effective::Cart'
    belongs_to :purchasable, polymorphic: true

    # Attributes
    # quantity    :integer
    # timestamps

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

    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 title
      purchasable.try(:title) || 'New Cart Item'
    end

    def tax_exempt
      purchasable.try(:tax_exempt) || false
    end

    def subtotal
      price * quantity
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
effective_orders-3.2.3 app/models/effective/cart_item.rb
effective_orders-3.2.2 app/models/effective/cart_item.rb
effective_orders-3.2.1 app/models/effective/cart_item.rb
effective_orders-3.2.0 app/models/effective/cart_item.rb
effective_orders-3.1.7 app/models/effective/cart_item.rb
effective_orders-3.1.6 app/models/effective/cart_item.rb
effective_orders-3.1.4 app/models/effective/cart_item.rb
effective_orders-3.1.3 app/models/effective/cart_item.rb
effective_orders-3.1.0 app/models/effective/cart_item.rb
effective_orders-3.0.4 app/models/effective/cart_item.rb
effective_orders-3.0.3 app/models/effective/cart_item.rb
effective_orders-3.0.2 app/models/effective/cart_item.rb
effective_orders-4.0.0beta4 app/models/effective/cart_item.rb
effective_orders-4.0.0beta3 app/models/effective/cart_item.rb
effective_orders-4.0.0beta2 app/models/effective/cart_item.rb
effective_orders-4.0.0beta1 app/models/effective/cart_item.rb
effective_orders-3.0.1 app/models/effective/cart_item.rb
effective_orders-3.0.0 app/models/effective/cart_item.rb