shopify_transporter 2.3.1 → 2.4.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
  SHA1:
3
- metadata.gz: 29372540546b779b2d3a248f7dd2c2079d9a22a2
4
- data.tar.gz: b1729a6eea756fceb2871d3a7393170269bc2806
3
+ metadata.gz: d74afe8f2cffa7be367716d17ee580cb69e793f4
4
+ data.tar.gz: 5193dbb1507a03df56e4c945f07fedfa29fdc2f1
5
5
  SHA512:
6
- metadata.gz: 2ed229bfda72b6f2a0bd1173b7c4dfdbd8cb33527b14da1e38e0482c51325f328778bf454942caf3972c8613626e794ffa2979de45070a851ceb64955f9765f2
7
- data.tar.gz: 9cc15dd97c160becb4200f49259399f7a879a07b8ca396d4984dc370b1014c4cc10caed7976453fce0e321e16c5190901ca0e9f525c38abdd564c4b57517f097
6
+ metadata.gz: 3a0fc07d7ab1c33b3d5556c9a3464c5a120b89e71b48072b0579e9098093c20933c29e3a152ba8ea59c678bf4a0952e968c07736babad5418aa90f318a7453ae
7
+ data.tar.gz: c7d9751cfd089ee8d73383ac09635350a6a72b1555ddd8aec67c23a9b5607d80ff895492e1d0fc49b487857cedeb20a46a8a491363d39d12989542cc3cccdcac
@@ -19,14 +19,24 @@ module ShopifyTransporter
19
19
 
20
20
  def line_items(input)
21
21
  line_items = line_items_array(input)
22
- line_items.map { |item| line_item(item) }
22
+ combine_associated_line_items(line_items.map { |item| line_item(item) })
23
+ end
24
+
25
+ def combine_associated_line_items(line_items)
26
+ line_items.group_by { |line_item| line_item['sku'] }.map do |_, associated_items|
27
+ case associated_items.size
28
+ when 1
29
+ associated_items.first
30
+ when 2
31
+ parent = associated_items.find { |x| x['product_type'] == 'configurable' }
32
+ child = associated_items.find { |x| x['product_type'] == 'simple' }
33
+ parent.merge(child.slice('name'))
34
+ end.except('product_type')
35
+ end
23
36
  end
24
37
 
25
38
  def line_items_array(input)
26
- items_1 = input['items']
27
- result = items_1 && items_1['result']
28
- items_2 = result && result['items']
29
- item = items_2 && items_2['item']
39
+ item = input.dig('items', 'result', 'items', 'item')
30
40
  return [] unless item
31
41
  item.is_a?(Array) ? item : [item]
32
42
  end
@@ -41,6 +51,7 @@ module ShopifyTransporter
41
51
  taxable: taxable?(item),
42
52
  fulfillment_status: fulfillment_status(item),
43
53
  tax_lines: tax_lines(item),
54
+ product_type: item['product_type'],
44
55
  }.stringify_keys
45
56
  end
46
57
 
@@ -0,0 +1,41 @@
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 ShippingLines < Pipeline::Stage
10
+ def convert(input, record)
11
+ record.merge(
12
+ {
13
+ shipping_lines: shipping_lines(input),
14
+ }.stringify_keys
15
+ )
16
+ end
17
+
18
+ private
19
+
20
+ def shipping_lines(input)
21
+ [
22
+ {
23
+ code: input['shipping_description'],
24
+ title: input['shipping_description'],
25
+ price: input['shipping_amount'],
26
+ carrier_identifier: input['shipping_method'],
27
+ tax_lines: shipping_tax_lines(input),
28
+ }.stringify_keys,
29
+ ]
30
+ end
31
+
32
+ def shipping_tax_lines(input)
33
+ return unless input['shipping_tax_amount'].present? && input['shipping_tax_amount'].to_f != 0
34
+
35
+ [{ price: input['shipping_tax_amount'] }.stringify_keys]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -57,12 +57,36 @@ module ShopifyTransporter
57
57
  ).freeze
58
58
 
59
59
  def top_level_row_values
60
- base_hash.merge(record_hash.slice(*TOP_LEVEL_ATTRIBUTES)).values
60
+ return top_level_attributes.values unless able_to_merge_default_address?
61
+
62
+ top_level_attributes.merge(default_address.compact).values_at(*Customer.columns)
63
+ end
64
+
65
+ def top_level_attributes
66
+ base_hash.merge(record_hash.slice(*TOP_LEVEL_ATTRIBUTES))
67
+ end
68
+
69
+ def default_address
70
+ return {} unless at_least_one_address?
71
+
72
+ record_hash['addresses'][0].slice(*ADDRESS_ATTRIBUTES)
73
+ end
74
+
75
+ def at_least_one_address?
76
+ record_hash['addresses'].present? && record_hash['addresses'][0].present?
77
+ end
78
+
79
+ def able_to_merge_default_address?
80
+ !top_level_attributes.compact.keys.any? do |key|
81
+ default_address[key].present? && top_level_attributes[key] != default_address[key]
82
+ end
61
83
  end
62
84
 
63
85
  def address_row_values
64
- return [] unless record_hash['addresses']
65
- record_hash['addresses'].map do |address_hash|
86
+ return [] unless at_least_one_address?
87
+
88
+ addresses = able_to_merge_default_address? ? record_hash['addresses'].drop(1) : record_hash['addresses']
89
+ addresses.map do |address_hash|
66
90
  address = address_hash.slice(*ADDRESS_ATTRIBUTES)
67
91
  populate_missing_address_attributes!(address)
68
92
  row_values_from(address) if self.class.has_values?(address)
