Class: ItemBuilder::Modes::Quantity::BlibliService

Inherits:
Base
  • Object
show all
Defined in:
lib/item_builder/modes/quantity/blibli_service.rb

Instance Attribute Summary

Attributes inherited from Base

#available_quantity, #listing

Instance Method Summary collapse

Methods inherited from Base

#api_data, #apigateway_get, #apigateway_post, #credential, #data, #headers, #initialize, #order_host, #reserved_params, #reserved_stock

Constructor Details

This class inherits a constructor from ItemBuilder::Modes::Quantity::Base

Instance Method Details

#local_productHash

Find local product based on id

Returns:

  • (Hash)

    Local Blibli product



32
33
34
# File 'lib/item_builder/modes/quantity/blibli_service.rb', line 32

def local_product
  @local_product ||= JSON.parse(apigateway_post)
end

#local_variantObject



12
13
14
15
16
17
18
# File 'lib/item_builder/modes/quantity/blibli_service.rb', line 12

def local_variant
  qty = 0
  local_product['value']['items'].each do |item|
    qty = total_quantity(item) if item['itemSku'] == listing.local_id
  end
  qty
end

#performObject



8
9
10
# File 'lib/item_builder/modes/quantity/blibli_service.rb', line 8

def perform
  local_variant
end

#total_quantity(item) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/item_builder/modes/quantity/blibli_service.rb', line 20

def total_quantity(item)
  # Make stock 0
  # if local reserved quantity is bigger than available quantity
  if item['reservedStockLevel2'] > available_quantity
    0
  else
    available_quantity
  end
end