item_builder 0.1.38 → 0.1.39
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 +12 -1
- data/lib/item_builder/modes.rb +2 -0
- data/lib/item_builder/modes/quantity_service.rb +7 -2
- data/lib/item_builder/shopify_quantity_service.rb +118 -0
- data/lib/item_builder/version.rb +1 -1
- 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: 33a795a8c5bc377cb851c71b81db06c9e7e56002c46dedbd55fbddb7fe6f2d0b
|
4
|
+
data.tar.gz: 0af4f467706e87b849455dd0a0a45ee21785f82820fbf2631aeee31540a44a2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2855fd51aef9dcd3c36c8c0776b83149d65598b661a6e1c87fe815e4e32bb2a7f2ffe74f1009ef6c492e0574787088c72b15e7408bfb4b2f4d70b7bd9a10eecc
|
7
|
+
data.tar.gz: 2f6e91d85c03dc6df7abfe7af2db1b833c8e1a5f82772a96b40db135a02bcd2bd3f913b91afb0fb19c493f73ed99de337452f94e832c647dae7ee8d1c97a08d4
|
data/lib/item_builder.rb
CHANGED
@@ -10,7 +10,7 @@ require 'item_builder/modes/active_service'
|
|
10
10
|
require 'item_models'
|
11
11
|
require 'item_builder/zilingo_quantity_service'
|
12
12
|
require 'item_builder/zalora_quantity_service'
|
13
|
-
|
13
|
+
require 'item_builder/shopify_quantity_service'
|
14
14
|
class ItemBuilder
|
15
15
|
def self.build(listing_ids, mode)
|
16
16
|
new(listing_ids, mode).mode_check
|
@@ -47,6 +47,11 @@ class ItemBuilder
|
|
47
47
|
new_param = qty_simple_params(listing)
|
48
48
|
.merge(zalora_reserved_stock: zalora_reserved_stock)
|
49
49
|
|
50
|
+
modes[mode].new(new_param).perform
|
51
|
+
elsif listing.channel_id == 2
|
52
|
+
new_param = qty_simple_params(listing)
|
53
|
+
.merge({shopify_inventory_location: shopify_inventory_location})
|
54
|
+
|
50
55
|
modes[mode].new(new_param).perform
|
51
56
|
else
|
52
57
|
modes[mode].new(qty_simple_params(listing)).perform
|
@@ -144,6 +149,12 @@ class ItemBuilder
|
|
144
149
|
).perform
|
145
150
|
end
|
146
151
|
|
152
|
+
def shopify_inventory_location
|
153
|
+
@shopify_inventory_location ||= ItemBuilder::ShopifyQuantityService.new(
|
154
|
+
listings: listings, skus: skus
|
155
|
+
).perform
|
156
|
+
end
|
157
|
+
|
147
158
|
def modes
|
148
159
|
{
|
149
160
|
price: ItemBuilder::Modes::PriceService,
|
data/lib/item_builder/modes.rb
CHANGED
@@ -19,6 +19,7 @@ class ItemBuilder
|
|
19
19
|
attr_reader :reserved_stocks
|
20
20
|
attr_reader :zilingo_quantity
|
21
21
|
attr_reader :zalora_reserved_stock
|
22
|
+
attr_reader :shopify_inventory_location
|
22
23
|
def initialize(args)
|
23
24
|
@listing = args.fetch(:listing)
|
24
25
|
@wh_spaces = args.fetch(:wh_spaces, [])
|
@@ -31,6 +32,7 @@ class ItemBuilder
|
|
31
32
|
@reserved_stocks = args.fetch(:reserved_stocks, [])
|
32
33
|
@zilingo_quantity = args.fetch(:zilingo_quantity, [])
|
33
34
|
@zalora_reserved_stock = args.fetch(:zalora_reserved_stock, [])
|
35
|
+
@shopify_inventory_location = args.fetch(:shopify_inventory_location, [])
|
34
36
|
end
|
35
37
|
|
36
38
|
def base
|
@@ -14,12 +14,17 @@ class ItemBuilder
|
|
14
14
|
|
15
15
|
QUANTITY_CHANNEL = {}.tap do |hash|
|
16
16
|
hash[3] = :Lazada
|
17
|
+
hash[2] = :Shopify
|
17
18
|
hash[13] = :Zalora
|
18
19
|
hash[18] = :Zilingo
|
19
20
|
end.freeze
|
20
21
|
|
21
22
|
def perform
|
22
|
-
|
23
|
+
if channel_name == "Shopify"
|
24
|
+
base.merge(to_h, shopify_inventory_location[listing.local_id])
|
25
|
+
else
|
26
|
+
to_h.merge(base)
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
def to_h
|
@@ -29,7 +34,7 @@ class ItemBuilder
|
|
29
34
|
end
|
30
35
|
|
31
36
|
def qty
|
32
|
-
if channel_name.empty?
|
37
|
+
if channel_name.empty? || channel_name == "Shopify"
|
33
38
|
available_quantity
|
34
39
|
else
|
35
40
|
qty_channel
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'item_builder/modes.rb'
|
4
|
+
class ItemBuilder
|
5
|
+
class ShopifyQuantityService
|
6
|
+
attr_reader :listings, :skus
|
7
|
+
def initialize(args)
|
8
|
+
@listings = args.fetch(:listings)
|
9
|
+
@skus = args.fetch(:skus)
|
10
|
+
@account_id = listings[0].profile_channel_association_id
|
11
|
+
@variant_listings = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def perform
|
15
|
+
datas = {}
|
16
|
+
|
17
|
+
@listings.each do |listing|
|
18
|
+
@listing = listing
|
19
|
+
@sku = listing.local_id
|
20
|
+
datas[@sku] = response_process
|
21
|
+
end
|
22
|
+
|
23
|
+
# update variant real_local_id database icava
|
24
|
+
VariantListing.update(@variant_listings.keys, @variant_listings.values)
|
25
|
+
datas
|
26
|
+
end
|
27
|
+
|
28
|
+
def inventory_item_id
|
29
|
+
real_local_id = @listing.real_local_id
|
30
|
+
listing_id = @listing.id
|
31
|
+
|
32
|
+
if real_local_id.nil? || real_local_id.blank?
|
33
|
+
# get data from shopify
|
34
|
+
args = {method: :post, url: url_variant, payload: data_variant, headers: headers}
|
35
|
+
|
36
|
+
resp = JSON.parse(rest_client(args, [200, 500, 406]))
|
37
|
+
|
38
|
+
hash = { listing_id => { "real_local_id" => resp['inventory_item_id'] } }
|
39
|
+
@variant_listings = @variant_listings.merge(hash)
|
40
|
+
|
41
|
+
resp['inventory_item_id']
|
42
|
+
else
|
43
|
+
# real_local_id exists
|
44
|
+
real_local_id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def location_id
|
49
|
+
cred = JSON.parse(credential)['credential']
|
50
|
+
if cred['primary_warehouse_id'].present?
|
51
|
+
cred['primary_warehouse_id']
|
52
|
+
else
|
53
|
+
# get data from shopify
|
54
|
+
args = {
|
55
|
+
method: :post, url: url_location, payload: data_location, headers: headers
|
56
|
+
}
|
57
|
+
|
58
|
+
resp = JSON.parse(rest_client(args, [200, 500, 406]))
|
59
|
+
resp['id']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def headers
|
64
|
+
{ content_type: :json, accept: :json }
|
65
|
+
end
|
66
|
+
|
67
|
+
def data_location
|
68
|
+
{
|
69
|
+
"credential": JSON.parse(credential)['credential']
|
70
|
+
}.to_json
|
71
|
+
end
|
72
|
+
|
73
|
+
def data_variant
|
74
|
+
{
|
75
|
+
"credential": JSON.parse(credential)['credential'],
|
76
|
+
"data": { "local_id": @sku }
|
77
|
+
}.to_json
|
78
|
+
end
|
79
|
+
|
80
|
+
def credential
|
81
|
+
return @credential if @credential
|
82
|
+
|
83
|
+
host = ENV['CREDENTIAL_URL'] || raise('credential url is not set')
|
84
|
+
url = "#{host}/credential?account_id=#{@account_id}"
|
85
|
+
@credential = rest_client(method: :get, url: url)
|
86
|
+
end
|
87
|
+
|
88
|
+
def url_variant
|
89
|
+
url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
|
90
|
+
url + "/shopify/data_variant"
|
91
|
+
end
|
92
|
+
|
93
|
+
def url_location
|
94
|
+
url = ENV['API_GATEWAY_URL'] || raise('api gateway is not set')
|
95
|
+
url + "/shopify/data_location"
|
96
|
+
end
|
97
|
+
|
98
|
+
def response_process
|
99
|
+
hash = Hash.new
|
100
|
+
|
101
|
+
hash[:inventory_item_id] = inventory_item_id.to_i
|
102
|
+
hash[:location_id] = location_id.to_i
|
103
|
+
|
104
|
+
hash
|
105
|
+
end
|
106
|
+
|
107
|
+
def rest_client(params, rescued_codes = 200)
|
108
|
+
RestClient::Request.execute(params.merge(timeout: 3)) do |response|
|
109
|
+
code = response.code
|
110
|
+
unless Array.wrap(rescued_codes).include?(code)
|
111
|
+
raise "Response Code is #{code}"
|
112
|
+
end
|
113
|
+
|
114
|
+
response
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/lib/item_builder/version.rb
CHANGED
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.39
|
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-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/item_builder/modes/update/tokopedia_service.rb
|
144
144
|
- lib/item_builder/modes/update/zalora_service.rb
|
145
145
|
- lib/item_builder/modes/update_service.rb
|
146
|
+
- lib/item_builder/shopify_quantity_service.rb
|
146
147
|
- lib/item_builder/version.rb
|
147
148
|
- lib/item_builder/zalora_quantity_service.rb
|
148
149
|
- lib/item_builder/zilingo_quantity_service.rb
|