shopify_transporter 2.2.0 → 2.3.1
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 +4 -4
- data/lib/shopify_transporter/pipeline/magento/order/discounts.rb +115 -0
- data/lib/shopify_transporter/pipeline/magento/order/line_items.rb +40 -1
- data/lib/shopify_transporter/pipeline/magento/order/top_level_attributes.rb +8 -12
- data/lib/shopify_transporter/pipeline/magento/product/top_level_attributes.rb +1 -1
- data/lib/shopify_transporter/pipeline/magento/product/top_level_variant_attributes.rb +8 -7
- data/lib/shopify_transporter/pipeline/magento/product/variant_attributes.rb +10 -5
- data/lib/shopify_transporter/pipeline/magento/product/variant_image.rb +1 -5
- data/lib/shopify_transporter/shopify/order.rb +25 -6
- data/lib/shopify_transporter/version.rb +1 -1
- data/lib/templates/magento/config.tt +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29372540546b779b2d3a248f7dd2c2079d9a22a2
|
4
|
+
data.tar.gz: b1729a6eea756fceb2871d3a7393170269bc2806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ed229bfda72b6f2a0bd1173b7c4dfdbd8cb33527b14da1e38e0482c51325f328778bf454942caf3972c8613626e794ffa2979de45070a851ceb64955f9765f2
|
7
|
+
data.tar.gz: 9cc15dd97c160becb4200f49259399f7a879a07b8ca396d4984dc370b1014c4cc10caed7976453fce0e321e16c5190901ca0e9f525c38abdd564c4b57517f097
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'shopify_transporter/pipeline/stage'
|
3
|
+
require 'shopify_transporter/shopify'
|
4
|
+
|
5
|
+
module ShopifyTransporter
|
6
|
+
module Pipeline
|
7
|
+
module Magento
|
8
|
+
module Order
|
9
|
+
class Discounts < Pipeline::Stage
|
10
|
+
def convert(input, record)
|
11
|
+
record.merge!(
|
12
|
+
{
|
13
|
+
discounts: discounts(input),
|
14
|
+
}.stringify_keys
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def discounts(hash)
|
21
|
+
[
|
22
|
+
shipping_discount(hash),
|
23
|
+
fixed_amount_discount(hash),
|
24
|
+
percentage_discount(hash),
|
25
|
+
].compact
|
26
|
+
end
|
27
|
+
|
28
|
+
def shipping_discount(hash)
|
29
|
+
shipping_discount_amount = value_as_float(hash, 'shipping_discount_amount')
|
30
|
+
shipping_amount = value_as_float(hash, 'shipping_amount')
|
31
|
+
return unless shipping_discount_amount > shipping_amount
|
32
|
+
|
33
|
+
{
|
34
|
+
code: discount_code(hash),
|
35
|
+
amount: shipping_discount_amount,
|
36
|
+
type: 'shipping',
|
37
|
+
}.stringify_keys
|
38
|
+
end
|
39
|
+
|
40
|
+
def fixed_amount_discount(hash)
|
41
|
+
return unless fixed_amount_discount?(hash)
|
42
|
+
|
43
|
+
{
|
44
|
+
code: discount_code(hash),
|
45
|
+
amount: discount_amount(hash),
|
46
|
+
type: 'fixed_amount',
|
47
|
+
}.stringify_keys
|
48
|
+
end
|
49
|
+
|
50
|
+
def percentage_discount(hash)
|
51
|
+
return unless percentage_discount?(hash)
|
52
|
+
|
53
|
+
{
|
54
|
+
code: discount_code(hash),
|
55
|
+
amount: discount_percentage(hash),
|
56
|
+
type: 'percentage',
|
57
|
+
}.stringify_keys
|
58
|
+
end
|
59
|
+
|
60
|
+
def discount_percentage(hash)
|
61
|
+
if qualifies_for_percentage_discount?(hash)
|
62
|
+
if line_items(hash).is_a?(Hash)
|
63
|
+
value_as_float(line_items(hash), 'discount_percent')
|
64
|
+
elsif line_items(hash).is_a?(Array)
|
65
|
+
all_discount_percentages(hash).first
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def discount_code(hash)
|
71
|
+
hash['discount_description'].present? ? hash['discount_description'] : 'Magento'
|
72
|
+
end
|
73
|
+
|
74
|
+
def discount_amount(hash)
|
75
|
+
hash['discount_amount'].present? ? hash['discount_amount'].to_f.abs : 0
|
76
|
+
end
|
77
|
+
|
78
|
+
def value_as_float(hash, key)
|
79
|
+
hash[key].present? ? hash[key].to_f : 0
|
80
|
+
end
|
81
|
+
|
82
|
+
def qualifies_for_percentage_discount?(hash)
|
83
|
+
return false unless line_items?(hash)
|
84
|
+
|
85
|
+
return true if line_items(hash).is_a?(Hash) && value_as_float(line_items(hash), 'discount_percent') > 0
|
86
|
+
|
87
|
+
all_discount_percentages(hash).length == 1 && all_discount_percentages(hash).first > 0
|
88
|
+
end
|
89
|
+
|
90
|
+
def line_items?(hash)
|
91
|
+
hash.dig('items', 'result', 'items', 'item').present?
|
92
|
+
end
|
93
|
+
|
94
|
+
def line_items(hash)
|
95
|
+
hash['items']['result']['items']['item']
|
96
|
+
end
|
97
|
+
|
98
|
+
def all_discount_percentages(hash)
|
99
|
+
line_items(hash).map do |line_item|
|
100
|
+
value_as_float(line_item, 'discount_percent')
|
101
|
+
end.uniq
|
102
|
+
end
|
103
|
+
|
104
|
+
def fixed_amount_discount?(hash)
|
105
|
+
discount_amount(hash) > 0 && !qualifies_for_percentage_discount?(hash)
|
106
|
+
end
|
107
|
+
|
108
|
+
def percentage_discount?(hash)
|
109
|
+
discount_amount(hash) > 0 && qualifies_for_percentage_discount?(hash)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -36,7 +36,10 @@ module ShopifyTransporter
|
|
36
36
|
quantity: item['qty_ordered'],
|
37
37
|
sku: item['sku'],
|
38
38
|
name: item['name'],
|
39
|
+
requires_shipping: requires_shipping?(item),
|
39
40
|
price: item['price'],
|
41
|
+
taxable: taxable?(item),
|
42
|
+
fulfillment_status: fulfillment_status(item),
|
40
43
|
tax_lines: tax_lines(item),
|
41
44
|
}.stringify_keys
|
42
45
|
end
|
@@ -47,11 +50,47 @@ module ShopifyTransporter
|
|
47
50
|
{
|
48
51
|
title: 'Tax',
|
49
52
|
price: item['tax_amount'],
|
50
|
-
rate: item
|
53
|
+
rate: tax_percentage(item),
|
51
54
|
}.stringify_keys,
|
52
55
|
]
|
53
56
|
end
|
54
57
|
|
58
|
+
def tax_percentage(item)
|
59
|
+
item['tax_percent'].to_f / 100
|
60
|
+
end
|
61
|
+
|
62
|
+
def fulfillment_status(item)
|
63
|
+
qty_ordered = qty_by_status(item, 'ordered')
|
64
|
+
qty_shipped = qty_by_status(item, 'shipped')
|
65
|
+
qty_refunded = qty_by_status(item, 'refunded')
|
66
|
+
if fully_fulfilled?(qty_ordered, qty_shipped, qty_refunded)
|
67
|
+
'fulfilled'
|
68
|
+
elsif partially_fulfilled?(qty_shipped, qty_ordered)
|
69
|
+
'partial'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def fully_fulfilled?(qty_ordered, qty_shipped, qty_refunded)
|
74
|
+
qty_ordered == qty_shipped && qty_refunded == 0 && qty_shipped > 0
|
75
|
+
end
|
76
|
+
|
77
|
+
def partially_fulfilled?(qty_shipped, qty_ordered)
|
78
|
+
qty_shipped > 0 && qty_shipped < qty_ordered
|
79
|
+
end
|
80
|
+
|
81
|
+
def requires_shipping?(item)
|
82
|
+
item['is_virtual'].to_i == 0
|
83
|
+
end
|
84
|
+
|
85
|
+
def taxable?(item)
|
86
|
+
item['tax_amount'].to_f > 0
|
87
|
+
end
|
88
|
+
|
89
|
+
def qty_by_status(item, status)
|
90
|
+
key = "qty_#{status}"
|
91
|
+
item[key].present? ? item[key].to_i : 0
|
92
|
+
end
|
93
|
+
|
55
94
|
def tax_applied?(item)
|
56
95
|
item['tax_percent'].to_f > 0 && item['tax_amount'].to_f > 0
|
57
96
|
end
|
@@ -43,21 +43,17 @@ module ShopifyTransporter
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def financial_status(hash)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if order_state == 'Pending Payment'
|
50
|
-
status = 'pending'
|
51
|
-
elsif paid?(hash)
|
52
|
-
status = 'paid'
|
46
|
+
if paid?(hash)
|
47
|
+
'paid'
|
53
48
|
elsif partially_paid?(hash)
|
54
|
-
|
49
|
+
'partially_paid'
|
55
50
|
elsif partially_refunded?(hash)
|
56
|
-
|
51
|
+
'partially_refunded'
|
57
52
|
elsif refunded?(hash)
|
58
|
-
|
53
|
+
'refunded'
|
54
|
+
else
|
55
|
+
'pending'
|
59
56
|
end
|
60
|
-
status
|
61
57
|
end
|
62
58
|
|
63
59
|
def fulfillment_status(hash)
|
@@ -104,7 +100,7 @@ module ShopifyTransporter
|
|
104
100
|
end
|
105
101
|
|
106
102
|
def paid?(hash)
|
107
|
-
total_price(hash) == total_paid(hash) && total_refunded(hash) == 0
|
103
|
+
total_price(hash) == total_paid(hash) && total_paid(hash) > 0 && total_refunded(hash) == 0
|
108
104
|
end
|
109
105
|
|
110
106
|
def partially_paid?(hash)
|
@@ -8,18 +8,15 @@ module ShopifyTransporter
|
|
8
8
|
module Product
|
9
9
|
class TopLevelVariantAttributes < Pipeline::Stage
|
10
10
|
def convert(hash, record)
|
11
|
-
return unless
|
12
|
-
simple_product_in_magento_format = record['variants'].
|
11
|
+
return {} unless record.key?('variants')
|
12
|
+
simple_product_in_magento_format = record['variants'].find do |product|
|
13
13
|
product['product_id'] == hash['product_id']
|
14
|
-
end
|
14
|
+
end
|
15
|
+
return {} unless simple_product_in_magento_format.present?
|
15
16
|
accumulator = TopLevelVariantAttributesAccumulator.new(simple_product_in_magento_format)
|
16
17
|
accumulator.accumulate(hash)
|
17
18
|
end
|
18
19
|
|
19
|
-
def input_applies?(input)
|
20
|
-
true unless input['parent_id'].nil?
|
21
|
-
end
|
22
|
-
|
23
20
|
class TopLevelVariantAttributesAccumulator < Shopify::AttributesAccumulator
|
24
21
|
COLUMN_MAPPING = {
|
25
22
|
'sku' => 'sku',
|
@@ -35,6 +32,10 @@ module ShopifyTransporter
|
|
35
32
|
|
36
33
|
private
|
37
34
|
|
35
|
+
def input_applies?(input)
|
36
|
+
input.present? && input['type'] == 'simple'
|
37
|
+
end
|
38
|
+
|
38
39
|
def variant_options(input)
|
39
40
|
{
|
40
41
|
'option1' => input['option1_value'],
|
@@ -14,11 +14,16 @@ module ShopifyTransporter
|
|
14
14
|
|
15
15
|
class VariantAttributesAccumulator < Shopify::AttributesAccumulator
|
16
16
|
def accumulate(current_product)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
return @output unless input_applies?(current_product)
|
18
|
+
@output['variants'] ||= []
|
19
|
+
@output['variants'] << current_product
|
20
|
+
@output
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def input_applies?(current_product)
|
26
|
+
current_product['type'] == 'simple'
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
@@ -8,16 +8,12 @@ module ShopifyTransporter
|
|
8
8
|
module Product
|
9
9
|
class VariantImage < Pipeline::Stage
|
10
10
|
def convert(hash, record)
|
11
|
-
return unless
|
11
|
+
return {} unless hash['images'].present? && hash['parent_id'].present?
|
12
12
|
add_variant_image!(hash, record)
|
13
13
|
add_variant_image_to_parent_images!(hash, record)
|
14
14
|
record
|
15
15
|
end
|
16
16
|
|
17
|
-
def input_applied?(input)
|
18
|
-
input['images'].present? && input['parent_id'].present?
|
19
|
-
end
|
20
|
-
|
21
17
|
def current_variant(input, record)
|
22
18
|
record['variants'].select do |variant|
|
23
19
|
variant['product_id'] == input['product_id']
|
@@ -14,7 +14,7 @@ module ShopifyTransporter
|
|
14
14
|
[
|
15
15
|
'Name', 'Email', 'Financial Status', 'Fulfillment Status', 'Currency',
|
16
16
|
'Buyer Accepts Marketing', 'Cancel Reason', 'Cancelled At', 'Closed At', 'Tags', 'Note',
|
17
|
-
'Phone', 'Referring Site', 'Processed At', 'Source name', 'Total
|
17
|
+
'Phone', 'Referring Site', 'Processed At', 'Source name', 'Total weight',
|
18
18
|
'Total Tax', 'Shipping Company', 'Shipping Name', 'Shipping Phone', 'Shipping First Name',
|
19
19
|
'Shipping Last Name', 'Shipping Address1', 'Shipping Address2', 'Shipping City',
|
20
20
|
'Shipping Province', 'Shipping Province Code', 'Shipping Zip', 'Shipping Country',
|
@@ -22,10 +22,11 @@ module ShopifyTransporter
|
|
22
22
|
'Billing First Name', 'Billing Last Name', 'Billing Address1', 'Billing Address2',
|
23
23
|
'Billing City', 'Billing Province', 'Billing Province Code', 'Billing Zip',
|
24
24
|
'Billing Country', 'Billing Country Code', 'Lineitem name', 'Lineitem quantity',
|
25
|
-
'Lineitem price', 'Lineitem
|
26
|
-
'Lineitem
|
27
|
-
'Tax
|
28
|
-
'
|
25
|
+
'Lineitem price', 'Lineitem sku', 'Lineitem requires shipping', 'Lineitem taxable',
|
26
|
+
'Lineitem fulfillment status', 'Tax 1 Title', 'Tax 1 Price', 'Tax 1 Rate', 'Tax 2 Title',
|
27
|
+
'Tax 2 Price', 'Tax 2 Rate', 'Tax 3 Title', 'Tax 3 Price', 'Tax 3 Rate',
|
28
|
+
'Transaction amount', 'Transaction kind', 'Transaction status',
|
29
|
+
'Discount code', 'Discount amount', 'Discount type',
|
29
30
|
'Metafield Namespace', 'Metafield Key', 'Metafield Value', 'Metafield Value Type'
|
30
31
|
].to_csv
|
31
32
|
end
|
@@ -46,6 +47,7 @@ module ShopifyTransporter
|
|
46
47
|
csv << top_level_row_values
|
47
48
|
line_item_row_values.each { |row| csv << row }
|
48
49
|
transaction_row_values.each { |row| csv << row }
|
50
|
+
discount_row_values.each { |row| csv << row }
|
49
51
|
metafield_row_values.each { |row| csv << row }
|
50
52
|
end
|
51
53
|
end
|
@@ -65,7 +67,7 @@ module ShopifyTransporter
|
|
65
67
|
LINE_ITEM_PREFIX = 'lineitem_'
|
66
68
|
|
67
69
|
LINE_ITEM_ATTRIBUTES = %w(
|
68
|
-
name quantity price
|
70
|
+
name quantity price sku requires_shipping taxable fulfillment_status
|
69
71
|
)
|
70
72
|
|
71
73
|
TRANSACTION_PREFIX = 'transaction_'
|
@@ -74,6 +76,12 @@ module ShopifyTransporter
|
|
74
76
|
amount kind status
|
75
77
|
)
|
76
78
|
|
79
|
+
DISCOUNT_PREFIX = 'discount_'
|
80
|
+
|
81
|
+
DISCOUNT_ATTRIBUTES = %w(
|
82
|
+
code amount type
|
83
|
+
)
|
84
|
+
|
77
85
|
def address_hash_for(address_hash, prefix)
|
78
86
|
return {} if address_hash.blank?
|
79
87
|
|
@@ -120,6 +128,17 @@ module ShopifyTransporter
|
|
120
128
|
row_values_from(transaction) if self.class.has_values?(transaction)
|
121
129
|
end.compact
|
122
130
|
end
|
131
|
+
|
132
|
+
def discount_row_values
|
133
|
+
return [] unless record_hash['discounts']
|
134
|
+
|
135
|
+
record_hash['discounts'].map do |discount_hash|
|
136
|
+
discount = discount_hash.slice(*DISCOUNT_ATTRIBUTES)
|
137
|
+
.transform_keys! { |k| "#{DISCOUNT_PREFIX}#{k}" }
|
138
|
+
|
139
|
+
row_values_from(discount) if self.class.has_values?(discount)
|
140
|
+
end.compact
|
141
|
+
end
|
123
142
|
end
|
124
143
|
end
|
125
144
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_transporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- lib/shopify_transporter/pipeline/magento/customer/addresses_attribute.rb
|
162
162
|
- lib/shopify_transporter/pipeline/magento/customer/top_level_attributes.rb
|
163
163
|
- lib/shopify_transporter/pipeline/magento/order/addresses_attribute.rb
|
164
|
+
- lib/shopify_transporter/pipeline/magento/order/discounts.rb
|
164
165
|
- lib/shopify_transporter/pipeline/magento/order/line_items.rb
|
165
166
|
- lib/shopify_transporter/pipeline/magento/order/top_level_attributes.rb
|
166
167
|
- lib/shopify_transporter/pipeline/magento/order/transactions.rb
|