huginn_bigcommerce_product_agent 1.3.2 → 1.4.2

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: '001803ced4355a9ab4473dafdd2aaae3adbf7ef8df1423a638f6f855be51bd65'
4
- data.tar.gz: 3655ffec4e587e324cc0e0736a8aef9f99b80649def79740db570bb1cfacc125
3
+ metadata.gz: 4212c209c32fafb12fc7746a038bcb4c20af8cde053cb2adc44cff87e8112433
4
+ data.tar.gz: 4dd2faafdf9ab8422eacd7c407ccf35549a69ace3df0a9a748c09bc91a038ffc
5
5
  SHA512:
6
- metadata.gz: 4075e23ac57f675e2bca6c59166da6ca0c596355fd474b3b834afa659dd1415e9dd83ea6a990c93c69055560c12c1a5104c3a588e13a8033c47551fa3e51a15a
7
- data.tar.gz: ce7be78f512019a8efbc8de98f28a383f484d7a8d1537862ebf63fd4a3007420f704a052eed3484afad11dadb562e1570b4d13b1e78075ae26806b9a2617680c
6
+ metadata.gz: c871f927452151ecd880b7b68731d8629100262911c9fc7d4566cf7f31a29c626bedba74f5dcb83dbd135413a95a781042d1e6408b060c00e0bf4106c408d2af
7
+ data.tar.gz: a275f1a162b1a7ed5633b5e0868766eb9e41b9b1ce0e8a024c5bc241183bf286ddc582f53df9b580e2ea3cb52b7ad6de51bdc1274b13857ecb153a206e924ce3
@@ -26,8 +26,8 @@ module BigcommerceProductAgent
26
26
 
27
27
  def upsert(payload, params={})
28
28
  begin
29
- if payload['id']
30
- return update(payload['id'], payload, params)
29
+ if payload[:id]
30
+ return update(payload[:id], payload, params)
31
31
  else
32
32
  return create(payload, params)
33
33
  end
@@ -28,7 +28,8 @@ module Agents
28
28
  'custom_fields_map' => {},
29
29
  'meta_fields_map' => {},
30
30
  'meta_fields_namespace' => '',
31
- 'mode' => modes[0]
31
+ 'mode' => modes[0],
32
+ 'not_purchasable_format_list' => []
32
33
  }
33
34
  end
34
35
 
@@ -62,6 +63,10 @@ module Agents
62
63
  unless options['mode'].present? && modes.include?(options['mode'])
63
64
  errors.add(:base, "mode is a required field and must be one of: #{modes.join(', ')}")
64
65
  end
66
+
67
+ unless options['not_purchasable_format_list'].present? && !options['not_purchasable_format_list'].is_a?(Array)
68
+ errors.add(:base, 'not_purchasable_format_list must be an Array')
69
+ end
65
70
  end
66
71
 
67
72
  def working?
@@ -103,15 +108,6 @@ module Agents
103
108
  def handle_variants(event)
104
109
  product = event.payload
105
110
 
