Class: ItemBuilderMwh::Modes::Simple::BlibliService
- Defined in:
- lib/item_builder_mwh/modes/simple/blibli_service.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#local_product ⇒ Hash
Find local product based on id.
- #local_variant ⇒ Object
- #perform ⇒ Object
- #total_quantity(item) ⇒ Object
Methods inherited from Base
#api_data, #apigateway_get, #apigateway_post, #credential, #data, #headers, #initialize, #order_host, #reserved_params, #reserved_stock, #sale_price_policy
Constructor Details
This class inherits a constructor from ItemBuilderMwh::Modes::Simple::Base
Instance Method Details
#local_product ⇒ Hash
Find local product based on id
43 44 45 |
# File 'lib/item_builder_mwh/modes/simple/blibli_service.rb', line 43 def local_product @local_product ||= JSON.parse(apigateway_post) end |
#local_variant ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/item_builder_mwh/modes/simple/blibli_service.rb', line 23 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 |
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/item_builder_mwh/modes/simple/blibli_service.rb', line 10 def perform { price: listing.price, sale_price: sale_price, sale_start_at: listing.sale_start_at, sale_end_at: listing.sale_end_at, quantity: local_variant, warehouse_id: wh_mapping( warehouse_space.warehouse_id ) } end |
#total_quantity(item) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/item_builder_mwh/modes/simple/blibli_service.rb', line 31 def total_quantity(item) # Make stock 0 # if local reserved quantity is bigger than available quantity if item['reservedStockLevel2'] > available_quantity 0 else item['availableStockLevel2'] + item['reservedStockLevel2'] end end |