Sha256: d5f54b3ec3975567de41e081aba21d215ba33ae1aae49770b5ec65e08cb0ea02

Contents?: true

Size: 1012 Bytes

Versions: 1

Compression:

Stored size: 1012 Bytes

Contents

class ShopProductVariant < ActiveRecord::Base
  
  belongs_to :product, :class_name => 'ShopProduct', :foreign_key => :product_id
  
  validates_presence_of   :product
  validates_presence_of   :name
  validates_uniqueness_of :name, :scope => :product_id
  
  belongs_to :created_by, :class_name => 'User'
  belongs_to :updated_by, :class_name => 'User'
  
  has_many    :line_items,  :class_name => 'ShopLineItem',          :foreign_key  => :item_id,      :dependent => :destroy
  has_many    :orders,      :class_name => 'ShopOrder',             :through      => :line_items,   :uniq      => true
  
  # Returns the price of the variant plus the product price
  def price
    price = product.price
    if read_attribute(:price).present?
      price = read_attribute(:price) + product.price
    end
    price
  end
  
  # Returns a mixed sku of product and variant name
  def sku
    %{#{product.sku}-#{ShopProduct.to_sku(name)}}
  end
  
  # Returns slug of the product
  def slug
    product.slug
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
radiant-shop-extension-0.11.6 app/models/shop_product_variant.rb