Class: PowerShop::Product

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

Direct Known Subclasses

Product

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activeObject

Public: get only active products

Returns ActiveRecord::Relation



22
23
24
# File 'app/models/power_shop/product.rb', line 22

def self.active
  where(active: true)
end

Instance Method Details

#decrement_category_countObject



37
38
39
# File 'app/models/power_shop/product.rb', line 37

def decrement_category_count
  ::Category.decrement_counter :products_count, category_id
end

#increment_category_countObject



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

def increment_category_count
  ::Category.increment_counter :products_count, category_id
end

#main_imageObject

Public: get first image from images

Returns ShopImage



29
30
31
# File 'app/models/power_shop/product.rb', line 29

def main_image
  images.first
end

#touch_category_countObject



41
42
43
# File 'app/models/power_shop/product.rb', line 41

def touch_category_count
  active? ? increment_category_count : decrement_category_count
end