huginn_bigcommerce_product_agent 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89cfc257bee7acf8c2a48655ce32e2e4bd9aa91f09a0e17fb19a54224fc764f4
4
- data.tar.gz: ea56efe75b854b60a42bcb6f26b7a105f0910ec7e629dc08e7d2c927d7a91900
3
+ metadata.gz: e7d61b54d98e2797d36d581599d2501e70f96a8adb325a6539a14770f16683b3
4
+ data.tar.gz: f43185ad5ca114d12255997f727fe5a952fd62cbcd3ea412244daa83ddcbc129
5
5
  SHA512:
6
- metadata.gz: 266955d42682aaf2e8f92f5685ac915767a75070b7cdb6957d7e6b0a23e11ed7854070b04a7218bea809b7269702a2f51fb33d4813e355debcc435684adcb5b6
7
- data.tar.gz: 19fef7e12d26c6ac94945204e375d3c86bc016eae304f435851e222ef026e4eb1066159b4601b9d92ee546cb9f21803ee41cb809c0d958207408e5fbe5af7e8e
6
+ metadata.gz: 1e90eb544f99296af2f228db2c8653c64ce6eb196e7c51f523cd426df02315e446df70caf8c28abd5e6f23326069a1fe79debcf2b59d6fed1dbff737ce17e45d
7
+ data.tar.gz: 0f8ab865f88e45f01eff587b5d92ecaece1dfa8c210d6692e73b47eed5633c717e9c6388c1eeebeb24b5f81450e042eaed90dfe518ecc6c11d17c40ffc573074
@@ -94,7 +94,7 @@ module BigcommerceProductAgent
94
94
  end
95
95
 
96
96
  # When using sku:in you must specify the fields you want returned.
97
- def get_by_skus(skus, include = %w[custom_fields modifiers], include_fields = %w[sku categories])
97
+ def get_by_skus(skus, include = %w[custom_fields modifiers], include_fields = %w[sku categories inventory_tracking])
98
98
  products = []
99
99
  skus.each do |sku|
100
100
  begin
@@ -25,7 +25,6 @@ module Agents
25
25
  'meta_fields_namespace' => '',
26
26
  'not_purchasable_format_list' => [],
27
27
  'should_disambiguate' => false,
28
-
29
28
  }
30
29
  end
31
30
 
@@ -347,7 +346,7 @@ module Agents
347
346
  if (track_inventory)
348
347
  track_inventory = boolify(raw_product['trackInventory'])
349
348
  end
350
- bc_payload = get_mapper(:ProductMapper).map_payload(raw_product, additional_data, track_inventory)
349
+ bc_payload = get_mapper(:ProductMapper).map_payload(raw_product, bc_product, additional_data, track_inventory)
351
350
  bc_payload['id'] = bc_product['id'] unless bc_product.nil? || bc_product['id'].nil?
352
351
  # NOTE: bc_product will be nil when this is called with `to_create` products
353
352
 
@@ -2,12 +2,19 @@ module BigcommerceProductAgent
2
2
  module Mapper
3
3
  class ProductMapper
4
4
 
5
- def self.map_payload(product, additional_data = {}, track_inventory = true, default_sku = '')
5
+ def self.map_payload(product, bc_product, additional_data = {}, track_inventory = true, default_sku = '')
6
6
  name = product['name']
7
7
  isDigital = product['isDigital'].to_s == 'true'
8
8
 
9
9
  track_inventory = self.get_availability(product) == 'preorder' ? false : track_inventory
10
10
 
11
+ # respect the visibility setting of existing products, otherwise
12
+ # default visibility to true.
13
+ is_visible = true
14
+ if !bc_product.nil? && !bc_product['is_visible'].nil?
15
+ is_visible = bc_product['is_visible']
16
+ end
17
+
11
18
  result = {
12
19
  availability: self.get_availability(product),
13
20
  categories: self.get_categories(product),
@@ -15,8 +22,8 @@ module BigcommerceProductAgent
15
22
  description: product['description'] || '',
16
23
  height: product['height'] ? product['height']['value'] : '0',
17
24
  is_default: product['isDefault'],
18
- is_preorder_only: self.get_availability(product) == 'preorder' ? true : false,
19
- is_visible: true,
25
+ is_preorder_only: false,
26
+ is_visible: is_visible,
20
27
  meta_description: self.meta_description(product) || '',
21
28
  meta_keywords: self.meta_keywords(product),
22
29
  name: name,
@@ -30,8 +37,37 @@ module BigcommerceProductAgent
30
37
  type: isDigital ? 'digital' : 'physical',
31
38
  weight: product['weight'] ? product['weight']['value'] : '0',
32
39
  width: product['width'] ? product['width']['value'] : '0',
33
- inventory_tracking: isDigital || !track_inventory ? 'none' : 'product',
34
40
  }
41
+
42
+ # BEGIN: The following block is a workaround for a BigCommerce bug.
43
+ #
44
+ # It seems that when the `inventory_tracking` attribute is included in the payload,
45
+ # BigCommerce is now triggering a low stock warning for products with inventory
46
+ # tracking disabled.
47
+ #
48
+ # We are currently seeing notifications for _every digital product_ each time
49
+ # the sync process runs.
50
+ #
51
+ # Pending a fix from BigCommerce the following logic is designed to mitigate
52
+ # the false alarms. Essentially, we will only be including the `inventory_tracking`
53
+ # attribute if the value is _changing_ from whatever is currently set.
54
+ # While this may not stop _all_ of the false alarms, it should reduce them
55
+ # significantly.
56
+ current_tracking_value = bc_product['inventory_tracking'] unless bc_product.nil?
57
+ new_tracking_value = isDigital || !track_inventory ? 'none' : 'product'
58
+
59
+ if (current_tracking_value != new_tracking_value)
60
+ result[:inventory_tracking] = new_tracking_value
61
+ end
62
+ # END: Stock warning workaround
63
+
64
+
65
+ stock = get_additional_property_value(product, 'product_inventory', 0)
66
+
67
+ if (stock)
68
+ result[:inventory_level] = stock
69
+ end
70
+
35
71
  result[:upc] = product['isbn'] ? product['isbn'] : product['gtin12']
36
72
  result[:gtin] = product['gtin12'] if product['gtin12']
37
73
 
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: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Spizziri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-17 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  requirements: []
95
- rubygems_version: 3.0.3
95
+ rubygems_version: 3.0.3.1
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Agent that takes a generic product interface and upserts that product in