@@ -26,6 +26,8 @@ module ShopifyTransporter
26
26
  'Lineitem fulfillment status', 'Tax 1 Title', 'Tax 1 Price', 'Tax 1 Rate', 'Tax 2 Title',
27
27
  'Tax 2 Price', 'Tax 2 Rate', 'Tax 3 Title', 'Tax 3 Price', 'Tax 3 Rate',
28
28
  'Transaction amount', 'Transaction kind', 'Transaction status',
29
+ 'Shipping line code', 'Shipping line price', 'Shipping line title', 'Shipping line carrier identifier',
30
+ 'Shipping Tax Price',
29
31
  'Discount code', 'Discount amount', 'Discount type',
30
32
  'Metafield Namespace', 'Metafield Key', 'Metafield Value', 'Metafield Value Type'
31
33
  ].to_csv
@@ -47,6 +49,7 @@ module ShopifyTransporter
47
49
  csv << top_level_row_values
48
50
  line_item_row_values.each { |row| csv << row }
49
51
  transaction_row_values.each { |row| csv << row }
52
+ shipping_line_row_values.each { |row| csv << row }
50
53
  discount_row_values.each { |row| csv << row }
51
54
  metafield_row_values.each { |row| csv << row }
52
55
  end
@@ -82,6 +85,12 @@ module ShopifyTransporter
82
85
  code amount type
83
86
  )
84
87
 
88
+ SHIPPING_LINE_PREFIX = 'shipping_line_'
89
+
90
+ SHIPPING_LINE_ATTRIBUTES = %w(
91
+ code price title carrier_identifier
92
+ )
93
+
85
94
  def address_hash_for(address_hash, prefix)
86
95
  return {} if address_hash.blank?
87
96
 
@@ -111,7 +120,7 @@ module ShopifyTransporter
111
120
 
112
121
  record_hash['line_items'].map do |line_item_hash|
113
122
  line_item = line_item_hash.slice(*LINE_ITEM_ATTRIBUTES)
114
- .transform_keys! { |k| "#{LINE_ITEM_PREFIX}#{k}" }
123
+ .transform_keys { |k| "#{LINE_ITEM_PREFIX}#{k}" }
115
124
  .merge(tax_line_hash(line_item_hash))
116
125
 
117
126
  row_values_from(line_item) if self.class.has_values?(line_item)
@@ -123,7 +132,7 @@ module ShopifyTransporter
123
132
 
124
133
  record_hash['transactions'].map do |transaction_hash|
125
134
  transaction = transaction_hash.slice(*TRANSACTION_ATTRIBUTES)
126
- .transform_keys! { |k| "#{TRANSACTION_PREFIX}#{k}" }
135
+ .transform_keys { |k| "#{TRANSACTION_PREFIX}#{k}" }
127
136
 
128
137
  row_values_from(transaction) if self.class.has_values?(transaction)
129
138
  end.compact
@@ -134,11 +143,33 @@ module ShopifyTransporter
134
143
 
135
144
  record_hash['discounts'].map do |discount_hash|
136
145
  discount = discount_hash.slice(*DISCOUNT_ATTRIBUTES)
137
- .transform_keys! { |k| "#{DISCOUNT_PREFIX}#{k}" }
146
+ .transform_keys { |k| "#{DISCOUNT_PREFIX}#{k}" }
138
147
 
139
148
  row_values_from(discount) if self.class.has_values?(discount)
140
149
  end.compact
141
150
  end
151
+
152
+ def shipping_line_row_values
153
+ return [] unless record_hash['shipping_lines']
154
+
155
+ record_hash['shipping_lines'].map do |shipping_line_hash|
156
+ shipping_line = shipping_line_hash.slice(*SHIPPING_LINE_ATTRIBUTES)
157
+ .transform_keys { |k| "#{SHIPPING_LINE_PREFIX}#{k}" }
158
+ .merge(shipping_tax_hash(shipping_line_hash))
159
+
160
+ row_values_from(shipping_line) if self.class.has_values?(shipping_line)
161
+ end.compact
162
+ end
163
+
164
+ def shipping_tax_hash(shipping_line_hash)
165
+ return {} if shipping_line_hash['tax_lines'].blank?
166
+
167
+ shipping_line_hash['tax_lines'].map do |tax_line|
168
+ tax_line.each_with_object({}) do |(key, val), hash|
169
+ hash["shipping_tax_#{key}"] = val
170
+ end
171
+ end.reduce({}, :merge)
172
+ end
142
173
  end
143
174
  end
144
175
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ShopifyTransporter
3
- VERSION = '2.3.1'
3
+ VERSION = '2.4.0'
4
4
  end
@@ -30,6 +30,7 @@ object_types:
30
30
  - AddressesAttribute
31
31
  - Transactions
32
32
  - Discounts
33
+ - ShippingLines
33
34
 
34
35
  extract_configuration:
35
36
  soap:
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.3.1
4
+ version: 2.4.0
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-25 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -163,6 +163,7 @@ files:
163
163
  - lib/shopify_transporter/pipeline/magento/order/addresses_attribute.rb
164
164
  - lib/shopify_transporter/pipeline/magento/order/discounts.rb
165
165
  - lib/shopify_transporter/pipeline/magento/order/line_items.rb
166
+ - lib/shopify_transporter/pipeline/magento/order/shipping_lines.rb
166
167
  - lib/shopify_transporter/pipeline/magento/order/top_level_attributes.rb
167
168
  - lib/shopify_transporter/pipeline/magento/order/transactions.rb
168
169
  - lib/shopify_transporter/pipeline/magento/product/top_level_attributes.rb