huginn_bigcommerce_product_agent 1.3.1 → 1.4.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: 911e20cea1ee097a95874f55f2366599eaed196c55e8da885e4c4273fc99baa2
4
- data.tar.gz: f9d92d1e656157743a633d32eb6ae97ebc7dc942e2d1ade910613a6775df77b2
3
+ metadata.gz: 80abf4633b57aeb958ec7f79f516f860fb099c20e6962de6e4cd0d8d0e1f3f5c
4
+ data.tar.gz: df57c8f677d590947fc4fce038740adc6d2aba7618acf60eca3c4a9bcaa5700a
5
5
  SHA512:
6
- metadata.gz: 9b04f1cdb14008d9ab24cf33aef05f330804cb3d8f95ae4726e228f3ced6882759b987321c6cea4c24f4802592aeec284c8cb7439e3352b7469d8496fdfe0942
7
- data.tar.gz: dc30b25ad1a9c020a47f8057362941da29b51f29bc0df6cc3e9c10ca456b92242ae5a2436b1554e2f1fc36a7941b0ddfa6852b0c5fc9a14ad0f4bff6ae42f4b1
6
+ metadata.gz: 817b6c0d76780bfab457aaf7a6b67693caf97d6d7c581361270adb1ff874cef268a63adf74b52846d7278c4ad02c9d095c230e7af7ffc77ac3572b73a121b505
7
+ data.tar.gz: a87ce903ed0c6c9c9e47fdb68acefcf1de788f8f6f754d02aa149793bed703846087a324b9c4004a99b5d3d9bf4de83de6dc223a5c59cf451093f4961dad5f22
@@ -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
@@ -103,15 +103,6 @@ module Agents
103
103
  def handle_variants(event)
104
104
  product = event.payload
105
105
 
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
106
  split = get_mapper(:ProductMapper).split_digital_and_physical(
116
107
  product,
117
108
  interpolated['custom_fields_map']
@@ -119,6 +110,15 @@ module Agents
119
110
  physical = split[:physical]
120
111
  digital = split[:digital]
121
112
 
113
+ wrapper_skus = {
114
+ physical: get_mapper(:ProductMapper).get_wrapper_sku(physical),
115
+ digital: get_mapper(:ProductMapper).get_wrapper_sku(digital),
116
+ }
117
+
118
+ bc_products = @product.get_by_skus(
119
+ wrapper_skus.map {|k,v| v},
120
+ %w[custom_fields options]
121
+ )
122
122
  # upsert wrapper products
123
123
  split.each do |type, product|
124
124
  is_digital = type == :digital ? true : false
@@ -138,17 +138,20 @@ module Agents
138
138
  # ##############################
139
139
  upsert_result = upsert_product(wrapper_sku, product, bc_product, is_digital)
140
140
  bc_product = upsert_result[:product]
141
- bc_products[wrapper_sku] = bc_product
142
- product_id = bc_products[wrapper_sku]['id']
143
141
 
144
142
  # clean up custom/meta fields. there are not batch operations so we might as well do them here.
145
143
  custom_fields_delete = upsert_result[:custom_fields_delete].select {|field| field['name'] != 'related_product_id'}
146
144
  clean_up_custom_fields(custom_fields_delete)
147
- update_meta_fields(
145
+ meta_fields = update_meta_fields(
148
146
  upsert_result[:meta_fields_upsert],
149
147
  upsert_result[:meta_fields_delete],
150
148
  )
151
149
 
150
+ bc_product['meta_fields'] = meta_fields
151
+
152
+ bc_products[wrapper_sku] = bc_product
153
+ product_id = bc_products[wrapper_sku]['id']
154
+
152
155
  # ##############################
153
156
  # 2. upsert option & option_values
154
157
  # ##############################
@@ -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',
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',
11
31
  description: product['description'],
12
- price: variant && variant['offers'] && variant['offers'][0] ? variant['offers'][0]['price'] : '0',
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
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
@@ -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,
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.1
4
+ version: 1.4.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-04-24 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler