huginn_bigcommerce_product_agent 1.4.0 → 1.6.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: 35c321f72aa2a5961ef5b305d1222e910a8d4432f8b758051300169c01fd5882
|
4
|
+
data.tar.gz: 9653eab8c17015e8bf9c9d1604ac86416f9497fcbe9698de7d3dfce213dd58c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40ddd8f7fda0c0d1cb792d4ad4a8c30c957c0e5e3b74c05b72d152b9c3a346cc8f1ba90def9fa9e95ad8eb9ca52d33f47b0d9b562ccd0e78e4155a9a8bf28e67
|
7
|
+
data.tar.gz: 4fa44c38eec2c696bacd090d33fc761b689d9839cae34596b61cb5ec1242d2bdd65b3ab36f8a8e0b970ade13c3b3539894701440a861fc948e2f26f9ee807876
|
@@ -28,7 +28,8 @@ module Agents
|
|
28
28
|
'custom_fields_map' => {},
|
29
29
|
'meta_fields_map' => {},
|
30
30
|
'meta_fields_namespace' => '',
|
31
|
-
'mode' => modes[0]
|
31
|
+
'mode' => modes[0],
|
32
|
+
'not_purchasable_format_list' => []
|
32
33
|
}
|
33
34
|
end
|
34
35
|
|
@@ -62,6 +63,10 @@ module Agents
|
|
62
63
|
unless options['mode'].present? && modes.include?(options['mode'])
|
63
64
|
errors.add(:base, "mode is a required field and must be one of: #{modes.join(', ')}")
|
64
65
|
end
|
66
|
+
|
67
|
+
if options['not_purchasable_format_list'].present? && !options['not_purchasable_format_list'].is_a?(Array)
|
68
|
+
errors.add(:base, 'not_purchasable_format_list must be an Array')
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
def working?
|
@@ -119,6 +124,16 @@ module Agents
|
|
119
124
|
wrapper_skus.map {|k,v| v},
|
120
125
|
%w[custom_fields options]
|
121
126
|
)
|
127
|
+
#save skus
|
128
|
+
digital_skus = []
|
129
|
+
physical_skus = []
|
130
|
+
if split[:digital] and split[:physical]
|
131
|
+
digital_skus.concat([wrapper_skus[:digital]])
|
132
|
+
digital_skus.concat(get_mapper(:ProductMapper).get_product_skus(split[:digital])).join(",")
|
133
|
+
physical_skus.concat([wrapper_skus[:physical]])
|
134
|
+
physical_skus.concat(get_mapper(:ProductMapper).get_product_skus(split[:physical])).join(",")
|
135
|
+
end
|
136
|
+
|
122
137
|
# upsert wrapper products
|
123
138
|
split.each do |type, product|
|
124
139
|
is_digital = type == :digital ? true : false
|
@@ -133,22 +148,26 @@ module Agents
|
|
133
148
|
variant_option_name = get_mapper(:OptionMapper).variant_option_name
|
134
149
|
bc_option = !bc_product.nil? ? bc_product['options'].select {|opt| opt['display_name'] === variant_option_name}.first : nil
|
135
150
|
|
151
|
+
search_skus = is_digital ? physical_skus : digital_skus
|
136
152
|
# ##############################
|
137
153
|
# 1. update wrapper product
|
138
154
|
# ##############################
|
139
|
-
upsert_result = upsert_product(wrapper_sku, product, bc_product, is_digital)
|
155
|
+
upsert_result = upsert_product(wrapper_sku, product, bc_product, is_digital, search_skus)
|
140
156
|
bc_product = upsert_result[:product]
|
141
|
-
bc_products[wrapper_sku] = bc_product
|
142
|
-
product_id = bc_products[wrapper_sku]['id']
|
143
157
|
|
144
158
|
# clean up custom/meta fields. there are not batch operations so we might as well do them here.
|
145
159
|
custom_fields_delete = upsert_result[:custom_fields_delete].select {|field| field['name'] != 'related_product_id'}
|
146
160
|
clean_up_custom_fields(custom_fields_delete)
|
147
|
-
update_meta_fields(
|
161
|
+
meta_fields = update_meta_fields(
|
148
162
|
upsert_result[:meta_fields_upsert],
|
149
163
|
upsert_result[:meta_fields_delete],
|
150
164
|
)
|
151
165
|
|
166
|
+
bc_product['meta_fields'] = meta_fields
|
167
|
+
|
168
|
+
bc_products[wrapper_sku] = bc_product
|
169
|
+
product_id = bc_products[wrapper_sku]['id']
|
170
|
+
|
152
171
|
# ##############################
|
153
172
|
# 2. upsert option & option_values
|
154
173
|
# ##############################
|
@@ -180,6 +199,8 @@ module Agents
|
|
180
199
|
[option_value],
|
181
200
|
product_id,
|
182
201
|
bc_variant.nil? ? nil : bc_variant['id'],
|
202
|
+
interpolated['not_purchasable_format_list'],
|
203
|
+
bc_option_value
|
183
204
|
)
|
184
205
|
end
|
185
206
|
|
@@ -327,7 +348,7 @@ module Agents
|
|
327
348
|
return ::BigcommerceProductAgent::Mapper.const_get(class_name.to_sym)
|
328
349
|
end
|
329
350
|
|
330
|
-
def upsert_product(sku, product, bc_product = nil, is_digital=false)
|
351
|
+
def upsert_product(sku, product, bc_product = nil, is_digital=false, search_skus=[])
|
331
352
|
custom_fields_updates = get_mapper(:CustomFieldMapper).map(
|
332
353
|
interpolated['custom_fields_map'],
|
333
354
|
product,
|
@@ -340,7 +361,10 @@ module Agents
|
|
340
361
|
sku,
|
341
362
|
product,
|
342
363
|
product_id,
|
343
|
-
{
|
364
|
+
{
|
365
|
+
additional_search_terms: search_skus,
|
366
|
+
custom_fields: custom_fields_updates[:upsert]
|
367
|
+
},
|
344
368
|
is_digital,
|
345
369
|
)
|
346
370
|
|
@@ -19,6 +19,9 @@ module BigcommerceProductAgent
|
|
19
19
|
"width" => default_variant['width'],
|
20
20
|
"depth" => default_variant['depth'],
|
21
21
|
"height" => default_variant['height'],
|
22
|
+
"releaseDate" => default_variant['releaseDate'],
|
23
|
+
"datePublished" => default_variant['datePublished'],
|
24
|
+
"availability" => self.get_availability_offer(product, default_variant),
|
22
25
|
}.merge(product)
|
23
26
|
end
|
24
27
|
end
|
@@ -28,18 +31,21 @@ module BigcommerceProductAgent
|
|
28
31
|
sku: product ? product['sku'] : default_sku,
|
29
32
|
is_default: product['isDefault'],
|
30
33
|
type: product['isDigital'] == true || is_digital ? 'digital' : 'physical',
|
31
|
-
description: product['description'],
|
34
|
+
description: product['description'] || '',
|
32
35
|
price: product['offers'] && product['offers'][0] ? product['offers'][0]['price'] : '0',
|
33
36
|
categories: self.get_categories(product),
|
34
|
-
|
37
|
+
availability: self.get_availability(product),
|
35
38
|
weight: product['weight'] ? product['weight']['value'] : '0',
|
36
39
|
width: product['width'] ? product['width']['value'] : '0',
|
37
40
|
depth: product['depth'] ? product['depth']['value'] : '0',
|
38
41
|
height: product['height'] ? product['height']['value'] : '0',
|
39
42
|
meta_keywords: self.meta_keywords(product),
|
40
|
-
meta_description: self.meta_description(product),
|
41
|
-
search_keywords: self.
|
43
|
+
meta_description: self.meta_description(product) || '',
|
44
|
+
search_keywords: self.get_search_keywords(additional_data.delete(:additional_search_terms), product),
|
42
45
|
is_visible: variant ? false : true,
|
46
|
+
preorder_release_date: product['releaseDate'] && product['releaseDate'].to_datetime ? product['releaseDate'].to_datetime.strftime("%FT%T%:z") : nil,
|
47
|
+
preorder_message: self.get_availability(product) == 'preorder' ? product['availability'] : '',
|
48
|
+
is_preorder_only: self.get_availability(product) == 'preorder' ? true : false,
|
43
49
|
}
|
44
50
|
result[:upc] = product['gtin12'] if product['gtin12']
|
45
51
|
|
@@ -182,6 +188,38 @@ module BigcommerceProductAgent
|
|
182
188
|
end
|
183
189
|
end
|
184
190
|
end
|
191
|
+
|
192
|
+
# get a list of search keywords for the products
|
193
|
+
def self.get_search_keywords(additional_search_terms, product)
|
194
|
+
return (self.meta_keywords(product) + additional_search_terms.split(",")).join(",")
|
195
|
+
end
|
196
|
+
|
197
|
+
def self.get_availability(product)
|
198
|
+
if product['datePublished'] && product['datePublished'].to_datetime && product['datePublished'].to_datetime < DateTime.now
|
199
|
+
return 'available'
|
200
|
+
else
|
201
|
+
if product['releaseDate'] && product['releaseDate'].to_datetime
|
202
|
+
if product['releaseDate'].to_datetime > DateTime.now
|
203
|
+
return 'preorder'
|
204
|
+
else
|
205
|
+
return 'available'
|
206
|
+
end
|
207
|
+
else
|
208
|
+
return 'disabled'
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.get_availability_offer(product, variant)
|
214
|
+
if product['offers'] && product['offers'][0]
|
215
|
+
return product['offers'][0]['availability']
|
216
|
+
else
|
217
|
+
if variant['offers'] && variant['offers'][0]
|
218
|
+
return variant['offers'][0]['availability']
|
219
|
+
end
|
220
|
+
end
|
221
|
+
return ''
|
222
|
+
end
|
185
223
|
end
|
186
224
|
end
|
187
225
|
end
|
@@ -2,7 +2,7 @@ module BigcommerceProductAgent
|
|
2
2
|
module Mapper
|
3
3
|
class VariantMapper
|
4
4
|
|
5
|
-
def self.map(variant, option_values, product_id, variant_id=nil)
|
5
|
+
def self.map(variant, option_values, product_id, variant_id=nil, not_purchasable_format_list, bc_option_value)
|
6
6
|
mapped = {
|
7
7
|
product_id: product_id,
|
8
8
|
sku: variant['sku'],
|
@@ -29,6 +29,14 @@ module BigcommerceProductAgent
|
|
29
29
|
mapped[:id] = variant_id
|
30
30
|
end
|
31
31
|
|
32
|
+
unless not_purchasable_format_list.nil?
|
33
|
+
not_purchasable_format_list.each do |format|
|
34
|
+
if format == bc_option_value['label']
|
35
|
+
mapped[:purchasing_disabled] = true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
32
40
|
return mapped
|
33
41
|
end
|
34
42
|
|
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.6.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: 2020-
|
11
|
+
date: 2020-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|