Class: Gemgento::API::SOAP::CatalogInventory::StockItem

Inherits:
Object
  • Object
show all
Defined in:
lib/gemgento/api/soap/catalog_inventory/stock_item.rb

Class Method Summary collapse

Class Method Details

.fetch_all(products = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gemgento/api/soap/catalog_inventory/stock_item.rb', line 7

def self.fetch_all(products = nil)
  products = Gemgento::Product.simple.not_deleted if products.nil?
  magento_product_ids = []

  products.each do |product|
    magento_product_ids << product.magento_id
  end

  list(magento_product_ids).each do |inventory|
    sync_magento_to_local(inventory)
  end
end

.list(product_ids) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gemgento/api/soap/catalog_inventory/stock_item.rb', line 20

def self.list(product_ids)
  message = {
      products: {item: product_ids},
  }
  response = Gemgento::MagentoApi.create_call(:catalog_inventory_stock_item_list, message)

  if response.success?
    if response.body[:result][:item].nil?
      response.body[:result][:item] = []
    end

    unless response.body[:result][:item].is_a? Array
      response.body[:result][:item] = [response.body[:result][:item]]
    end

    response.body[:result][:item]
  end
end

.update(inventory) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/gemgento/api/soap/catalog_inventory/stock_item.rb', line 39

def self.update(inventory)
  message = {
      product: inventory.product.magento_id,
      data: compose_inventory_data(inventory)
  }

  return Gemgento::MagentoApi.create_call(:catalog_inventory_stock_item_update, message)
end