huginn_bigcommerce_product_agent 1.4.1 → 1.7.0
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: ce068992ff7f5e99b7f7656d246d104b60bc1a12c836c84d3c0156e0fadc9c67
|
4
|
+
data.tar.gz: eadfb8e593e0e44a806f6cbcffbbe8f0b6d364f73215ffd2565c91be80c6b885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b8cbc08bc80f5cf0e811fa61874545ce54cb2ee4af113cc3f43fc102959690b32d8e7ce8ec027e29d836c60db78d4d7c50aca414ca24149f66dae1756879032
|
7
|
+
data.tar.gz: a1ee6941129e2df489daa52077f5bd9daa57943ebc6328880a8cbf7b8747a3c59ebdd16634f9ed8398f48e2490ffee278c0360d472b8989c45c6fa629d27da52
|
@@ -28,7 +28,9 @@ 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' => [],
|
33
|
+
'should_disambiguate' => false
|
32
34
|
}
|
33
35
|
end
|
34
36
|
|
@@ -62,6 +64,15 @@ module Agents
|
|
62
64
|
unless options['mode'].present? && modes.include?(options['mode'])
|
63
65
|
errors.add(:base, "mode is a required field and must be one of: #{modes.join(', ')}")
|
64
66
|
end
|
67
|
+
|
68
|
+
if options['not_purchasable_format_list'].present? && !options['not_purchasable_format_list'].is_a?(Array)
|
69
|
+
errors.add(:base, 'not_purchasable_format_list must be an Array')
|
70
|
+
end
|
71
|
+
|
72
|
+
if options.has_key?('should_disambiguate') && boolify(options['should_disambiguate']).nil?
|
73
|
+
errors.add(:base, 'when provided, `should_disambiguate` must be either true or false')
|
74
|
+
end
|
75
|
+
|
65
76
|
end
|
66
77
|
|
67
78
|
def working?
|
@@ -119,6 +130,16 @@ module Agents
|
|
119
130
|
wrapper_skus.map {|k,v| v},
|
120
131
|
%w[custom_fields options]
|
121
132
|
)
|
133
|
+
#save skus
|
134
|
+
digital_skus = []
|
135
|
+
physical_skus = []
|
136
|
+
if split[:digital] and split[:physical]
|
137
|
+
digital_skus.concat([wrapper_skus[:digital]])
|
138
|
+
digital_skus.concat(get_mapper(:ProductMapper).get_product_skus(split[:digital])).join(",")
|
139
|
+
physical_skus.concat([wrapper_skus[:physical]])
|
140
|
+
physical_skus.concat(get_mapper(:ProductMapper).get_product_skus(split[:physical])).join(",")
|
141
|
+
end
|
142
|
+
|
122
143
|
# upsert wrapper products
|
123
144
|
split.each do |type, product|
|
124
145
|
is_digital = type == :digital ? true : false
|
@@ -128,15 +149,26 @@ module Agents
|
|
128
149
|
product['name'] = "#{product['name']} (Digital)"
|
129
150
|
end
|
130
151
|
|
152
|
+
# Ignatius Press -- some products have the same name and must be disambiguated.
|
153
|
+
# ...by adding a list of the product types (hardback, paperback, etc.) to their names
|
154
|
+
if boolify(options['should_disambiguate'])
|
155
|
+
product['name'] += " |~ " + product['model'].map { |m|
|
156
|
+
m['additionalProperty'].find { |p|
|
157
|
+
p['propertyID'] == 'option'
|
158
|
+
}['value']
|
159
|
+
}.join(", ")
|
160
|
+
end
|
161
|
+
|
131
162
|
wrapper_sku = wrapper_skus[type]
|
132
163
|
bc_product = bc_products[wrapper_sku]
|
133
164
|
variant_option_name = get_mapper(:OptionMapper).variant_option_name
|
134
165
|
bc_option = !bc_product.nil? ? bc_product['options'].select {|opt| opt['display_name'] === variant_option_name}.first : nil
|
135
166
|
|
167
|
+
search_skus = is_digital ? physical_skus : digital_skus
|
136
168
|
# ##############################
|
137
169
|
# 1. update wrapper product
|
138
170
|
# ##############################
|
139
|
-
upsert_result = upsert_product(wrapper_sku, product, bc_product, is_digital)
|
171
|
+
upsert_result = upsert_product(wrapper_sku, product, bc_product, is_digital, search_skus)
|
140
172
|
bc_product = upsert_result[:product]
|
141
173
|
|
142
174
|
# clean up custom/meta fields. there are not batch operations so we might as well do them here.
|
@@ -183,6 +215,8 @@ module Agents
|
|
183
215
|
[option_value],
|
184
216
|
product_id,
|
185
217
|
bc_variant.nil? ? nil : bc_variant['id'],
|
218
|
+
interpolated['not_purchasable_format_list'],
|
219
|
+
bc_option_value
|
186
220
|
)
|
187
221
|
end
|
188
222
|
|
@@ -330,7 +364,7 @@ module Agents
|
|
330
364
|
return ::BigcommerceProductAgent::Mapper.const_get(class_name.to_sym)
|
331
365
|
end
|
332
366
|
|
333
|
-
def upsert_product(sku, product, bc_product = nil, is_digital=false)
|
367
|
+
def upsert_product(sku, product, bc_product = nil, is_digital=false, search_skus=[])
|
334
368
|
custom_fields_updates = get_mapper(:CustomFieldMapper).map(
|
335
369
|
interpolated['custom_fields_map'],
|
336
370
|
product,
|
@@ -343,7 +377,10 @@ module Agents
|
|
343
377
|
sku,
|
344
378
|
product,
|
345
379
|
product_id,
|
346
|
-
{
|
380
|
+
{
|
381
|
+
additional_search_terms: search_skus,
|
382
|
+
custom_fields: custom_fields_updates[:upsert]
|
383
|
+
},
|
347
384
|
is_digital,
|
348
385
|
)
|
349
386
|
|
@@ -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.7.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-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|