Class: Comable::Product

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Search, Ransackable, SkuItem
Defined in:
app/models/comable/product.rb,
app/models/concerns/comable/product/search.rb

Defined Under Namespace

Modules: Search

Constant Summary

Constants included from Search

Search::SEARCH_COLUMNS

Instance Method Summary collapse

Methods included from SkuItem

#sku_h?, #sku_v?

Instance Method Details

#category_path_names=(category_path_names, delimiter: Comable::Category::DEFAULT_PATH_NAME_DELIMITER) ⇒ Object



47
48
49
# File 'app/models/comable/product.rb', line 47

def category_path_names=(category_path_names, delimiter: Comable::Category::DEFAULT_PATH_NAME_DELIMITER)
  self.categories = Comable::Category.find_by_path_names(category_path_names, delimiter: delimiter)
end

#image_urlObject



27
28
29
30
31
# File 'app/models/comable/product.rb', line 27

def image_url
  image = images.first
  return image.url if image
  'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMTcxIiBoZWlnaHQ9IjE4MCIgdmlld0JveD0iMCAwIDE3MSAxODAiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjxkZWZzLz48cmVjdCB3aWR0aD0iMTcxIiBoZWlnaHQ9IjE4MCIgZmlsbD0iI0VFRUVFRSIvPjxnPjx0ZXh0IHg9IjU4IiB5PSI5MCIgc3R5bGU9ImZpbGw6I0FBQUFBQTtmb250LXdlaWdodDpib2xkO2ZvbnQtZmFtaWx5OkFyaWFsLCBIZWx2ZXRpY2EsIE9wZW4gU2Fucywgc2Fucy1zZXJpZiwgbW9ub3NwYWNlO2ZvbnQtc2l6ZToxMHB0O2RvbWluYW50LWJhc2VsaW5lOmNlbnRyYWwiPjE3MXgxODA8L3RleHQ+PC9nPjwvc3ZnPg=='
end

#imagesObject

Add conditions for the images association. Override method of the images association to support Rails 3.x.



23
24
25
# File 'app/models/comable/product.rb', line 23

def images
  super.order(:id)
end

#stocked?Boolean Also known as: unsold?

Returns:

  • (Boolean)


33
34
35
# File 'app/models/comable/product.rb', line 33

def stocked?
  stocks.stocked.exists?
end

#unstocked?Boolean Also known as: soldout?

Returns:

  • (Boolean)


40
41
42
# File 'app/models/comable/product.rb', line 40

def unstocked?
  !stocked?
end