huginn_bigcommerce_product_agent 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mapper/product_mapper.rb +33 -19
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9e9dc2ed53e9e917bc0a35da06e11037cf4f0a4cec60c5713aae4414ce5ae23
4
- data.tar.gz: 7bdfa35384ac7ea108a0b20872ffa9d46b977d0d5b48952c5eb3c23fcc69efc8
3
+ metadata.gz: 6edc2db0f86f9193fa3463ca3a21db71bc52b06b007d1d00d81b934891eea499
4
+ data.tar.gz: f2635fda8a26cf5c0e7706c2be7794897769d0a99f3da2c243e61f96da069242
5
5
  SHA512:
6
- metadata.gz: 516223ed77ca56c44d0988ed8c58256978da78ca7cd8d9a7699d54e923e08885f903acbe3f8dabc09f874aeabd93267b387da380f1c35672c0917e3c200ab9a7
7
- data.tar.gz: d61416b643d805ba659783080091cfb95fadcd32c5d1fea40ea741dc286f6207c6fd50c1d940efbce06a3372ea3b26cd9b50f38174f4e27254503814650364b2
6
+ metadata.gz: e730a73a5be204f43e0c54866f37e9e0e16542ad5357806d6dc1e69c41c0a3a9cd0ef9fb1c90b39982b3471dac0c61c23b0551ef60184ef9b66bfa878e0fa5f2
7
+ data.tar.gz: 628d7bd1ddf7dcfa831a3f34d0522c155eefcb99a90b39528a736251ed03d17480c30f9fa2a93def20af9aed0e6a6d31cea82333733a9ab10c910465c3e3284d
@@ -3,33 +3,47 @@ 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)})",
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,
8
28
  sku: variant ? variant['sku'] : default_sku,
9
- is_default: variant && variant['isDefault'],
10
- type: (variant && variant['isDigital'] == true) || is_digital ? 'digital' : 'physical',
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']
27
-
28
- if upc
29
- product[:upc] = upc
30
- end
42
+ is_visible: variant ? false : true,
43
+ }
44
+ result[:upc] = product['gtin12'] if product['gtin12']
31
45
 
32
- return product
46
+ result.merge(additional_data)
33
47
  end
34
48
 
35
49
  def self.get_wrapper_sku(product)
metadata CHANGED
@@ -1,7 +1,7 @@
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.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Spizziri