Revision fc58ee00
Von Werner Hahn vor mehr als 3 Jahren hinzugefügt
t/shop/woocommerce.t | ||
---|---|---|
1 |
use strict; |
|
2 |
use Test::More; |
|
3 |
|
|
4 |
use lib 't'; |
|
5 |
use Support::TestSetup; |
|
6 |
use Carp; |
|
7 |
use Test::Exception; |
|
8 |
use SL::Dev::ALL; |
|
9 |
use SL::Dev::Part qw(new_part); |
|
10 |
use SL::Dev::Shop qw(new_shop new_shop_part); |
|
11 |
use SL::Dev::CustomerVendor qw(new_customer); |
|
12 |
use SL::DB::Shop; |
|
13 |
use SL::DB::ShopOrder; |
|
14 |
use SL::DB::ShopOrderItem; |
|
15 |
use SL::Controller::ShopOrder; |
|
16 |
use SL::Shop; |
|
17 |
use Data::Dumper; |
|
18 |
use SL::JSON; |
|
19 |
use SL::ShopConnector::Shopware; |
|
20 |
my ($shop, $shopware, $shop_order, $shop_part, $part, $customer, $employee, $json_import); |
|
21 |
|
|
22 |
sub reset_state { |
|
23 |
my %params = @_; |
|
24 |
|
|
25 |
clear_up(); |
|
26 |
|
|
27 |
$shop = new_shop( connector => 'woocommerce', |
|
28 |
last_order_number => 20000, |
|
29 |
pricetype => 'brutto', |
|
30 |
price_source => 'master_data', |
|
31 |
taxzone_id => 1, |
|
32 |
); |
|
33 |
$shopware = SL::Shop->new( config => $shop ); |
|
34 |
$part = new_part( partnumber => 'SW10002', |
|
35 |
description => 'TITANIUM CARBON GS 12m cm', |
|
36 |
); |
|
37 |
$shop_part = new_shop_part(part => $part, shop => $shop); |
|
38 |
|
|
39 |
$employee = SL::DB::Manager::Employee->current || croak "No employee"; |
|
40 |
|
|
41 |
$customer = new_customer( name => 'Evil Inc', |
|
42 |
street => 'Evil Street', |
|
43 |
zipcode => '66666', |
|
44 |
email => 'evil@evilinc.com' |
|
45 |
)->save; |
|
46 |
} |
|
47 |
|
|
48 |
sub get_data { |
|
49 |
|
|
50 |
my %data = ( |
|
51 |
'_links' => { |
|
52 |
'collection' => [ |
|
53 |
{ |
|
54 |
'href' => 'https://WOOCOMMERCESHOP/wp-json/wc/v3/orders' |
|
55 |
} |
|
56 |
], |
|
57 |
'self' => [ |
|
58 |
{ |
|
59 |
'href' => 'https://WOOCOMMERCESHOP/wp-json/wc/v3/orders/8163' |
|
60 |
} |
|
61 |
] |
|
62 |
}, |
|
63 |
'billing' => { |
|
64 |
'address_1' => 'Hauptstrasse 52a', |
|
65 |
'address_2' => '', |
|
66 |
'city' => 'Halle', |
|
67 |
'company' => '', |
|
68 |
'country' => 'DE', |
|
69 |
'email' => 'test@test.de', |
|
70 |
'first_name' => 'Heike', |
|
71 |
'last_name' => 'Mustermann', |
|
72 |
'phone' => '12345', |
|
73 |
'postcode' => '06118', |
|
74 |
'state' => '' |
|
75 |
}, |
|
76 |
'cart_hash' => '4f978421d12277a81e8b6f83c02fba55', |
|
77 |
'cart_tax' => '0.21', |
|
78 |
'coupon_lines' => [], |
|
79 |
'created_via' => 'checkout', |
|
80 |
'currency' => 'EUR', |
|
81 |
'currency_symbol' => "\x{20ac}", |
|
82 |
'customer_id' => 0, |
|
83 |
'customer_ip_address' => '888.888.888.888', |
|
84 |
'customer_note' => '', |
|
85 |
'customer_user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0', |
|
86 |
'date_completed' => '2021-04-13T10:04:12', |
|
87 |
'date_completed_gmt' => '2021-04-13T08:04:12', |
|
88 |
'date_created' => '2021-04-12T11:56:42', |
|
89 |
'date_created_gmt' => '2021-04-12T09:56:42', |
|
90 |
'date_modified' => '2021-04-13T10:04:12', |
|
91 |
'date_modified_gmt' => '2021-04-13T08:04:12', |
|
92 |
'date_paid' => '2021-04-12T11:56:44', |
|
93 |
'date_paid_gmt' => '2021-04-12T09:56:44', |
|
94 |
'discount_tax' => '0.00', |
|
95 |
'discount_total' => '0.00', |
|
96 |
'fee_lines' => [], |
|
97 |
'id' => 8163, |
|
98 |
'line_items' => [ |
|
99 |
{ |
|
100 |
'id' => 33594, |
|
101 |
'meta_data' => [ |
|
102 |
{ |
|
103 |
'display_key' => 'Verpackungseinheit', |
|
104 |
'display_value' => "P\x{e4}ckchen mit 12 Samen", |
|
105 |
'id' => 323242, |
|
106 |
'key' => 'pa_verpackungseinheit', |
|
107 |
'value' => 'paeckchen-mit-12-samen' |
|
108 |
}, |
|
109 |
{ |
|
110 |
'display_key' => '_deliverytime', |
|
111 |
'display_value' => '151', |
|
112 |
'id' => 323243, |
|
113 |
'key' => '_deliverytime', |
|
114 |
'value' => '151' |
|
115 |
} |
|
116 |
], |
|
117 |
'name' => "Wassermelone M 11 (Blacktail Mountain) - P\x{e4}ckchen mit 12 Samen", |
|
118 |
'parent_name' => 'Wassermelone M 11 (Blacktail Mountain)', |
|
119 |
'price' => '2.95', |
|
120 |
'product_id' => 4930, |
|
121 |
'quantity' => 1, |
|
122 |
'sku' => 'SW10002', |
|
123 |
'subtotal' => '2.95', |
|
124 |
'subtotal_tax' => '0.21', |
|
125 |
'tax_class' => 'reduced-rate', |
|
126 |
'taxes' => [ |
|
127 |
{ |
|
128 |
'id' => 255, |
|
129 |
'subtotal' => '0.2065', |
|
130 |
'total' => '0.2065' |
|
131 |
} |
|
132 |
], |
|
133 |
'total' => '2.95', |
|
134 |
'total_tax' => '0.21', |
|
135 |
'variation_id' => 4931 |
|
136 |
} |
|
137 |
], |
|
138 |
'meta_data' => [ |
|
139 |
{ |
|
140 |
'id' => 339538, |
|
141 |
'key' => '_billing_fax', |
|
142 |
'value' => '' |
|
143 |
}, |
|
144 |
{ |
|
145 |
'id' => 339539, |
|
146 |
'key' => '_shipping_fax', |
|
147 |
'value' => '' |
|
148 |
}, |
|
149 |
{ |
|
150 |
'id' => 339540, |
|
151 |
'key' => 'is_vat_exempt', |
|
152 |
'value' => 'no' |
|
153 |
}, |
|
154 |
{ |
|
155 |
'id' => 339541, |
|
156 |
'key' => 'wpml_language', |
|
157 |
'value' => 'de' |
|
158 |
} |
|
159 |
], |
|
160 |
'number' => '8163', |
|
161 |
'order_key' => 'wc_order_HjusTgQrJZHFQ', |
|
162 |
'parent_id' => 0, |
|
163 |
'payment_method' => 'german_market_purchase_on_account', |
|
164 |
'payment_method_title' => 'Kauf auf Rechnung', |
|
165 |
'prices_include_tax' => '0', |
|
166 |
'refunds' => [], |
|
167 |
'shipping' => { |
|
168 |
'address_1' => 'Hauptstrasse 52a', |
|
169 |
'address_2' => '', |
|
170 |
'city' => 'Halle', |
|
171 |
'company' => '', |
|
172 |
'country' => 'DE', |
|
173 |
'first_name' => 'Heike', |
|
174 |
'last_name' => 'Mustermann', |
|
175 |
'postcode' => '06118', |
|
176 |
'state' => '' |
|
177 |
}, |
|
178 |
'shipping_lines' => [ |
|
179 |
{ |
|
180 |
'id' => 33595, |
|
181 |
'instance_id' => '1', |
|
182 |
'meta_data' => [ |
|
183 |
{ |
|
184 |
'display_key' => 'Positionen', |
|
185 |
'display_value' => "Wassermelone M 11 (Blacktail Mountain) - P\x{e4}ckchen mit 12 Samen × 1", |
|
186 |
'id' => 323249, |
|
187 |
'key' => 'Positionen', |
|
188 |
'value' => "Wassermelone M 11 (Blacktail Mountain) - P\x{e4}ckchen mit 12 Samen × 1" |
|
189 |
} |
|
190 |
], |
|
191 |
'method_id' => 'flat_rate', |
|
192 |
'method_title' => 'Versandkostenpauschale', |
|
193 |
'taxes' => [ |
|
194 |
{ |
|
195 |
'id' => 255, |
|
196 |
'subtotal' => '', |
|
197 |
'total' => '0.16' |
|
198 |
} |
|
199 |
], |
|
200 |
'total' => '2.34', |
|
201 |
'total_tax' => '0.16' |
|
202 |
} |
|
203 |
], |
|
204 |
'shipping_tax' => '0.16', |
|
205 |
'shipping_total' => '2.34', |
|
206 |
'status' => 'completed', |
|
207 |
'tax_lines' => [ |
|
208 |
{ |
|
209 |
'compound' => '0', |
|
210 |
'id' => 33596, |
|
211 |
'label' => 'MwSt.', |
|
212 |
'meta_data' => [], |
|
213 |
'rate_code' => 'DE-MWST.-2', |
|
214 |
'rate_id' => 255, |
|
215 |
'rate_percent' => 7, |
|
216 |
'shipping_tax_total' => '0.16', |
|
217 |
'tax_total' => '0.21' |
|
218 |
} |
|
219 |
], |
|
220 |
'total' => '5.66', |
|
221 |
'total_tax' => '0.37', |
|
222 |
'transaction_id' => '', |
|
223 |
'version' => '4.9.2' |
|
224 |
); |
|
225 |
return \%data; |
|
226 |
} |
|
227 |
|
|
228 |
sub test_import { |
|
229 |
|
|
230 |
my $import = get_data(); |
|
231 |
note('testing shoporder mapping json good'); |
|
232 |
$shop_order = $shopware->connector->import_data_to_shop_order($import); |
|
233 |
is($shop_order->shop_id , $shop->id , "shop_id ok"); |
|
234 |
} |
|
235 |
|
|
236 |
Support::TestSetup::login(); |
|
237 |
|
|
238 |
reset_state(); |
|
239 |
|
|
240 |
test_import(); |
|
241 |
|
|
242 |
done_testing; |
|
243 |
|
|
244 |
clear_up(); |
|
245 |
|
|
246 |
1; |
|
247 |
|
|
248 |
sub clear_up { |
|
249 |
"SL::DB::Manager::${_}"->delete_all(all => 1) for qw(OrderItem Order); |
|
250 |
"SL::DB::Manager::${_}"->delete_all(all => 1) for qw(ShopPart Part ShopOrderItem ShopOrder Shop Customer); |
|
251 |
} |
Auch abrufbar als: Unified diff
Shop: Woocommerce Test