Class: Gemgento::Magento::InventoryController

Inherits:
BaseController show all
Defined in:
app/controllers/gemgento/magento/inventory_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#validate_ip

Instance Method Details

#updateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/gemgento/magento/inventory_controller.rb', line 5

def update
  data = params[:data]

  @product = Gemgento::Product.find_by!(magento_id: data[:product_id])

  @product.stores.each do |store|
      inventory = Gemgento::Inventory.find_or_initialize_by(store: store, product: @product)
      inventory.product = @product
      inventory.store = store
      inventory.quantity = data[:qty]
      inventory.is_in_stock = data[:is_in_stock]
      inventory.backorders = data[:backorders].to_i
      inventory.use_config_backorders = data[:use_config_backorders]
      inventory.min_qty = data[:min_qty].to_i
      inventory.use_config_min_qty = data[:use_config_min_qty]
      inventory.manage_stock = data[:manage_stock]
      inventory.sync_needed = false
      inventory.save
  end

  render nothing: true
end