Sha256: b6d37f6d24e4f5c6e8771ff2d32e0bdb56bf75e42c437a9dec9de06aebc0c740

Contents?: true

Size: 863 Bytes

Versions: 38

Compression:

Stored size: 863 Bytes

Contents

module Effective
  class CartItem < ActiveRecord::Base
    self.table_name = (EffectiveOrders.cart_items_table_name || :cart_items).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

38 entries across 38 versions & 1 rubygems

Version Path
effective_orders-6.17.2 app/models/effective/cart_item.rb
effective_orders-6.17.1 app/models/effective/cart_item.rb
effective_orders-6.17.0 app/models/effective/cart_item.rb
effective_orders-6.16.4 app/models/effective/cart_item.rb
effective_orders-6.16.3 app/models/effective/cart_item.rb
effective_orders-6.16.2 app/models/effective/cart_item.rb
effective_orders-6.16.1 app/models/effective/cart_item.rb
effective_orders-6.16.0 app/models/effective/cart_item.rb
effective_orders-6.15.0 app/models/effective/cart_item.rb
effective_orders-6.14.6 app/models/effective/cart_item.rb
effective_orders-6.14.5 app/models/effective/cart_item.rb
effective_orders-6.14.4 app/models/effective/cart_item.rb
effective_orders-6.14.3 app/models/effective/cart_item.rb
effective_orders-6.14.2 app/models/effective/cart_item.rb
effective_orders-6.14.1 app/models/effective/cart_item.rb
effective_orders-6.14.0 app/models/effective/cart_item.rb
effective_orders-6.13.3 app/models/effective/cart_item.rb
effective_orders-6.13.2 app/models/effective/cart_item.rb
effective_orders-6.13.1 app/models/effective/cart_item.rb
effective_orders-6.13.0 app/models/effective/cart_item.rb