item_builder 0.1.37 → 0.1.38
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.rb +10 -6
- data/lib/item_builder/get_quantity_service.rb +1 -1
- data/lib/item_builder/modes.rb +8 -8
- data/lib/item_builder/modes/active_service.rb +3 -3
- data/lib/item_builder/modes/quantity/base.rb +3 -3
- data/lib/item_builder/modes/quantity/lazada_service.rb +1 -1
- data/lib/item_builder/modes/quantity/zalora_service.rb +1 -1
- data/lib/item_builder/modes/quantity/zilingo_service.rb +1 -1
- data/lib/item_builder/modes/quantity_service.rb +7 -4
- data/lib/item_builder/modes/simple_service.rb +2 -2
- data/lib/item_builder/version.rb +1 -1
- data/lib/item_builder/zalora_quantity_service.rb +7 -6
- data/lib/item_builder/zilingo_quantity_service.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e5978f4671ec45e2e71e9e2656b7b40e13a48a7beca282c25149963066958e3
|
4
|
+
data.tar.gz: b89bb4ccea8a89fd7d456c8b45283bf3917c0d290fad4eeb773235456a031764
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4462f8fa85ec85e6b9960b6114431b30372eb0df207e57257a42f7d7fcbc55c76b38d92e2c978bf202ec389491d819b5ae8eacc12898a3130a14b81929d6143e
|
7
|
+
data.tar.gz: 3ef0ce28611e19beb65a84540d732ed3034f7ec59310a52975dc75add648a6e584945e61dc6c32f9ac2f53ce13456bfddde9118d9af075d1ea65c98fdacd2815
|
data/lib/item_builder.rb
CHANGED
@@ -29,7 +29,7 @@ class ItemBuilder
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def mode_check
|
32
|
-
if mode == :quantity || mode == :simple
|
32
|
+
if mode == :quantity || mode == :simple
|
33
33
|
quantity_simple_mode
|
34
34
|
else
|
35
35
|
default
|
@@ -40,12 +40,12 @@ class ItemBuilder
|
|
40
40
|
listings.map do |listing|
|
41
41
|
if listing.channel_id == 18
|
42
42
|
new_param = qty_simple_params(listing)
|
43
|
-
.merge(
|
43
|
+
.merge(zilingo_quantity: zilingo_quantity)
|
44
44
|
|
45
45
|
modes[mode].new(new_param).perform
|
46
46
|
elsif listing.channel_id == 13
|
47
47
|
new_param = qty_simple_params(listing)
|
48
|
-
.merge(
|
48
|
+
.merge(zalora_reserved_stock: zalora_reserved_stock)
|
49
49
|
|
50
50
|
modes[mode].new(new_param).perform
|
51
51
|
else
|
@@ -60,7 +60,7 @@ class ItemBuilder
|
|
60
60
|
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
61
61
|
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
62
62
|
existing_alloc_stocks: existing_alloc_stocks,
|
63
|
-
reserved_stocks: reserved_stocks
|
63
|
+
reserved_stocks: reserved_stocks
|
64
64
|
}
|
65
65
|
end
|
66
66
|
|
@@ -68,6 +68,10 @@ class ItemBuilder
|
|
68
68
|
listings.map do |listing|
|
69
69
|
if listing.channel_id == 2 && mode == :active
|
70
70
|
modes[mode].new(qty_simple_params(listing)).perform
|
71
|
+
elsif listing.channel_id == 18 && mode == :active
|
72
|
+
modes[mode].new(qty_simple_params(listing)
|
73
|
+
.merge(zilingo_quantity: zilingo_quantity)
|
74
|
+
).perform
|
71
75
|
else
|
72
76
|
modes[mode].new(listing: listing).perform
|
73
77
|
end
|
@@ -128,8 +132,8 @@ class ItemBuilder
|
|
128
132
|
@skus ||= listings.map(&:local_id).uniq
|
129
133
|
end
|
130
134
|
|
131
|
-
def
|
132
|
-
@
|
135
|
+
def zilingo_quantity
|
136
|
+
@zilingo_quantity ||= ItemBuilder::ZilingoQuantityService.new(
|
133
137
|
listings: listings, skus: skus
|
134
138
|
).perform
|
135
139
|
end
|
data/lib/item_builder/modes.rb
CHANGED
@@ -17,7 +17,7 @@ class ItemBuilder
|
|
17
17
|
attr_reader :existing_alloc_stocks
|
18
18
|
attr_reader :variant_listings
|
19
19
|
attr_reader :reserved_stocks
|
20
|
-
attr_reader :
|
20
|
+
attr_reader :zilingo_quantity
|
21
21
|
attr_reader :zalora_reserved_stock
|
22
22
|
def initialize(args)
|
23
23
|
@listing = args.fetch(:listing)
|
@@ -29,7 +29,7 @@ class ItemBuilder
|
|
29
29
|
@existing_alloc_stocks = args.fetch(:existing_alloc_stocks, [])
|
30
30
|
@variant_listings = args.fetch(:variant_listings, [])
|
31
31
|
@reserved_stocks = args.fetch(:reserved_stocks, [])
|
32
|
-
@
|
32
|
+
@zilingo_quantity = args.fetch(:zilingo_quantity, [])
|
33
33
|
@zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
|
34
34
|
end
|
35
35
|
|
@@ -51,29 +51,29 @@ class ItemBuilder
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def listings
|
54
|
-
variant_listings.select {|vl| vl.variant_id == listing.variant_id}
|
54
|
+
variant_listings.select { |vl| vl.variant_id == listing.variant_id}
|
55
55
|
end
|
56
56
|
|
57
57
|
def bundle_variants
|
58
58
|
if bundle.present?
|
59
|
-
item_bundle_variants.select {|ibv| ibv.bundle_id == bundle.id }
|
59
|
+
item_bundle_variants.select { |ibv| ibv.bundle_id == bundle.id }
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
def bundle
|
64
|
-
bundles.select {|b| b.variant_id == listing.variant_id }.first
|
64
|
+
bundles.select { |b| b.variant_id == listing.variant_id }.first
|
65
65
|
end
|
66
66
|
|
67
67
|
def stock_alloc
|
68
|
-
stock_allocs.select {|sa| sa.variant_association_id == listing.id }.first
|
68
|
+
stock_allocs.select { |sa| sa.variant_association_id == listing.id }.first
|
69
69
|
end
|
70
70
|
|
71
71
|
def warehouse
|
72
|
-
wh_spaces.select {|ws| ws.item_variant_id == listing.variant_id }.first
|
72
|
+
wh_spaces.select { |ws| ws.item_variant_id == listing.variant_id }.first
|
73
73
|
end
|
74
74
|
|
75
75
|
def variant
|
76
|
-
variants.select {|v| v.id == listing.variant_id }.first
|
76
|
+
variants.select { |v| v.id == listing.variant_id }.first
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -8,7 +8,7 @@ class ItemBuilder
|
|
8
8
|
include Modes
|
9
9
|
|
10
10
|
def perform
|
11
|
-
if listing.channel_id == 2
|
11
|
+
if listing.channel_id == 2 || listing.channel_id == 18
|
12
12
|
to_h.merge(base).merge(quantity)
|
13
13
|
else
|
14
14
|
to_h.merge(base)
|
@@ -28,8 +28,8 @@ class ItemBuilder
|
|
28
28
|
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
29
29
|
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
30
30
|
existing_alloc_stocks: existing_alloc_stocks,
|
31
|
-
reserved_stocks: reserved_stocks,
|
32
|
-
|
31
|
+
reserved_stocks: reserved_stocks,
|
32
|
+
zilingo_quantity: zilingo_quantity,
|
33
33
|
zalora_reserved_stock: zalora_reserved_stock
|
34
34
|
).to_h
|
35
35
|
end
|
@@ -6,14 +6,14 @@ class ItemBuilder
|
|
6
6
|
class Base
|
7
7
|
attr_reader :listing
|
8
8
|
attr_reader :available_quantity
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :local_qty
|
10
10
|
|
11
|
-
def initialize(listing, available_quantity,
|
11
|
+
def initialize(listing, available_quantity, local_qty)
|
12
12
|
raise 'listing is not set' if listing.nil?
|
13
13
|
|
14
14
|
@listing = listing
|
15
15
|
@available_quantity = available_quantity
|
16
|
-
@
|
16
|
+
@local_qty = local_qty
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -39,21 +39,24 @@ class ItemBuilder
|
|
39
39
|
def qty_channel
|
40
40
|
class_name = "ItemBuilder::Modes::Quantity::#{channel_name}Service"
|
41
41
|
qty_channel_service = class_name.constantize
|
42
|
-
qty_channel_service.new(listing, available_quantity,
|
42
|
+
qty_channel_service.new(listing, available_quantity, local_qty.to_i).perform
|
43
43
|
end
|
44
44
|
|
45
45
|
def channel_name
|
46
46
|
QUANTITY_CHANNEL[listing.channel_id].to_s
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
49
|
+
def local_qty
|
50
50
|
if channel_name == 'Zilingo'
|
51
|
-
|
51
|
+
return 0 if zilingo_quantity.blank?
|
52
|
+
|
53
|
+
zilingo_quantity[listing.local_id].to_i
|
52
54
|
elsif channel_name == 'Zalora'
|
53
55
|
return 0 if zalora_reserved_stock.blank?
|
56
|
+
|
54
57
|
zalora_reserved_stock[listing.local_id].to_i
|
55
58
|
else
|
56
|
-
reserved_stocks.find {|rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
|
59
|
+
reserved_stocks.find { |rs| rs['variant_id'] == listing.variant_id }['reserved_quantity']
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
@@ -22,8 +22,8 @@ class ItemBuilder
|
|
22
22
|
stock_allocs: stock_allocs, variant_listings: variant_listings,
|
23
23
|
bundles: bundles, item_bundle_variants: item_bundle_variants,
|
24
24
|
existing_alloc_stocks: existing_alloc_stocks,
|
25
|
-
reserved_stocks: reserved_stocks,
|
26
|
-
|
25
|
+
reserved_stocks: reserved_stocks,
|
26
|
+
zilingo_quantity: zilingo_quantity
|
27
27
|
).to_h
|
28
28
|
end
|
29
29
|
|
data/lib/item_builder/version.rb
CHANGED
@@ -6,7 +6,7 @@ class ItemBuilder
|
|
6
6
|
attr_reader :listings, :skus
|
7
7
|
def initialize(args)
|
8
8
|
@listings = args.fetch(:listings)
|
9
|
-
@skus = args.fetch(:skus)
|
9
|
+
@skus = args.fetch(:skus)
|
10
10
|
end
|
11
11
|
|
12
12
|
def perform
|
@@ -39,21 +39,22 @@ class ItemBuilder
|
|
39
39
|
|
40
40
|
def url
|
41
41
|
url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
|
42
|
-
url +
|
42
|
+
url + '/zalora/product_stocks'
|
43
43
|
end
|
44
44
|
|
45
45
|
def response_process(resp)
|
46
|
-
if resp.dig(
|
47
|
-
raise "Response Code is #{resp.dig(
|
46
|
+
if resp.dig('response_code') && resp.dig('response_code') != 200
|
47
|
+
raise "Response Code is #{resp.dig('response_code')}"
|
48
48
|
elsif resp.dig('ErrorResponse', 'Head', 'ErrorMessage') == 'E009: Access Denied'
|
49
49
|
return nil
|
50
50
|
end
|
51
|
+
|
51
52
|
success_handle(resp)
|
52
53
|
end
|
53
54
|
|
54
55
|
def success_handle(resp)
|
55
|
-
hash =
|
56
|
-
resp.dig(
|
56
|
+
hash = {}
|
57
|
+
resp.dig('SuccessResponse', 'Body', 'ProductStocks', 'ProductStock').each do |sku|
|
57
58
|
hash[sku['SellerSku']] = sku['ReservedStock']
|
58
59
|
end
|
59
60
|
hash
|
@@ -6,7 +6,7 @@ class ItemBuilder
|
|
6
6
|
attr_reader :listings, :skus
|
7
7
|
def initialize(args)
|
8
8
|
@listings = args.fetch(:listings)
|
9
|
-
@skus = args.fetch(:skus)
|
9
|
+
@skus = args.fetch(:skus)
|
10
10
|
end
|
11
11
|
|
12
12
|
def perform
|
@@ -39,11 +39,11 @@ class ItemBuilder
|
|
39
39
|
|
40
40
|
def url
|
41
41
|
url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
|
42
|
-
url +
|
42
|
+
url + '/zilingo/item_quantity_by_sku'
|
43
43
|
end
|
44
44
|
|
45
45
|
def response_process(resp)
|
46
|
-
hash =
|
46
|
+
hash = {}
|
47
47
|
resp['zilingoSKUQuantities'].each do |sku|
|
48
48
|
hash[sku['zilingoSKUId']] = sku['quantity'] + sku['frozenQuantity']
|
49
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: item_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okaaryanata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|