item_builder_mwh 0.1.25 → 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/item_builder_mwh/lazada_quantity_service.rb +67 -0
- data/lib/item_builder_mwh/modes/active_service.rb +3 -3
- data/lib/item_builder_mwh/modes/price_service.rb +2 -2
- data/lib/item_builder_mwh/modes/quantity_service.rb +19 -15
- data/lib/item_builder_mwh/modes/simple_service.rb +5 -5
- data/lib/item_builder_mwh/modes.rb +10 -0
- data/lib/item_builder_mwh/shopify_quantity_service.rb +16 -6
- data/lib/item_builder_mwh/version.rb +1 -1
- data/lib/item_builder_mwh/zalora_quantity_service.rb +1 -1
- data/lib/item_builder_mwh/zilingo_quantity_service.rb +1 -1
- data/lib/item_builder_mwh.rb +26 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b78cf06c6468a43cb0276bce86475e9e26225998a51a07ebc0f5abcccbb275a
|
4
|
+
data.tar.gz: 26f16ef4c2b1e4c0d27ba8f1da2817b1c185713c0fa64af76f440ce9ec218eec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5db1144fc273bb1861c8477a72dfc9d119c98e6c0fddb9befc07d13b431bfe116075ec0c70b315de618b2d7ddc35f9c8d8e4b241f8e26421d15b8a3ec502ac55
|
7
|
+
data.tar.gz: 0a02b711a5dd12ebd751ffa106f786949456c25b555638962a102fbee3ef57c9ee5bb34e34e37d9af6ba673c357b8be82f88b88d21895293a4bbed43ef79bff4
|
@@ -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
|
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
|
@@ -15,13 +15,16 @@ 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
|
21
22
|
|
22
23
|
def perform
|
23
24
|
if channel_name == "Shopify"
|
24
|
-
|
25
|
+
dataSIL = shopify_inventory_location[listing.local_id]
|
26
|
+
|
27
|
+
base.merge!(dataSIL, warehouse: warehouses ) if dataSIL.present?
|
25
28
|
else
|
26
29
|
base.merge!(
|
27
30
|
warehouse: warehouses
|
@@ -30,20 +33,19 @@ class ItemBuilderMwh
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def to_h(warehouse_space)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
warehouse_id
|
37
|
-
|
38
|
-
|
39
|
-
|
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)
|
40
47
|
else
|
41
|
-
|
42
|
-
quantity: [qty(warehouse_space.quantity), 0].sort[1],
|
43
|
-
warehouse_id: wh_mapping(
|
44
|
-
warehouse_space.warehouse_id
|
45
|
-
)
|
46
|
-
}
|
48
|
+
[qty(warehouse_space.quantity), 0].sort[1]
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -75,7 +77,9 @@ class ItemBuilderMwh
|
|
75
77
|
|
76
78
|
zalora_reserved_stock[listing.local_id].to_i
|
77
79
|
else
|
78
|
-
|
80
|
+
return 0 if lazada_quantity.blank?
|
81
|
+
|
82
|
+
lazada_quantity[listing.local_id].to_i
|
79
83
|
end
|
80
84
|
end
|
81
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
|
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
|
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
|
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
|
|
@@ -14,9 +14,14 @@ class ItemBuilderMwh
|
|
14
14
|
def perform
|
15
15
|
datas = {}
|
16
16
|
@listings.each do |listing|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if listing.local_id.present?
|
18
|
+
@listing = listing
|
19
|
+
@sku = listing.local_id
|
20
|
+
resp = response_process
|
21
|
+
next if resp[:inventory_item_id].nil? || resp[:inventory_item_id] == 0
|
22
|
+
|
23
|
+
datas[@sku] = resp
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
# update variant real_local_id database icava
|
@@ -100,8 +105,12 @@ class ItemBuilderMwh
|
|
100
105
|
def response_process
|
101
106
|
hash = Hash.new
|
102
107
|
|
103
|
-
|
104
|
-
|
108
|
+
begin
|
109
|
+
hash[:inventory_item_id] = inventory_item_id.to_i
|
110
|
+
hash[:location_id] = location_id.to_i
|
111
|
+
rescue
|
112
|
+
hash
|
113
|
+
end
|
105
114
|
|
106
115
|
hash
|
107
116
|
end
|
@@ -109,8 +118,9 @@ class ItemBuilderMwh
|
|
109
118
|
def rest_client(params, rescued_codes = 200)
|
110
119
|
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
111
120
|
code = response.code
|
121
|
+
resp = response.body.to_str
|
112
122
|
unless Array.wrap(rescued_codes).include?(code)
|
113
|
-
raise "Response Code is #{code}"
|
123
|
+
raise "Response Code is #{code}" unless resp.include?('Response code = 404')
|
114
124
|
end
|
115
125
|
|
116
126
|
response
|
data/lib/item_builder_mwh.rb
CHANGED
@@ -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
|
|
@@ -37,6 +38,8 @@ class ItemBuilderMwh
|
|
37
38
|
|
38
39
|
def quantity_simple_mode
|
39
40
|
listings.map do |listing|
|
41
|
+
next unless listing.local_id.present?
|
42
|
+
|
40
43
|
if listing.channel_id == 18
|
41
44
|
new_param = qty_simple_params(listing)
|
42
45
|
.merge({zilingo_quantity: zilingo_quantity})
|
@@ -51,23 +54,30 @@ class ItemBuilderMwh
|
|
51
54
|
new_param = qty_simple_params(listing)
|
52
55
|
.merge({shopify_inventory_location: shopify_inventory_location})
|
53
56
|
|
57
|
+
modes[mode].new(new_param).perform
|
58
|
+
elsif listing.channel_id == 3
|
59
|
+
new_param = qty_simple_params(listing)
|
60
|
+
.merge({lazada_quantity: lazada_quantity})
|
61
|
+
|
54
62
|
modes[mode].new(new_param).perform
|
55
63
|
else
|
56
64
|
modes[mode].new(qty_simple_params(listing)).perform
|
57
65
|
end
|
58
|
-
end
|
66
|
+
end.compact
|
59
67
|
end
|
60
68
|
|
61
69
|
def default
|
62
70
|
listings.map do |listing|
|
63
|
-
if listing.
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
if listing.local_id.present?
|
72
|
+
if listing.channel_id == 2 && mode == :active
|
73
|
+
modes[mode].new(qty_simple_params(listing)).perform
|
74
|
+
elsif listing.channel_id == 18 && mode == :active
|
75
|
+
modes[mode].new(qty_simple_params(listing)
|
76
|
+
.merge(zilingo_quantity: zilingo_quantity)
|
77
|
+
).perform
|
78
|
+
else
|
79
|
+
modes[mode].new(listing: listing).perform
|
80
|
+
end
|
71
81
|
end
|
72
82
|
end
|
73
83
|
end
|
@@ -150,6 +160,12 @@ class ItemBuilderMwh
|
|
150
160
|
).perform
|
151
161
|
end
|
152
162
|
|
163
|
+
def lazada_quantity
|
164
|
+
@lazada_quantity ||= ItemBuilderMwh::LazadaQuantityService.new(
|
165
|
+
listings: listings, skus: skus
|
166
|
+
).perform
|
167
|
+
end
|
168
|
+
|
153
169
|
def order_host
|
154
170
|
url = ENV['ORDERS_URL'] || 'orders.forstok.com'
|
155
171
|
url + '/api/v3/item_line/reserved_stock'
|
@@ -176,6 +192,6 @@ class ItemBuilderMwh
|
|
176
192
|
end
|
177
193
|
|
178
194
|
def listings
|
179
|
-
@listings ||= VariantListing.where(id: listing_ids)
|
195
|
+
@listings ||= VariantListing.joins(:variant).where(id: listing_ids)
|
180
196
|
end
|
181
197
|
end
|
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.
|
4
|
+
version: 0.1.29
|
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-08
|
11
|
+
date: 2021-09-08 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
|