Sha256: b6fc1a5f2c52f909df5abefca2a0e5b9869cc9682638242b90c8a899adb24268

Contents?: true

Size: 716 Bytes

Versions: 5

Compression:

Stored size: 716 Bytes

Contents

class ShopLineItem < ActiveRecord::Base
  
  belongs_to  :order,       :class_name   => 'ShopOrder'
  has_one     :customer,    :class_name   => 'ShopCustomer', :through => :order, :source => :customer
  belongs_to  :item,        :polymorphic  => true
  
  before_validation       :adjust_quantity
  validates_uniqueness_of :item_id, :scope => [ :order_id, :item_type ]
  validates_presence_of   :item
  
  def price
    (item.price.to_f * self.quantity.to_f).to_f
  end
  
  def weight
    (item.weight.to_f * self.quantity.to_f).to_f
  end
  
  class << self
    
    def params
      [ :id, :quantity ]
    end
    
  end
  
private
  
  def adjust_quantity
    self.quantity = [1,self.quantity].max
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
radiant-shop-extension-0.11.5 app/models/shop_line_item.rb
radiant-shop-extension-0.11.4 app/models/shop_line_item.rb
radiant-shop-extension-0.11.3 app/models/shop_line_item.rb
radiant-shop-extension-0.11.1 app/models/shop_line_item.rb
radiant-shop-extension-0.11.0 app/models/shop_line_item.rb