huginn_bigcommerce_product_agent 1.8.0 → 1.11.1

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: 401d12c4fd8a1bd918e0e0b4d6a20eca3467e7ce288130025c500e7f3a7e7d9c
4
- data.tar.gz: 501ebd2b48cc23f68671c407ddefdf69d12b666eb608f37d4f149e81eeaecf6d
3
+ metadata.gz: 0ddeb18b4e875ae897160512f80f8af033dbb4cc2e34295f46eb0114e0628298
4
+ data.tar.gz: 37b77bfe861b477d65c0c42c359538a4fa9853b5a0840dfd9deb132946ccde49
5
5
  SHA512:
6
- metadata.gz: fb699b59217b6c4ee28b5691ffa1f08bd8298e7aa96bdaed61060097e506bb170d189a386b61871bfb761c5eb6c103e9451aa13ced6330843808774e9fd00997
7
- data.tar.gz: a368c30a438e9c20659a7b819e4cdf691f2f790436ecd588bb6742b65fefa6453ee42a3f8eb4aab0aaf924d6bfd7f002053b60cd946f27b7da13fc11f1470748
6
+ metadata.gz: 89d31246d6961bdac0a37f698afb238b6d6820df667a36cbcfde9452733acc07eb0906a38dae6f04fc7be065733cfdcab0434b4b77d5fab9a7dc5a21025365b2
7
+ data.tar.gz: 52b2ab013d9e885a14f684aa233b05c69fe1d73aaebf881d2f30da52ee4322fa6727054769dabaafe9e06ee69fde2a69432718f8022dd5051c203eb35dcd9b79
@@ -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
@@ -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])
@@ -152,6 +152,7 @@ module Agents
152
152
  # Ignatius Press -- some products have the same name and must be disambiguated.
153
153
  # ...by adding a list of the product types (hardback, paperback, etc.) to their names
154
154
  if boolify(options['should_disambiguate'])
155
+ product['page_title'] = product['name']
155
156
  product['name'] += " |~ " + product['model'].map { |m|
156
157
  m['additionalProperty'].find { |p|
157
158
  p['propertyID'] == 'option'
@@ -426,7 +427,9 @@ module Agents
426
427
  end
427
428
 
428
429
  delete_fields.each do |field|
429
- @meta_field.delete(field[:resource_id], field[:id])
430
+ if field[:resource_id] && field[:id]
431
+ @meta_field.delete(field[:resource_id], field[:id])
432
+ end
430
433
  end
431
434
 
432
435
  meta_fields
@@ -46,6 +46,7 @@ module BigcommerceProductAgent
46
46
  preorder_release_date: product['releaseDate'] && product['releaseDate'].to_datetime ? product['releaseDate'].to_datetime.strftime("%FT%T%:z") : nil,
47
47
  preorder_message: self.get_availability(product) == 'preorder' ? product['availability'] : '',
48
48
  is_preorder_only: self.get_availability(product) == 'preorder' ? true : false,
49
+ page_title: product['page_title'] || '',
49
50
  }
50
51
  result[:upc] = product['gtin12'] if product['gtin12']
51
52
 
@@ -108,6 +109,7 @@ module BigcommerceProductAgent
108
109
  clone = Marshal.load(Marshal.dump(product))
109
110
  clone['model'] = digitals
110
111
  clone['sku'] = clone['model'].select {|m| m['isDefault'] = true}.first['sku']
112
+ clone['categories'] = self.get_categories_after_split(clone, clone['categories'])
111
113
  self.merge_additional_properties(clone, field_map)
112
114
  result[:digital] = clone
113
115
  end
@@ -118,6 +120,7 @@ module BigcommerceProductAgent
118
120
  clone = Marshal.load(Marshal.dump(product))
119
121
  clone['model'] = physicals
120
122
  clone['sku'] = clone['model'].select {|m| m['isDefault'] = true}.first['sku']
123
+ clone['categories'] = self.get_categories_after_split(clone, clone['categories'])
121
124
  self.merge_additional_properties(clone, field_map)
122
125
  result[:physical] = clone
123
126
  end
@@ -139,6 +142,20 @@ module BigcommerceProductAgent
139
142
  return categories
140
143
  end
141
144
 
145
+ def self.get_categories_after_split(product, categories)
146
+ # categories equal shared categories between digital and physical products
147
+
148
+ if product['model'].select { |c| c['categories']}
149
+ product['model'].each do |variant|
150
+ variant['categories'].map do |category|
151
+ categories.push(category)
152
+ end
153
+ end
154
+ end
155
+
156
+ return categories
157
+ end
158
+
142
159
  def self.get_option(variant)
143
160
  if variant['encodingFormat']
144
161
  return variant['encodingFormat']
@@ -9,7 +9,7 @@ module BigcommerceProductAgent
9
9
  price: variant['offers'] && variant['offers'][0] ? variant['offers'][0]['price'] : '0',
10
10
  cost_price: nil,
11
11
  sale_price: nil,
12
- retail_price: nil,
12
+ retail_price: variant['offers'] && variant['offers'][0] ? variant['offers'][0]['price'] : nil,
13
13
  weight: variant['weight'] ? variant['weight']['value'] : '0',
14
14
  width: variant['width'] ? variant['width']['value'] : '0',
15
15
  depth: variant['depth'] ? variant['depth']['value'] : '0',
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.8.0
4
+ version: 1.11.1
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-07-14 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler