item_builder_mwh 0.1.26 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e01aa6ef954cf51bc3dcb92ca26f17d430c4ea1fc51d4ef8c90fecfc990f0fd
4
- data.tar.gz: f11f2141638776fa7aa54fed48488b4b5435288dcd9367290d51443963d2434b
3
+ metadata.gz: a7d9cbd0ff16d3f1b3ff9f1eec6bbe89304e1445fe3d2cd9ed0fa07e3884c6b1
4
+ data.tar.gz: 874ff15f589f0b9de12af48badaabfc16dba5087796143f2b548080498f2c91f
5
5
  SHA512:
6
- metadata.gz: 6fff1385a38d7539f9ecf9776fb3fd2d6bc06047035cae7f529b9e5f11bb4de9107a21b1dca457a579d3fb6b59bcec691b0b5799b37ef5e98a40d45cb96e4982
7
- data.tar.gz: 5e8dea305c73d37530197d3506d5f9a697c35e4690281d96465e93b0f65d59ad73f8ca20897fae1bdcc4ccee0b10f600d419968a7f596aeb977cafa06d305f03
6
+ metadata.gz: 556eb6eeb96fb7df53e15a03526de0a6f77377a6cd69c96e8bcc14e71491c863f16bf8ea8949eb61237d7ecf48f348156b1d495535de7d15cc6aba0914841928
7
+ data.tar.gz: ba4db1fbf9de3ce57a444ee75d0b157093a85df642869e89094f78f3b7d0c41e7890149ca97e44d87a4bba5b9ca1e1d8a9b29f97fb6bc00ae7449678c7b3bc4f
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'item_builder_mwh/modes.rb'
4
+ class ItemBuilderMwh
5
+ class LazadaQuantityService
6
+ attr_reader :listings, :skus
7
+ def initialize(args)
8
+ @listings = args.fetch(:listings)
9
+ @skus = args.fetch(:skus)
10
+ end
11
+
12
+ def perform
13
+ args = {
14
+ method: :post, url: url, payload: data, headers: headers
15
+ }
16
+ resp = JSON.parse(rest_client(args, [200, 500, 406]))
17
+ response_process(resp)
18
+ end
19
+
20
+ def headers
21
+ { content_type: :json, accept: :json }
22
+ end
23
+
24
+ def data
25
+ {
26
+ "credential": JSON.parse(credential)['credential'],
27
+ "data": { "skus": skus.to_json }
28
+ }.to_json
29
+ end
30
+
31
+ def credential
32
+ return @credential if @credential
33
+
34
+ account_id = listings[0].profile_channel_association_id
35
+ host = ENV['CREDENTIAL_URL'] || raise('credential url is not set')
36
+ url = "#{host}/credential?account_id=#{account_id}"
37
+ @credential = rest_client(method: :get, url: url)
38
+ end
39
+
40
+ def url
41
+ url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
42
+ url + '/lazada/items'
43
+ end
44
+
45
+ def response_process(resp)
46
+ hash = {}
47
+ resp['data']['products'].each do |product|
48
+ product['skus'].each do |sku|
49
+ qty = sku['multiWarehouseInventories'][0]
50
+ hash[sku['SellerSku']] = qty['occupyQuantity'] + qty['withholdQuantity']
51
+ end
52
+ end if resp['data'].present?
53
+ hash
54
+ end
55
+
56
+ def rest_client(params, rescued_codes = 200)
57
+ RestClient::Request.execute(params.merge(timeout: 3)) do |response|
58
+ code = response.code
59
+ unless Array.wrap(rescued_codes).include?(code)
60
+ raise "Response Code is #{code}"
61
+ end
62
+
63
+ response
64
+ end
65
+ end
66
+ end
67
+ end
@@ -15,10 +15,10 @@ class ItemBuilderMwh
15
15
  def to_h(warehouse_space)
16
16
  {
17
17
  active: listing.active,
18
- quantity: warehouse_space.quantity,
19
- warehouse_id: wh_mapping(
18
+ quantity: warehouse_space&.quantity || 0,
19
+ warehouse_id: warehouse_space.present? ? wh_mapping(
20
20
  warehouse_space.warehouse_id
21
- )
21
+ ) : ''
22
22
  }
23
23
  end
24
24
  end
@@ -35,9 +35,9 @@ class ItemBuilderMwh
35
35
 
36
36
  def warehouse_ids(warehouse_space)
37
37
  {
38
- warehouse_id: wh_mapping(
38
+ warehouse_id: warehouse_space.present? ? wh_mapping(
39
39
  warehouse_space.warehouse_id
40
- )
40
+ ) : ''
41
41
  }
42
42
  end
43
43
 
@@ -15,6 +15,7 @@ class ItemBuilderMwh
15
15
 
16
16
  QUANTITY_CHANNEL = {}.tap do |hash|
17
17
  hash[2] = :Shopify
18
+ hash[3] = :Lazada
18
19
  hash[13] = :Zalora
19
20
  hash[18] = :Zilingo
20
21
  end.freeze
@@ -32,20 +33,19 @@ class ItemBuilderMwh
32
33
  end
33
34
 
34
35
  def to_h(warehouse_space)
35
- if channel_name == "Zilingo"
36
- {
37
- quantity: qty(warehouse_space.quantity),
38
- warehouse_id: wh_mapping(
39
- warehouse_space.warehouse_id
40
- )
41
- }
36
+ {
37
+ quantity: warehouse_space.present? ? real_quantity(warehouse_space) : 0,
38
+ warehouse_id: warehouse_space.present? ? wh_mapping(
39
+ warehouse_space.warehouse_id
40
+ ) : ''
41
+ }
42
+ end
43
+
44
+ def real_quantity(warehouse_space)
45
+ if channel_name == 'Zilingo'
46
+ qty(warehouse_space.quantity)
42
47
  else
43
- {
44
- quantity: [qty(warehouse_space.quantity), 0].sort[1],
45
- warehouse_id: wh_mapping(
46
- warehouse_space.warehouse_id
47
- )
48
- }
48
+ [qty(warehouse_space.quantity), 0].sort[1]
49
49
  end
50
50
  end
51
51
 
@@ -77,7 +77,9 @@ class ItemBuilderMwh
77
77
 
78
78
  zalora_reserved_stock[listing.local_id].to_i
79
79
  else
80
- reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
80
+ return 0 if lazada_quantity.blank?
81
+
82
+ lazada_quantity[listing.local_id].to_i
81
83
  end
82
84
  end
83
85
 
@@ -41,14 +41,14 @@ class ItemBuilderMwh
41
41
 
42
42
  def warehouse_ids(warehouse_space)
43
43
  {
44
- warehouse_id: wh_mapping(
44
+ warehouse_id: warehouse_space.present? ? wh_mapping(
45
45
  warehouse_space.warehouse_id
46
- )
46
+ ) : ''
47
47
  }
48
48
  end
49
49
 
50
50
  def simple(warehouse_space)
51
- qty = warehouse_space.quantity
51
+ qty = warehouse_space&.quantity || 0
52
52
  qty(qty).merge(
53
53
  price
54
54
  )
@@ -92,11 +92,11 @@ class ItemBuilderMwh
92
92
  end
93
93
 
94
94
  def local_qty
95
- if channel_name == 'Zilingo'
95
+ if quantity_name == 'Zilingo'
96
96
  return 0 if zilingo_quantity.blank?
97
97
 
98
98
  zilingo_quantity[listing.local_id].to_i
99
- elsif channel_name == 'Zalora'
99
+ elsif quantity_name == 'Zalora'
100
100
  return 0 if zalora_reserved_stock.blank?
101
101
 
102
102
  zalora_reserved_stock[listing.local_id].to_i
@@ -17,6 +17,7 @@ class ItemBuilderMwh
17
17
  attr_reader :variant_listings
18
18
  attr_reader :reserved_stocks
19
19
  attr_reader :zilingo_quantity
20
+ attr_reader :lazada_quantity
20
21
  attr_reader :zalora_reserved_stock
21
22
  attr_reader :shopify_inventory_location
22
23
  def initialize(args)
@@ -30,6 +31,7 @@ class ItemBuilderMwh
30
31
  @variant_listings = args.fetch(:variant_listings, [])
31
32
  @reserved_stocks = args.fetch(:reserved_stocks, [])
32
33
  @zilingo_quantity = args.fetch(:zilingo_quantity, [])
34
+ @lazada_quantity = args.fetch(:lazada_quantity, [])
33
35
  @zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
34
36
  @shopify_inventory_location = args.fetch(:shopify_inventory_location, {})
35
37
  warehouse
@@ -78,9 +80,17 @@ class ItemBuilderMwh
78
80
  if multiwarehouse && wh_routing == 1
79
81
  warehouses << to_h(warehouse_spaces.first)
80
82
  else
83
+ warehouse_list
84
+ end
85
+ end
86
+
87
+ def warehouse_list
88
+ if warehouse_spaces.present?
81
89
  warehouse_spaces.each do |warehouse_space|
82
90
  warehouses << to_h(warehouse_space)
83
91
  end
92
+ else
93
+ warehouses << to_h(nil)
84
94
  end
85
95
  end
86
96
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ItemBuilderMwh
4
- VERSION = '0.1.26'
4
+ VERSION = '0.1.30'
5
5
  end
@@ -57,7 +57,7 @@ class ItemBuilderMwh
57
57
  hash = Hash.new
58
58
  resp.dig("SuccessResponse", "Body", "ProductStocks", "ProductStock").each do |sku|
59
59
  hash[sku['SellerSku']] = sku['ReservedStock']
60
- end
60
+ end if resp.dig('SuccessResponse').present?
61
61
  hash
62
62
  end
63
63
 
@@ -46,7 +46,7 @@ class ItemBuilderMwh
46
46
  hash = Hash.new
47
47
  resp['zilingoSKUQuantities'].each do |sku|
48
48
  hash[sku['zilingoSKUId']] = sku['quantity'] + sku['frozenQuantity']
49
- end
49
+ end if resp['zilingoSKUQuantities'].present?
50
50
  hash
51
51
  end
52
52
 
@@ -8,6 +8,7 @@ require 'item_builder_mwh/modes/quantity_service'
8
8
  require 'item_builder_mwh/modes/simple_service'
9
9
  require 'item_models'
10
10
  require 'item_builder_mwh/zilingo_quantity_service'
11
+ require 'item_builder_mwh/lazada_quantity_service'
11
12
  require 'item_builder_mwh/zalora_quantity_service'
12
13
  require 'item_builder_mwh/shopify_quantity_service'
13
14
 
@@ -39,24 +40,23 @@ class ItemBuilderMwh
39
40
  listings.map do |listing|
40
41
  next unless listing.local_id.present?
41
42
 
42
- if listing.channel_id == 18
43
- new_param = qty_simple_params(listing)
44
- .merge({zilingo_quantity: zilingo_quantity})
45
-
46
- modes[mode].new(new_param).perform
47
- elsif listing.channel_id == 13
48
- new_param = qty_simple_params(listing)
49
- .merge({zalora_reserved_stock: zalora_reserved_stock})
50
-
51
- modes[mode].new(new_param).perform
52
- elsif listing.channel_id == 2
53
- new_param = qty_simple_params(listing)
54
- .merge({shopify_inventory_location: shopify_inventory_location})
55
-
56
- modes[mode].new(new_param).perform
57
- else
58
- modes[mode].new(qty_simple_params(listing)).perform
59
- end
43
+ param =
44
+ if listing.channel_id == 18
45
+ qty_simple_params(listing)
46
+ .merge(zilingo_quantity: @zilingo_quantity)
47
+ elsif listing.channel_id == 13
48
+ qty_simple_params(listing)
49
+ .merge(zalora_reserved_stock: @zalora_reserved_stock)
50
+ elsif listing.channel_id == 2
51
+ qty_simple_params(listing)
52
+ .merge({shopify_inventory_location: @shopify_inventory_location})
53
+ elsif listing.channel_id == 3
54
+ qty_simple_params(listing)
55
+ .merge({lazada_quantity: @lazada_quantity})
56
+ else
57
+ qty_simple_params(listing)
58
+ end
59
+ modes[mode].new(param).perform
60
60
  end.compact
61
61
  end
62
62
 
@@ -154,6 +154,12 @@ class ItemBuilderMwh
154
154
  ).perform
155
155
  end
156
156
 
157
+ def lazada_quantity
158
+ @lazada_quantity ||= ItemBuilderMwh::LazadaQuantityService.new(
159
+ listings: listings, skus: skus
160
+ ).perform
161
+ end
162
+
157
163
  def order_host
158
164
  url = ENV['ORDERS_URL'] || 'orders.forstok.com'
159
165
  url + '/api/v3/item_line/reserved_stock'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: item_builder_mwh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Ivander
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-02 00:00:00.000000000 Z
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,6 +117,7 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - lib/item_builder_mwh.rb
119
119
  - lib/item_builder_mwh/get_quantity_service.rb
120
+ - lib/item_builder_mwh/lazada_quantity_service.rb
120
121
  - lib/item_builder_mwh/modes.rb
121
122
  - lib/item_builder_mwh/modes/active_service.rb
122
123
  - lib/item_builder_mwh/modes/base_service.rb
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  - !ruby/object:Gem::Version
166
167
  version: '0'
167
168
  requirements: []
168
- rubygems_version: 3.2.3
169
+ rubygems_version: 3.0.9
169
170
  signing_key:
170
171
  specification_version: 4
171
172
  summary: Item Builder Multiwarehouse