Sha256: ae7380e7fb9b71c2aa9b54e243f588f1a7687cfc01d7ff7de5267ef91f46211b

Contents?: true

Size: 833 Bytes

Versions: 66

Compression:

Stored size: 833 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 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

66 entries across 66 versions & 1 rubygems

Version Path
effective_orders-4.6.3 app/models/effective/cart_item.rb
effective_orders-4.6.2 app/models/effective/cart_item.rb
effective_orders-4.6.0 app/models/effective/cart_item.rb
effective_orders-4.5.12 app/models/effective/cart_item.rb
effective_orders-4.5.11 app/models/effective/cart_item.rb
effective_orders-4.5.10 app/models/effective/cart_item.rb
effective_orders-4.5.9 app/models/effective/cart_item.rb
effective_orders-4.5.8 app/models/effective/cart_item.rb
effective_orders-4.5.7 app/models/effective/cart_item.rb
effective_orders-4.5.6 app/models/effective/cart_item.rb
effective_orders-4.5.5 app/models/effective/cart_item.rb
effective_orders-4.5.4 app/models/effective/cart_item.rb
effective_orders-4.5.3 app/models/effective/cart_item.rb
effective_orders-4.5.2 app/models/effective/cart_item.rb
effective_orders-4.5.1 app/models/effective/cart_item.rb
effective_orders-4.5.0 app/models/effective/cart_item.rb
effective_orders-4.4.10 app/models/effective/cart_item.rb
effective_orders-4.4.9 app/models/effective/cart_item.rb
effective_orders-4.4.8 app/models/effective/cart_item.rb
effective_orders-4.4.7 app/models/effective/cart_item.rb