item_builder_mwh 0.1.11 → 0.1.16
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.rb +31 -1
- data/lib/item_builder_mwh/get_quantity_service.rb +1 -1
- data/lib/item_builder_mwh/modes.rb +4 -0
- data/lib/item_builder_mwh/modes/price/sale_price_policy.rb +5 -1
- data/lib/item_builder_mwh/modes/quantity/zilingo_service.rb +14 -0
- data/lib/item_builder_mwh/modes/quantity_service.rb +11 -2
- data/lib/item_builder_mwh/version.rb +1 -1
- data/lib/item_builder_mwh/zalora_quantity_service.rb +68 -0
- data/lib/item_builder_mwh/zilingo_quantity_service.rb +64 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9267900d48fc70b5b7c41943cda2dde2b7a1c5732c26085bf2411e0683fe677a
|
4
|
+
data.tar.gz: bd40a5dfc2a2f9dfbc4278e59bdd795e8b375666e466faf641b9235fccbcfba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9beefb0a4650bf6bdf4d5ff7613c220b503764091395573de87f09ad2db2208ff5e6cc329384c36ae76252ad44cfc88fb86929d78b17b96dcf525491e0663f49
|
7
|
+
data.tar.gz: 9303229b16cb1fee06661b10103e85602eb465b56d25a0336cc5663011013ac0e7e4f5da6b8f32b4cba6fd2144fbbd371b124a4bf9876b7f55692f5f17f303ad
|
data/lib/item_builder_mwh.rb
CHANGED
@@ -7,6 +7,8 @@ require 'item_builder_mwh/modes/price_service'
|
|
7
7
|
require 'item_builder_mwh/modes/quantity_service'
|
8
8
|
require 'item_builder_mwh/modes/simple_service'
|
9
9
|
require 'item_models'
|
10
|
+
require 'item_builder_mwh/zilingo_quantity_service'
|
11
|
+
require 'item_builder_mwh/zalora_quantity_service'
|
10
12
|
|
11
13
|
class ItemBuilderMwh
|
12
14
|
attr_reader :listing_ids
|
@@ -34,7 +36,19 @@ class ItemBuilderMwh
|
|
34
36
|
|
35
37
|
def quantity_simple_mode
|
36
38
|
listings.map do |listing|
|
37
|
-
|
39
|
+
if listing.channel_id == 18
|
40
|
+
new_param = qty_simple_params(listing)
|
41
|
+
.merge({zilingo_delta_quantity: zilingo_delta_quantity})
|
42
|
+
|
43
|
+
modes[mode].new(new_param).perform
|
44
|
+
elsif listing.channel_id == 13
|
45
|
+
new_param = qty_simple_params(listing)
|
46
|
+
.merge({zalora_reserved_stock: zalora_reserved_stock})
|
47
|
+
|
48
|
+
modes[mode].new(new_param).perform
|
49
|
+
else
|
50
|
+
modes[mode].new(qty_simple_params(listing)).perform
|
51
|
+
end
|
38
52
|
end
|
39
53
|
end
|
40
54
|
|
@@ -100,6 +114,22 @@ class ItemBuilderMwh
|
|
100
114
|
@variant_ids ||= listings.map(&:variant_id).uniq
|
101
115
|
end
|
102
116
|
|
117
|
+
def skus
|
118
|
+
@skus ||= listings.map(&:local_id).uniq
|
119
|
+
end
|
120
|
+
|
121
|
+
def zilingo_delta_quantity
|
122
|
+
@zilingo_delta_quantity ||= ItemBuilderMwh::ZilingoQuantityService.new(
|
123
|
+
listings: listings, skus: skus
|
124
|
+
).perform
|
125
|
+
end
|
126
|
+
|
127
|
+
def zalora_reserved_stock
|
128
|
+
@zalora_reserved_stock ||= ItemBuilderMwh::ZaloraQuantityService.new(
|
129
|
+
listings: listings, skus: skus
|
130
|
+
).perform
|
131
|
+
end
|
132
|
+
|
103
133
|
def order_host
|
104
134
|
url = ENV['ORDERS_URL'] || 'orders.forstok.com'
|
105
135
|
url + '/api/v3/item_line/reserved_stock'
|
@@ -16,6 +16,8 @@ class ItemBuilderMwh
|
|
16
16
|
attr_reader :existing_alloc_stocks
|
17
17
|
attr_reader :variant_listings
|
18
18
|
attr_reader :reserved_stocks
|
19
|
+
attr_reader :zilingo_delta_quantity
|
20
|
+
attr_reader :zalora_reserved_stock
|
19
21
|
def initialize(args)
|
20
22
|
@listing = args.fetch(:listing)
|
21
23
|
@wh_spaces = args.fetch(:wh_spaces, [])
|
@@ -26,6 +28,8 @@ class ItemBuilderMwh
|
|
26
28
|
@existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
|
27
29
|
@variant_listings = args.fetch(:variant_listings, [])
|
28
30
|
@reserved_stocks = args.fetch(:reserved_stocks, [])
|
31
|
+
@zilingo_delta_quantity = args.fetch(:zilingo_delta_quantity, [])
|
32
|
+
@zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
|
29
33
|
warehouse
|
30
34
|
end
|
31
35
|
|
@@ -7,7 +7,11 @@ class ItemBuilderMwh
|
|
7
7
|
module Modes
|
8
8
|
module Price
|
9
9
|
class SalePricePolicy
|
10
|
-
|
10
|
+
attr_reader :listing
|
11
|
+
def initialize(args)
|
12
|
+
@listing = args.fetch(:listing)
|
13
|
+
end
|
14
|
+
|
11
15
|
def sale_price
|
12
16
|
# has sale price but no sale date defined
|
13
17
|
# then push sale price immediately
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'item_builder_mwh/modes/quantity/base'
|
4
|
+
class ItemBuilderMwh
|
5
|
+
module Modes
|
6
|
+
module Quantity
|
7
|
+
class ZilingoService < Base
|
8
|
+
def perform
|
9
|
+
available_quantity - reserved_stock.to_i
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -6,6 +6,8 @@ require 'item_builder_mwh/get_quantity_service'
|
|
6
6
|
require 'item_builder_mwh/modes/quantity/base'
|
7
7
|
require 'item_builder_mwh/modes/quantity/lazada_service'
|
8
8
|
require 'item_builder_mwh/modes/quantity/zalora_service'
|
9
|
+
require 'item_builder_mwh/modes/quantity/zilingo_service'
|
10
|
+
|
9
11
|
class ItemBuilderMwh
|
10
12
|
module Modes
|
11
13
|
class QuantityService
|
@@ -14,6 +16,7 @@ class ItemBuilderMwh
|
|
14
16
|
QUANTITY_CHANNEL = {}.tap do |hash|
|
15
17
|
hash[3] = :Lazada
|
16
18
|
hash[13] = :Zalora
|
19
|
+
hash[18] = :Zilingo
|
17
20
|
end.freeze
|
18
21
|
|
19
22
|
def perform
|
@@ -24,7 +27,7 @@ class ItemBuilderMwh
|
|
24
27
|
|
25
28
|
def to_h(warehouse_space)
|
26
29
|
{
|
27
|
-
quantity: qty(warehouse_space.quantity),
|
30
|
+
quantity: [qty(warehouse_space.quantity), 0].sort[1],
|
28
31
|
warehouse_id: wh_mapping(
|
29
32
|
warehouse_space.warehouse_id
|
30
33
|
)
|
@@ -50,7 +53,13 @@ class ItemBuilderMwh
|
|
50
53
|
end
|
51
54
|
|
52
55
|
def reserved_stock
|
53
|
-
|
56
|
+
if channel_name == 'Zilingo'
|
57
|
+
zilingo_delta_quantity[listing.local_id].to_i
|
58
|
+
elsif channel_name == 'Zalora'
|
59
|
+
zalora_reserved_stock[listing.local_id].to_i
|
60
|
+
else
|
61
|
+
reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
|
62
|
+
end
|
54
63
|
end
|
55
64
|
|
56
65
|
def available_quantity(qty)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'item_builder_mwh/modes.rb'
|
4
|
+
class ItemBuilderMwh
|
5
|
+
class ZaloraQuantityService
|
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 }
|
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 + "/zalora/product_stocks"
|
43
|
+
end
|
44
|
+
|
45
|
+
def response_process(resp)
|
46
|
+
if resp.dig("response_code") && resp.dig("response_code") != 200
|
47
|
+
raise "Response Code is #{resp.dig("response_code")}"
|
48
|
+
end
|
49
|
+
|
50
|
+
hash = Hash.new
|
51
|
+
resp.dig("SuccessResponse", "Body", "ProductStocks", "ProductStock").each do |sku|
|
52
|
+
hash[sku['SellerSku']] = sku['ReservedStock']
|
53
|
+
end
|
54
|
+
hash
|
55
|
+
end
|
56
|
+
|
57
|
+
def rest_client(params, rescued_codes = 200)
|
58
|
+
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
59
|
+
code = response.code
|
60
|
+
unless Array.wrap(rescued_codes).include?(code)
|
61
|
+
raise "Response Code is #{code}"
|
62
|
+
end
|
63
|
+
|
64
|
+
response
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'item_builder_mwh/modes.rb'
|
4
|
+
class ItemBuilderMwh
|
5
|
+
class ZilingoQuantityService
|
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 }
|
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 + "/zilingo/item_quantity_by_sku"
|
43
|
+
end
|
44
|
+
|
45
|
+
def response_process(resp)
|
46
|
+
hash = Hash.new
|
47
|
+
resp['zilingoSKUQuantities'].each do |sku|
|
48
|
+
hash[sku['zilingoSKUId']] = sku['quantity'] + sku['frozenQuantity']
|
49
|
+
end
|
50
|
+
hash
|
51
|
+
end
|
52
|
+
|
53
|
+
def rest_client(params, rescued_codes = 200)
|
54
|
+
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
55
|
+
code = response.code
|
56
|
+
unless Array.wrap(rescued_codes).include?(code)
|
57
|
+
raise "Response Code is #{code}"
|
58
|
+
end
|
59
|
+
|
60
|
+
response
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
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.16
|
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-
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- lib/item_builder_mwh/modes/quantity/base.rb
|
132
132
|
- lib/item_builder_mwh/modes/quantity/lazada_service.rb
|
133
133
|
- lib/item_builder_mwh/modes/quantity/zalora_service.rb
|
134
|
+
- lib/item_builder_mwh/modes/quantity/zilingo_service.rb
|
134
135
|
- lib/item_builder_mwh/modes/quantity_service.rb
|
135
136
|
- lib/item_builder_mwh/modes/simple/base.rb
|
136
137
|
- lib/item_builder_mwh/modes/simple/blibli_service.rb
|
@@ -143,6 +144,8 @@ files:
|
|
143
144
|
- lib/item_builder_mwh/modes/simple/zalora_service.rb
|
144
145
|
- lib/item_builder_mwh/modes/simple_service.rb
|
145
146
|
- lib/item_builder_mwh/version.rb
|
147
|
+
- lib/item_builder_mwh/zalora_quantity_service.rb
|
148
|
+
- lib/item_builder_mwh/zilingo_quantity_service.rb
|
146
149
|
homepage:
|
147
150
|
licenses: []
|
148
151
|
metadata: {}
|
@@ -161,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
164
|
- !ruby/object:Gem::Version
|
162
165
|
version: '0'
|
163
166
|
requirements: []
|
164
|
-
rubygems_version: 3.0.
|
167
|
+
rubygems_version: 3.0.9
|
165
168
|
signing_key:
|
166
169
|
specification_version: 4
|
167
170
|
summary: Item Builder Multiwarehouse
|