Class: ShopProductVariant

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/shop_product_variant.rb

Instance Method Summary collapse

Instance Method Details

#nameObject



19
20
21
# File 'app/models/shop_product_variant.rb', line 19

def name
  %{#{product.name} #{self[:name]}}
end

#priceObject

Returns the price of the variant plus the product price



24
25
26
27
28
29
30
# File 'app/models/shop_product_variant.rb', line 24

def price
  price = product.price
  if read_attribute(:price).present?
    price = read_attribute(:price) + product.price
  end
  price
end

#skuObject

Returns a mixed sku of product and variant name



33
34
35
36
37
38
39
# File 'app/models/shop_product_variant.rb', line 33

def sku
  sku = nil
  if self[:name].present?
    sku = %{#{product.sku}-#{self[:name].gsub(/[^a-zA-Z0-9_]/,"_")}}
  end
  sku
end

#slugObject

Returns slug of the product



42
43
44
# File 'app/models/shop_product_variant.rb', line 42

def slug
  product.slug
end

#to_paramObject



50
51
52
# File 'app/models/shop_product_variant.rb', line 50

def to_param
  product.to_param
end

#urlObject



46
47
48
# File 'app/models/shop_product_variant.rb', line 46

def url
  product.url
end