huginn_bigcommerce_product_agent 2.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d61b54d98e2797d36d581599d2501e70f96a8adb325a6539a14770f16683b3
|
4
|
+
data.tar.gz: f43185ad5ca114d12255997f727fe5a952fd62cbcd3ea412244daa83ddcbc129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e90eb544f99296af2f228db2c8653c64ce6eb196e7c51f523cd426df02315e446df70caf8c28abd5e6f23326069a1fe79debcf2b59d6fed1dbff737ce17e45d
|
7
|
+
data.tar.gz: 0f8ab865f88e45f01eff587b5d92ecaece1dfa8c210d6692e73b47eed5633c717e9c6388c1eeebeb24b5f81450e042eaed90dfe518ecc6c11d17c40ffc573074
|
data/lib/client/product.rb
CHANGED
@@ -37,10 +37,10 @@ module BigcommerceProductAgent
|
|
37
37
|
e.response[:status],
|
38
38
|
'update product',
|
39
39
|
'Failed to update product batch',
|
40
|
+
payload.map { |p|
|
41
|
+
{ id: p["id"], sku: p[:sku] }
|
42
|
+
},
|
40
43
|
{
|
41
|
-
product_identifiers: payload.map { |p|
|
42
|
-
{ id: p[:id], sku: p[:sku] }
|
43
|
-
},
|
44
44
|
errors: JSON.parse(e.response[:body])['errors'],
|
45
45
|
},
|
46
46
|
e
|
@@ -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])
|
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
|
@@ -115,7 +115,8 @@ module BigcommerceProductAgent
|
|
115
115
|
{
|
116
116
|
related_skus: skus,
|
117
117
|
errors: JSON.parse(e.response[:body])['errors'],
|
118
|
-
}
|
118
|
+
},
|
119
|
+
e
|
119
120
|
)
|
120
121
|
end
|
121
122
|
end
|
@@ -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
|
|
@@ -330,7 +329,7 @@ module Agents
|
|
330
329
|
'upsert_products',
|
331
330
|
e.message,
|
332
331
|
nil,
|
333
|
-
{ sku: product_data.map { |p| p[
|
332
|
+
{ sku: product_data.map { |p| p[:sku] } },
|
334
333
|
e
|
335
334
|
))
|
336
335
|
end
|
@@ -342,11 +341,20 @@ module Agents
|
|
342
341
|
bc_payload = nil
|
343
342
|
|
344
343
|
begin
|
344
|
+
# if track inventory on the agent is true set track inventory to product level track inventory
|
345
345
|
track_inventory = boolify(options['track_inventory']).nil? ? true : boolify(options['track_inventory'])
|
346
|
-
|
346
|
+
if (track_inventory)
|
347
|
+
track_inventory = boolify(raw_product['trackInventory'])
|
348
|
+
end
|
349
|
+
bc_payload = get_mapper(:ProductMapper).map_payload(raw_product, bc_product, additional_data, track_inventory)
|
347
350
|
bc_payload['id'] = bc_product['id'] unless bc_product.nil? || bc_product['id'].nil?
|
348
351
|
# NOTE: bc_product will be nil when this is called with `to_create` products
|
349
352
|
|
353
|
+
if bc_payload[:categories].empty?
|
354
|
+
# If categories is empty keep existing categories because categories should never be empty
|
355
|
+
bc_payload[:categories] = bc_product['categories'] unless bc_product.nil? || bc_product['categories'].nil?
|
356
|
+
end
|
357
|
+
|
350
358
|
if bc_payload[:type] == 'digital'
|
351
359
|
bc_payload[:name].concat(' (Digital)')
|
352
360
|
end
|
@@ -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:
|
19
|
-
is_visible:
|
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.
|
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:
|
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
|