huginn_bigcommerce_product_agent 1.3.4 → 1.4.3

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: c9e9dc2ed53e9e917bc0a35da06e11037cf4f0a4cec60c5713aae4414ce5ae23
4
- data.tar.gz: 7bdfa35384ac7ea108a0b20872ffa9d46b977d0d5b48952c5eb3c23fcc69efc8
3
+ metadata.gz: 4d9046f3fa0d6c9e3f0c58720148502c622ec9662cecc03488d381f5c7730440
4
+ data.tar.gz: 15652aee1e058bffc5a15920574bd93c7eb89ba0391c267cb6912c270a1f0810
5
5
  SHA512:
6
- metadata.gz: 516223ed77ca56c44d0988ed8c58256978da78ca7cd8d9a7699d54e923e08885f903acbe3f8dabc09f874aeabd93267b387da380f1c35672c0917e3c200ab9a7
7
- data.tar.gz: d61416b643d805ba659783080091cfb95fadcd32c5d1fea40ea741dc286f6207c6fd50c1d940efbce06a3372ea3b26cd9b50f38174f4e27254503814650364b2
6
+ metadata.gz: b75f6cc9fbfabb4c0143b33146d1c736fd4680657642c29e755621e12a5d1d5efb6aa1aadc4d3ee6494dea17d1f6dab20d34a15aacf8ec992be8c79430d89fc3
7
+ data.tar.gz: 3fe2de4e3330ae759ef8e43b402a6a5ca7ac9e1ce21dac24c8ff2bbdb0e8680ca2fcde53f129d6ae5358a07d3f9e237eae08ae8b1c0fc1f378b3c880082d5239
@@ -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
+ if 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'],
@@ -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.4
4
+ version: 1.4.3
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