Class: Comable::Stock
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Stock
- Includes:
- Decoratable
- Defined in:
- app/models/comable/stock.rb
Overview
在庫モデル。商品に複数紐付き、品数やSKU(Stock Keeping Unit)情報を保持する。
Scope collapse
-
.activated ⇒ Object
有効な在庫インスタンスを返す.
-
.soldout ⇒ Object
品切れの在庫インスタンスを返す.
-
.unsold ⇒ Object
品切れでない在庫インスタンスを返す.
Instance Method Summary collapse
-
#decrement!(quantity: 1) ⇒ Boolean
在庫減算を行う.
- #name ⇒ Object
-
#soldout? ⇒ Boolean
在庫の有無を取得する.
-
#unsold? ⇒ Boolean
在庫の有無を取得する.
Methods included from Decoratable
Class Method Details
.activated ⇒ Object
有効な在庫インスタンスを返す
17 |
# File 'app/models/comable/stock.rb', line 17 scope :activated, -> { where.not(product_id_num: nil) } |
.soldout ⇒ Object
品切れの在庫インスタンスを返す
25 |
# File 'app/models/comable/stock.rb', line 25 scope :soldout, -> { where('quantity <= ?', 0) } |
.unsold ⇒ Object
品切れでない在庫インスタンスを返す
21 |
# File 'app/models/comable/stock.rb', line 21 scope :unsold, -> { where('quantity > ?', 0) } |
Instance Method Details
#decrement!(quantity: 1) ⇒ Boolean
在庫減算を行う
74 75 76 77 78 79 80 |
# File 'app/models/comable/stock.rb', line 74 def decrement!(quantity: 1) with_lock do # TODO: カラムマッピングのdecrementメソッドへの対応 self.quantity -= quantity save! end end |
#name ⇒ Object
34 35 36 37 38 39 |
# File 'app/models/comable/stock.rb', line 34 def name return product.name unless product.sku? sku_name = sku_h_choice_name sku_name += '/' + sku_v_choice_name if sku_v_choice_name.present? product.name + "(#{sku_name})" end |
#soldout? ⇒ Boolean
在庫の有無を取得する
61 62 63 |
# File 'app/models/comable/stock.rb', line 61 def soldout? !unsold? end |
#unsold? ⇒ Boolean
在庫の有無を取得する
48 49 50 51 52 |
# File 'app/models/comable/stock.rb', line 48 def unsold? return false if product_id_num.nil? return false if quantity.nil? quantity > 0 end |