Class: Spina::Shop::ChangeStockLevel

Inherits:
Object
  • Object
show all
Defined in:
app/services/spina/shop/change_stock_level.rb

Instance Method Summary collapse

Constructor Details

#initialize(product, params, send_in_stock_reminders: false) ⇒ ChangeStockLevel

Returns a new instance of ChangeStockLevel.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/services/spina/shop/change_stock_level.rb', line 4

def initialize(product, params, send_in_stock_reminders: false)
  @product = product
  @send_in_stock_reminders = send_in_stock_reminders
  @params = {
    product_id: @product.id,
    order_item_id: params[:order_item_id],
    adjustment: params[:adjustment],
    expiration_year: params[:expiration_year],
    expiration_month: params[:expiration_month],
    description: params[:description],
    actor: params[:actor]
  }
end

Instance Method Details

#saveObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/services/spina/shop/change_stock_level.rb', line 18

def save
  # Create StockLevelAdjustment
  StockLevelAdjustment.create(@params)

  # Cache product columns for fast querying
  @product.cache_stock_level

  # Stock reminders
  send_in_stock_reminders if @send_in_stock_reminders && @product.in_stock?

  return true
end