huginn_bigcommerce_product_agent 1.5.0 → 1.10.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4b3e2536acd4ff18f83977f51c923c42e1a3eb53c3795d4f97ac08794c25682
|
4
|
+
data.tar.gz: a58f917ba53ae85c77b9b27f3e7874d5f0aec59239c16e2d6ccdc37b1d30b7b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cb5d5996d73be6a66c06ade306ee2a6e79a0f95169aeca83df39df6db17c855cce8c6620541999d256a6d164c239d83b72515921ca3897534849c2ed39d2e74
|
7
|
+
data.tar.gz: 4f9576be2448f833da6c077865538769e8a2553d3abcfa1fd0c6d9bdb2f887b7ae464c0577d0d0f2c6a852ad880284bc3431b5ab89c2839db9a091a88ab20693
|
data/lib/client/meta_field.rb
CHANGED
@@ -42,7 +42,11 @@ module BigcommerceProductAgent
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def delete(product_id, meta_field_id)
|
45
|
-
|
45
|
+
begin
|
46
|
+
client.delete(uri(product_id: product_id, meta_field_id: meta_field_id))
|
47
|
+
rescue Faraday::Error::ClientError => e
|
48
|
+
raise e, "\n#{e.message}\nFailed to delete meta_field with id = #{meta_field_id}\nfor product with id = #{product_id}\n", e.backtrace
|
49
|
+
end
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
data/lib/client/product.rb
CHANGED
@@ -4,8 +4,12 @@ module BigcommerceProductAgent
|
|
4
4
|
@uri_base = 'catalog/products/:product_id'
|
5
5
|
|
6
6
|
def update(id, payload, params={})
|
7
|
-
|
8
|
-
|
7
|
+
begin
|
8
|
+
response = client.put(uri(product_id: id), payload.to_json) do |request|
|
9
|
+
request.params.update(params) if params
|
10
|
+
end
|
11
|
+
rescue Faraday::Error::ClientError => e
|
12
|
+
raise e, "\n#{e.message}\nFailed to update product with payload = #{payload.to_json}\n", e.backtrace
|
9
13
|
end
|
10
14
|
|
11
15
|
return response.body['data']
|
@@ -17,23 +21,22 @@ module BigcommerceProductAgent
|
|
17
21
|
end
|
18
22
|
|
19
23
|
def create(payload, params={})
|
20
|
-
|
21
|
-
|
24
|
+
begin
|
25
|
+
response = client.post(uri, payload.to_json) do |request|
|
26
|
+
request.params.update(params) if params
|
27
|
+
end
|
28
|
+
rescue Faraday::Error::ClientError => e
|
29
|
+
raise e, "\n#{e.message}\nFailed to create product with payload = #{payload.to_json}\n", e.backtrace
|
22
30
|
end
|
23
31
|
|
24
32
|
return response.body['data']
|
25
33
|
end
|
26
34
|
|
27
35
|
def upsert(payload, params={})
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
return create(payload, params)
|
33
|
-
end
|
34
|
-
rescue Faraday::Error::ClientError => e
|
35
|
-
puts e.inspect
|
36
|
-
raise e
|
36
|
+
if payload[:id]
|
37
|
+
return update(payload[:id], payload, params)
|
38
|
+
else
|
39
|
+
return create(payload, params)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
@@ -33,8 +33,12 @@ module BigcommerceProductAgent
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def create(product_id, option)
|
36
|
-
|
37
|
-
|
36
|
+
begin
|
37
|
+
response = client.post(uri(product_id: product_id), option.to_json)
|
38
|
+
return response.body['data']
|
39
|
+
rescue Faraday::Error::ClientError => e
|
40
|
+
raise e, "\n#{e.message}\nFailed to upsert product_option = #{option.to_json}\nfor product with id = #{product_id}\n", e.backtrace
|
41
|
+
end
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
data/lib/client/variant.rb
CHANGED
@@ -15,10 +15,9 @@ module BigcommerceProductAgent
|
|
15
15
|
begin
|
16
16
|
response = client.put(uri, payload.to_json)
|
17
17
|
return response.body['data']
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
rescue Faraday::Error::ClientError => e
|
19
|
+
raise e, "\n#{e.message}\nFailed to upsert variant with payload = #{payload.to_json}\n", e.backtrace
|
20
|
+
end
|
22
21
|
end
|
23
22
|
|
24
23
|
def get_by_skus(skus, include = %w[custom_fields modifiers])
|
@@ -29,7 +29,8 @@ module Agents
|
|
29
29
|
'meta_fields_map' => {},
|
30
30
|
'meta_fields_namespace' => '',
|
31
31
|
'mode' => modes[0],
|
32
|
-
'not_purchasable_format_list' => []
|
32
|
+
'not_purchasable_format_list' => [],
|
33
|
+
'should_disambiguate' => false
|
33
34
|
}
|
34
35
|
end
|
35
36
|
|
@@ -67,6 +68,11 @@ module Agents
|
|
67
68
|
if options['not_purchasable_format_list'].present? && !options['not_purchasable_format_list'].is_a?(Array)
|
68
69
|
errors.add(:base, 'not_purchasable_format_list must be an Array')
|
69
70
|
end
|
71
|
+
|
72
|
+
if options.has_key?('should_disambiguate') && boolify(options['should_disambiguate']).nil?
|
73
|
+
errors.add(:base, 'when provided, `should_disambiguate` must be either true or false')
|
74
|
+
end
|
75
|
+
|
70
76
|
end
|
71
77
|
|
72
78
|
def working?
|
@@ -143,6 +149,17 @@ module Agents
|
|
143
149
|
product['name'] = "#{product['name']} (Digital)"
|
144
150
|
end
|
145
151
|
|
152
|
+
# Ignatius Press -- some products have the same name and must be disambiguated.
|
153
|
+
# ...by adding a list of the product types (hardback, paperback, etc.) to their names
|
154
|
+
if boolify(options['should_disambiguate'])
|
155
|
+
product['page_title'] = product['name']
|
156
|
+
product['name'] += " |~ " + product['model'].map { |m|
|
157
|
+
m['additionalProperty'].find { |p|
|
158
|
+
p['propertyID'] == 'option'
|
159
|
+
}['value']
|
160
|
+
}.join(", ")
|
161
|
+
end
|
162
|
+
|
146
163
|
wrapper_sku = wrapper_skus[type]
|
147
164
|
bc_product = bc_products[wrapper_sku]
|
148
165
|
variant_option_name = get_mapper(:OptionMapper).variant_option_name
|
@@ -19,6 +19,9 @@ module BigcommerceProductAgent
|
|
19
19
|
"width" => default_variant['width'],
|
20
20
|
"depth" => default_variant['depth'],
|
21
21
|
"height" => default_variant['height'],
|
22
|
+
"releaseDate" => default_variant['releaseDate'],
|
23
|
+
"datePublished" => default_variant['datePublished'],
|
24
|
+
"availability" => self.get_availability_offer(product, default_variant),
|
22
25
|
}.merge(product)
|
23
26
|
end
|
24
27
|
end
|
@@ -31,7 +34,7 @@ module BigcommerceProductAgent
|
|
31
34
|
description: product['description'] || '',
|
32
35
|
price: product['offers'] && product['offers'][0] ? product['offers'][0]['price'] : '0',
|
33
36
|
categories: self.get_categories(product),
|
34
|
-
|
37
|
+
availability: self.get_availability(product),
|
35
38
|
weight: product['weight'] ? product['weight']['value'] : '0',
|
36
39
|
width: product['width'] ? product['width']['value'] : '0',
|
37
40
|
depth: product['depth'] ? product['depth']['value'] : '0',
|
@@ -40,6 +43,10 @@ module BigcommerceProductAgent
|
|
40
43
|
meta_description: self.meta_description(product) || '',
|
41
44
|
search_keywords: self.get_search_keywords(additional_data.delete(:additional_search_terms), product),
|
42
45
|
is_visible: variant ? false : true,
|
46
|
+
preorder_release_date: product['releaseDate'] && product['releaseDate'].to_datetime ? product['releaseDate'].to_datetime.strftime("%FT%T%:z") : nil,
|
47
|
+
preorder_message: self.get_availability(product) == 'preorder' ? product['availability'] : '',
|
48
|
+
is_preorder_only: self.get_availability(product) == 'preorder' ? true : false,
|
49
|
+
page_title: product['page_title'] || '',
|
43
50
|
}
|
44
51
|
result[:upc] = product['gtin12'] if product['gtin12']
|
45
52
|
|
@@ -187,6 +194,33 @@ module BigcommerceProductAgent
|
|
187
194
|
def self.get_search_keywords(additional_search_terms, product)
|
188
195
|
return (self.meta_keywords(product) + additional_search_terms.split(",")).join(",")
|
189
196
|
end
|
197
|
+
|
198
|
+
def self.get_availability(product)
|
199
|
+
if product['datePublished'] && product['datePublished'].to_datetime && product['datePublished'].to_datetime < DateTime.now
|
200
|
+
return 'available'
|
201
|
+
else
|
202
|
+
if product['releaseDate'] && product['releaseDate'].to_datetime
|
203
|
+
if product['releaseDate'].to_datetime > DateTime.now
|
204
|
+
return 'preorder'
|
205
|
+
else
|
206
|
+
return 'available'
|
207
|
+
end
|
208
|
+
else
|
209
|
+
return 'disabled'
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def self.get_availability_offer(product, variant)
|
215
|
+
if product['offers'] && product['offers'][0]
|
216
|
+
return product['offers'][0]['availability']
|
217
|
+
else
|
218
|
+
if variant['offers'] && variant['offers'][0]
|
219
|
+
return variant['offers'][0]['availability']
|
220
|
+
end
|
221
|
+
end
|
222
|
+
return ''
|
223
|
+
end
|
190
224
|
end
|
191
225
|
end
|
192
226
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huginn_bigcommerce_product_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Spizziri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|