huginn_bigcommerce_product_agent 1.12.0 → 2.0.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.
@@ -1,35 +0,0 @@
1
- module BigcommerceProductAgent
2
- module Client
3
- class Modifier < AbstractClient
4
- @uri_base = 'catalog/products/:product_id/modifiers/:modifier_id'
5
-
6
- def delete(product_id, modifier_id)
7
- client.delete(uri(product_id: product_id, modifier_id: modifier_id))
8
- end
9
-
10
- def upsert(product_id, modifier)
11
- begin
12
- if modifier[:id] || modifier['id']
13
- modifier['id'] = modifier[:id] unless modifier[:id].nil?
14
- return update(product_id, modifier)
15
- else
16
- return create(product_id, modifier)
17
- end
18
- rescue Faraday::Error::ClientError => e
19
- puts e.inspect
20
- raise e
21
- end
22
- end
23
-
24
- def update(product_id, modifier)
25
- response = client.put(uri(product_id: product_id, modifier_id: modifier['id']), modifier.to_json)
26
- return response.body['data']
27
- end
28
-
29
- def create(product_id, modifier)
30
- response = client.post(uri(product_id: product_id), modifier.to_json)
31
- return response.body['data']
32
- end
33
- end
34
- end
35
- end
@@ -1,11 +0,0 @@
1
- module BigcommerceProductAgent
2
- module Client
3
- class ModifierValue < AbstractClient
4
- @uri_base = 'catalog/products/:product_id/modifiers/:modifier_id/values/:value_id'
5
-
6
- def delete(product_id, modifier_id, value_id)
7
- client.delete(uri(product_id: product_id, modifier_id: modifier_id, value_id: value_id))
8
- end
9
- end
10
- end
11
- end
@@ -1,45 +0,0 @@
1
- module BigcommerceProductAgent
2
- module Client
3
- class ProductOption < AbstractClient
4
- @uri_base = 'catalog/products/:product_id/options/:option_id'
5
-
6
- def delete(product_id, option_id)
7
- client.delete(uri(product_id: product_id, option_id: option_id))
8
- end
9
-
10
- def delete_all(options)
11
- options.each do |option|
12
- delete(option['product_id'], option['id'])
13
- end
14
- end
15
-
16
- def upsert(product_id, option)
17
- begin
18
- if option[:id] || option['id']
19
- option['id'] = option[:id] unless option[:id].nil?
20
- return update(product_id, option)
21
- else
22
- return create(product_id, option)
23
- end
24
- rescue Faraday::Error::ClientError => e
25
- puts e.inspect
26
- raise e
27
- end
28
- end
29
-
30
- def update(product_id, option)
31
- response = client.put(uri(product_id: product_id, option_id: option['id']), option.to_json)
32
- return response.body['data']
33
- end
34
-
35
- def create(product_id, option)
36
- begin
37
- response = client.post(uri(product_id: product_id), option.to_json)
38
- return response.body['data']
39
- rescue Faraday::Error::ClientError => e
40
- raise e, "\n#{e.message}\nFailed to upsert product_option = #{option.to_json}\nfor product with id = #{product_id}\n", e.backtrace
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,72 +0,0 @@
1
- module BigcommerceProductAgent
2
- module Client
3
- class ProductOptionValue < AbstractClient
4
- @uri_base = 'catalog/products/:product_id/options/:option_id/values/:value_id'
5
-
6
- def delete(product_id, option_id, value_id)
7
- client.delete(uri(product_id: product_id, option_id: option_id, value_id: value_id))
8
- end
9
-
10
- def delete_all(option, option_values)
11
- option_values.each do |option_value|
12
- delete(option['product_id'], option['id'], option_value['id'])
13
- end
14
- end
15
-
16
- def upsert(option, option_value)
17
- begin
18
- if option[:product_id] || option['product_id']
19
- option['product_id'] = option[:product_id] unless option[:product_id].nil?
20
- end
21
-
22
- if option[:id] || option['id']
23
- option['id'] = option[:id] unless option[:id].nil?
24
- end
25
-
26
- if option_value[:id] || option_value['id']
27
- option_value['id'] = option_value[:id] unless option_value[:id].nil?
28
- return update(option, option_value)
29
- else
30
- return create(option, option_value)
31
- end
32
- rescue Faraday::Error::ClientError => e
33
- puts e.inspect
34
- raise e
35
- end
36
- end
37
-
38
- def upsert_all(option, option_values)
39
- results = []
40
- option_values.each do |option_value|
41
- result = upsert(option, option_value)
42
- results.push(result)
43
- end
44
-
45
- return results
46
- end
47
-
48
- def update(option, option_value)
49
- response = client.put(
50
- uri(
51
- product_id: option['product_id'],
52
- option_id: option['id'],
53
- value_id: option_value['id'],
54
- ),
55
- option_value.to_json,
56
- )
57
- return response.body['data']
58
- end
59
-
60
- def create(option, option_value)
61
- response = client.post(
62
- uri(
63
- product_id: option['product_id'],
64
- option_id: option['id'],
65
- ),
66
- option_value.to_json,
67
- )
68
- return response.body['data']
69
- end
70
- end
71
- end
72
- end
@@ -1,40 +0,0 @@
1
- module BigcommerceProductAgent
2
- module Client
3
- class ProductVariant < AbstractClient
4
- @uri_base = 'catalog/products/:product_id/variants/:variant_id'
5
-
6
- def index(product_id, params = {})
7
- response = client.get(uri(product_id: product_id), params)
8
- return response.body['data']
9
- end
10
-
11
- def delete(product_id, variant_id)
12
- client.delete(uri(product_id: product_id, variant_id: variant_id))
13
- end
14
-
15
- def upsert(product_id, variant)
16
- begin
17
- if variant[:id] || variant['id']
18
- variant['id'] = variant[:id] unless variant[:id].nil?
19
- return update(product_id, variant)
20
- else
21
- return create(product_id, variant)
22
- end
23
- rescue Faraday::Error::ClientError => e
24
- puts e.inspect
25
- raise e
26
- end
27
- end
28
-
29
- def update(product_id, variant)
30
- response = client.put(uri(product_id: product_id, variant_id: variant['id']), variant.to_json)
31
- return response.body['data']
32
- end
33
-
34
- def create(product_id, variant)
35
- response = client.post(uri(product_id: product_id), variant.to_json)
36
- return response.body['data']
37
- end
38
- end
39
- end
40
- end
@@ -1,40 +0,0 @@
1
- module BigcommerceProductAgent
2
- module Client
3
- class Variant < AbstractClient
4
- @uri_base = 'catalog/variants'
5
-
6
- def update(payload)
7
- raise "this endpoint only has upsert available"
8
- end
9
-
10
- def create(payload)
11
- raise "this endpoint only has upsert available"
12
- end
13
-
14
- def upsert(payload)
15
- begin
16
- response = client.put(uri, payload.to_json)
17
- return response.body['data']
18
- rescue Faraday::Error::ClientError => e
19
- raise e, "\n#{e.message}\nFailed to upsert variant with payload = #{payload.to_json}\n", e.backtrace
20
- end
21
- end
22
-
23
- def get_by_skus(skus, include = %w[custom_fields modifiers])
24
- variants = index({
25
- 'sku:in': skus.join(','),
26
- include: include.join(','),
27
- })
28
-
29
- map = {}
30
-
31
- variants.each do |variant|
32
- map[variant['sku']] = variant
33
- end
34
-
35
- map
36
- end
37
-
38
- end
39
- end
40
- end
@@ -1,83 +0,0 @@
1
- module BigcommerceProductAgent
2
- module Mapper
3
- class ModifierMapper
4
-
5
- def self.map(bc_product, bc_children, sku_option_map, is_default_map)
6
- modifier = {
7
- display_name: 'Option',
8
- type: 'product_list',
9
- required: true,
10
- sort_order: 1,
11
- config: {
12
- product_list_adjusts_inventory: true,
13
- product_list_adjusts_pricing: true,
14
- product_list_shipping_calc: 'none'
15
- },
16
- option_values: []
17
- }
18
-
19
- existing_modifier = nil
20
- existing_option_ids = []
21
- if bc_product && !bc_product['modifiers'].nil?
22
- existing_modifier = bc_product['modifiers'].select {|m| m['display_name'] == modifier[:display_name]}.first
23
- modifier[:product_id] = bc_product['id']
24
-
25
- if !existing_modifier.nil?
26
- modifier[:id] = existing_modifier['id']
27
- existing_option_ids = existing_modifier['option_values'].map {|value| value['id']}
28
- end
29
- end
30
-
31
- bc_children.each do |child|
32
- existing_option = nil
33
- if existing_modifier
34
- existing_option = existing_modifier['option_values'].select do |val|
35
- val['value_data'] && val['value_data']['product_id'] == child['id']
36
- end.first
37
- end
38
-
39
- option = {
40
- label: sku_option_map[child['sku']],
41
- sort_order: 0,
42
- value_data: {
43
- product_id: child['id']
44
- },
45
- is_default: is_default_map[child['sku']],
46
- adjusters: {
47
- price: nil,
48
- weight: nil,
49
- image_url: '',
50
- purchasing_disabled: {
51
- status: false,
52
- message: ''
53
- }
54
- }
55
- }
56
-
57
- if existing_option
58
- option[:id] = existing_option['id']
59
- option[:option_id] = existing_option['option_id']
60
- existing_option_ids.delete(existing_option['id'])
61
- end
62
-
63
- modifier[:option_values].push(option)
64
- end
65
-
66
- # any left over option value should be removed
67
- modifier_values_delete = existing_option_ids.map do |id|
68
- {
69
- product_id: bc_product['id'],
70
- modifier_id: existing_modifier['id'],
71
- value_id: id
72
- }
73
- end
74
-
75
- return {
76
- upsert: modifier,
77
- delete: modifier_values_delete
78
- }
79
- end
80
-
81
- end
82
- end
83
- end