106
- wrapper_skus = {
107
- physical: get_mapper(:ProductMapper).get_wrapper_sku_physical(product),
108
- digital: get_mapper(:ProductMapper).get_wrapper_sku_digital(product),
109
- }
110
- bc_products = @product.get_by_skus(
111
- wrapper_skus.map {|k,v| v},
112
- %w[custom_fields options]
113
- )
114
-
115
111
  split = get_mapper(:ProductMapper).split_digital_and_physical(
116
112
  product,
117
113
  interpolated['custom_fields_map']
@@ -119,6 +115,15 @@ module Agents
119
115
  physical = split[:physical]
120
116
  digital = split[:digital]
121
117
 
118
+ wrapper_skus = {
119
+ physical: get_mapper(:ProductMapper).get_wrapper_sku(physical),
120
+ digital: get_mapper(:ProductMapper).get_wrapper_sku(digital),
121
+ }
122
+
123
+ bc_products = @product.get_by_skus(
124
+ wrapper_skus.map {|k,v| v},
125
+ %w[custom_fields options]
126
+ )
122
127
  # upsert wrapper products
123
128
  split.each do |type, product|
124
129
  is_digital = type == :digital ? true : false
@@ -138,17 +143,20 @@ module Agents
138
143
  # ##############################
139
144
  upsert_result = upsert_product(wrapper_sku, product, bc_product, is_digital)
140
145
  bc_product = upsert_result[:product]
141
- bc_products[wrapper_sku] = bc_product
142
- product_id = bc_products[wrapper_sku]['id']
143
146
 
144
147
  # clean up custom/meta fields. there are not batch operations so we might as well do them here.
145
148
  custom_fields_delete = upsert_result[:custom_fields_delete].select {|field| field['name'] != 'related_product_id'}
146
149
  clean_up_custom_fields(custom_fields_delete)
147
- update_meta_fields(
150
+ meta_fields = update_meta_fields(
148
151
  upsert_result[:meta_fields_upsert],
149
152
  upsert_result[:meta_fields_delete],
150
153
  )
151
154
 
155
+ bc_product['meta_fields'] = meta_fields
156
+
157
+ bc_products[wrapper_sku] = bc_product
158
+ product_id = bc_products[wrapper_sku]['id']
159
+
152
160
  # ##############################
153
161
  # 2. upsert option & option_values
154
162
  # ##############################
@@ -180,6 +188,8 @@ module Agents
180
188
  [option_value],
181
189
  product_id,
182
190
  bc_variant.nil? ? nil : bc_variant['id'],
191
+ interpolated['not_purchasable_format_list'],
192
+ bc_option_value
183
193
  )
184
194
  end
185
195
 
@@ -3,51 +3,60 @@ module BigcommerceProductAgent
3
3
  class ProductMapper
4
4
 
5
5
  def self.map(product, variant, additional_data = {}, is_digital = false, default_sku='')
6
- product = {
7
- name: variant.nil? ? product['name'] : "#{product['name']} (#{self.get_option(variant)})",
8
- sku: variant ? variant['sku'] : default_sku,
9
- is_default: variant && variant['isDefault'],
10
- type: (variant && variant['isDigital'] == true) || is_digital ? 'digital' : 'physical',
11
- description: product['description'],
12
- price: variant && variant['offers'] && variant['offers'][0] ? variant['offers'][0]['price'] : '0',
6
+ name = product['name']
7
+
8
+ if variant
9
+ # variants inherit from and override parent product info
10
+ name = "#{name} (#{self.get_option(variant)})"
11
+ product = product.merge(variant)
12
+ else
13
+ # wrapper product
14
+ default_variant = self.get_variant_by_sku(product['sku'], product)
15
+ if default_variant
16
+ # pull up some properties from default variant (since bc doesn't display them otherwise)
17
+ product = {
18
+ "weight" => default_variant['weight'],
19
+ "width" => default_variant['width'],
20
+ "depth" => default_variant['depth'],
21
+ "height" => default_variant['height'],
22
+ }.merge(product)
23
+ end
24
+ end
25
+
26
+ result = {
27
+ name: name,
28
+ sku: product ? product['sku'] : default_sku,
29
+ is_default: product['isDefault'],
30
+ type: product['isDigital'] == true || is_digital ? 'digital' : 'physical',
31
+ description: product['description'] || '',
32
+ price: product['offers'] && product['offers'][0] ? product['offers'][0]['price'] : '0',
13
33
  categories: self.get_categories(product),
14
34
  available: 'available',
15
- weight: variant && variant['weight'] ? variant['weight']['value'] : '0',
16
- width: variant && variant['width'] ? variant['width']['value'] : '0',
17
- depth: variant && variant['depth'] ? variant['depth']['value'] : '0',
18
- height: variant && variant['height'] ? variant['height']['value'] : '0',
35
+ weight: product['weight'] ? product['weight']['value'] : '0',
36
+ width: product['width'] ? product['width']['value'] : '0',
37
+ depth: product['depth'] ? product['depth']['value'] : '0',
38
+ height: product['height'] ? product['height']['value'] : '0',
19
39
  meta_keywords: self.meta_keywords(product),
20
- meta_description: self.meta_description(product),
40
+ meta_description: self.meta_description(product) || '',
21
41
  search_keywords: self.meta_keywords(product).join(','),
22
- is_visible: variant.nil? ? true : false,
23
- }.merge(additional_data)
24
-
25
-
26
- upc = variant ? variant['gtin12'] : product['gtin12']
42
+ is_visible: variant ? false : true,
43
+ }
44
+ result[:upc] = product['gtin12'] if product['gtin12']
27
45
 
28
- if upc
29
- product[:upc] = upc
30
- end
31
-
32
- return product
46
+ result.merge(additional_data)
33
47
  end
34
48
 
35
49
  def self.get_wrapper_sku(product)
36
- "#{product['sku']}-W"
37
- end
38
-
39
- def self.get_wrapper_sku_physical(product)
40
- self.get_wrapper_sku(product)
41
- end
42
-
43
- def self.get_wrapper_sku_digital(product)
44
- "#{self.get_wrapper_sku_physical(product)}-DIGITAL"
50
+ if product
51
+ "#{product['sku']}-W"
52
+ end
45
53
  end
46
54
 
47
55
  def self.payload(sku, product, product_id = nil, additional_data = {}, is_digital = false)
48
56
  variant = self.get_variant_by_sku(sku, product)
49
57
  payload = self.map(product, variant, additional_data, is_digital, sku)
50
- payload['id'] = product_id unless product_id.nil?
58
+ payload[:id] = product_id unless product_id.nil?
59
+ payload[:sku] = self.get_wrapper_sku(product)
51
60
 
52
61
  return payload
53
62
  end
@@ -92,6 +101,7 @@ module BigcommerceProductAgent
92
101
  if digitals.length > 0
93
102
  clone = Marshal.load(Marshal.dump(product))
94
103
  clone['model'] = digitals
104
+ clone['sku'] = clone['model'].select {|m| m['isDefault'] = true}.first['sku']
95
105
  self.merge_additional_properties(clone, field_map)
96
106
  result[:digital] = clone
97
107
  end
@@ -101,6 +111,7 @@ module BigcommerceProductAgent
101
111
  if physicals.length > 0
102
112
  clone = Marshal.load(Marshal.dump(product))
103
113
  clone['model'] = physicals
114
+ clone['sku'] = clone['model'].select {|m| m['isDefault'] = true}.first['sku']
104
115
  self.merge_additional_properties(clone, field_map)
105
116
  result[:physical] = clone
106
117
  end
@@ -2,7 +2,7 @@ module BigcommerceProductAgent
2
2
  module Mapper
3
3
  class VariantMapper
4
4
 
5
- def self.map(variant, option_values, product_id, variant_id=nil)
5
+ def self.map(variant, option_values, product_id, variant_id=nil, not_purchasable_format_list, bc_option_value)
6
6
  mapped = {
7
7
  product_id: product_id,
8
8
  sku: variant['sku'],
@@ -18,7 +18,7 @@ module BigcommerceProductAgent
18
18
  fixed_cost_shipping_price: nil,
19
19
  purchasing_disabled: false,
20
20
  purchasing_disabled_message: '',
21
- upc: variant['gtin12'],
21
+ upc: variant['isbn'] ? variant['isbn'] : variant['gtin12'],
22
22
  inventory_level: nil,
23
23
  inventory_warning_level: nil,
24
24
  bin_picking_number: nil,
@@ -29,6 +29,14 @@ module BigcommerceProductAgent
29
29
  mapped[:id] = variant_id
30
30
  end
31
31
 
32
+ unless not_purchasable_format_list.nil?
33
+ not_purchasable_format_list.each do |format|
34
+ if format == bc_option_value['label']
35
+ mapped[:purchasing_disabled] = true
36
+ end
37
+ end
38
+ end
39
+
32
40
  return mapped
33
41
  end
34
42
 
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.3.2
4
+ version: 1.4.2
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-04-30 00:00:00.000000000 Z
11
+ date: 2020-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler