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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80abf4633b57aeb958ec7f79f516f860fb099c20e6962de6e4cd0d8d0e1f3f5c
|
4
|
+
data.tar.gz: df57c8f677d590947fc4fce038740adc6d2aba7618acf60eca3c4a9bcaa5700a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 817b6c0d76780bfab457aaf7a6b67693caf97d6d7c581361270adb1ff874cef268a63adf74b52846d7278c4ad02c9d095c230e7af7ffc77ac3572b73a121b505
|
7
|
+
data.tar.gz: a87ce903ed0c6c9c9e47fdb68acefcf1de788f8f6f754d02aa149793bed703846087a324b9c4004a99b5d3d9bf4de83de6dc223a5c59cf451093f4961dad5f22
|
data/lib/client/product.rb
CHANGED
@@ -26,8 +26,8 @@ module BigcommerceProductAgent
|
|
26
26
|
|
27
27
|
def upsert(payload, params={})
|
28
28
|
begin
|
29
|
-
if payload[
|
30
|
-
return update(payload[
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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:
|
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:
|
16
|
-
width:
|
17
|
-
depth:
|
18
|
-
height:
|
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
|
23
|
-
}
|
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
|
-
|
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
|
-
|
37
|
-
|
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[
|
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.
|
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-
|
11
|
+
date: 2020-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|