huginn_bigcommerce_product_agent 1.5.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 728526f71b899d714ffeaf9cca25b150326ba889dc17c732ace2c41b7b92782e
4
- data.tar.gz: d237a9f1a6eb179f76679a7a870b56a7844239ee45f4fd32f56ba8a296201ca9
3
+ metadata.gz: e4b3e2536acd4ff18f83977f51c923c42e1a3eb53c3795d4f97ac08794c25682
4
+ data.tar.gz: a58f917ba53ae85c77b9b27f3e7874d5f0aec59239c16e2d6ccdc37b1d30b7b0
5
5
  SHA512:
6
- metadata.gz: 54e4aa00c7216da7c8d66ba4ea45cbcd1ec51339982686719505f2806761a91e601d807165c194975777e9b7ae0ee8327cde0d9ee966ccee264659d70b083ee1
7
- data.tar.gz: 9e9ff91a64dbab6ac8e0a1b599a5415ce2744d39cf00e3ca12d697fddde434dcf9aa174ecd89b0e67333838bd03cfe8585797c6d9e50c73cd57b936eb3ed8b9a
6
+ metadata.gz: 3cb5d5996d73be6a66c06ade306ee2a6e79a0f95169aeca83df39df6db17c855cce8c6620541999d256a6d164c239d83b72515921ca3897534849c2ed39d2e74
7
+ data.tar.gz: 4f9576be2448f833da6c077865538769e8a2553d3abcfa1fd0c6d9bdb2f887b7ae464c0577d0d0f2c6a852ad880284bc3431b5ab89c2839db9a091a88ab20693
@@ -42,7 +42,11 @@ module BigcommerceProductAgent
42
42
  end
43
43
 
44
44
  def delete(product_id, meta_field_id)
45
- client.delete(uri(product_id: product_id, meta_field_id: meta_field_id))
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
@@ -4,8 +4,12 @@ module BigcommerceProductAgent
4
4
  @uri_base = 'catalog/products/:product_id'
5
5
 
6
6
  def update(id, payload, params={})
7
- response = client.put(uri(product_id: id), payload.to_json) do |request|
8
- request.params.update(params) if params
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
- response = client.post(uri, payload.to_json) do |request|
21
- request.params.update(params) if params
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
- begin
29
- if payload[:id]
30
- return update(payload[:id], payload, params)
31
- else
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
- response = client.post(uri(product_id: product_id), option.to_json)
37
- return response.body['data']
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
@@ -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
- rescue Faraday::Error::ClientError => e
19
- puts e.inspect
20
- raise e
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
- available: 'available',
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.5.0
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-06-12 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler