Sha256: 47caf6ed7becfe0f3a672ccfa6913776e7754b18749e8c9a043fa7f63b433953

Contents?: true

Size: 601 Bytes

Versions: 3

Compression:

Stored size: 601 Bytes

Contents

class ShopLineItem < ActiveRecord::Base
  
  belongs_to :order,      :class_name => 'ShopOrder', :foreign_key => :shop_order_id
  belongs_to :item,       :polymorphic => true
  
  validates_uniqueness_of :item_id, :scope => [ :shop_order_id, :item_type ]
  
  before_validation       :adjust_quantity
  
  def price
    item.price.to_f * self.quantity.to_f
  end
  
  def weight
    item.weight.to_f * self.quantity.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

3 entries across 3 versions & 1 rubygems

Version Path
radiant-shop-extension-0.10.0 app/models/shop_line_item.rb
radiant-shop-extension-0.9.3 app/models/shop_line_item.rb
radiant-shop-extension-0.9.2 app/models/shop_line_item.rb