Revision b9aaed24
Von Werner Hahn vor mehr als 3 Jahren hinzugefügt
SL/ShopConnector/WooCommerce.pm | ||
---|---|---|
130 | 130 |
my @positions = sort { Sort::Naturally::ncmp($a->{"sku"}, $b->{"sku"}) } @{ $import->{line_items} }; |
131 | 131 |
my $position = 1; |
132 | 132 |
|
133 |
my $answer= $self->send_request("taxes"); |
|
134 |
unless ($answer->{success}){ return 0;} |
|
135 |
my %taxes = map { ($_->{id} => $_) } @{ $answer->{data} }; |
|
136 |
|
|
137 | 133 |
my $active_price_source = $self->config->price_source; |
134 |
my $tax_included = $self->config->pricetype eq 'brutto' ? 1 : 0; |
|
138 | 135 |
#Mapping Positions |
139 | 136 |
foreach my $pos(@positions) { |
140 |
my $price = $::form->round_amount($pos->{total},2); |
|
141 |
my $tax_id = $pos->{taxes}[0]->{id}; |
|
142 |
my $tax_rate = $taxes{ $tax_id }{rate}; |
|
137 |
my $tax_rate = $pos->{tax_class} eq "reduced-rate" ? 7 : 19; |
|
138 |
my $tax_factor = $tax_rate/100+1; |
|
139 |
my $price = $pos->{price}; |
|
140 |
if ( $tax_included ) { |
|
141 |
$price = $price * $tax_factor; |
|
142 |
$price = $::form->round_amount($price,2); |
|
143 |
} else { |
|
144 |
$price = $::form->round_amount($price,2); |
|
145 |
} |
|
143 | 146 |
my %pos_columns = ( description => $pos->{name}, |
144 | 147 |
partnumber => $pos->{sku}, # sku has to be a valid value in WooCommerce |
145 | 148 |
price => $price, |
... | ... | |
158 | 161 |
} |
159 | 162 |
$shop_order->positions($position-1); |
160 | 163 |
|
164 |
if ( $self->config->shipping_costs_parts_id ) { |
|
165 |
my $shipping_part = SL::DB::Part->find_by( id => $self->config->shipping_costs_parts_id); |
|
166 |
my %shipping_pos = ( |
|
167 |
description => $import->{data}->{dispatch}->{name}, |
|
168 |
partnumber => $shipping_part->partnumber, |
|
169 |
price => $import->{data}->{invoiceShipping}, |
|
170 |
quantity => 1, |
|
171 |
position => $position, |
|
172 |
shop_trans_id => 0, |
|
173 |
shop_order_id => $id, |
|
174 |
); |
|
175 |
my $shipping_pos_insert = SL::DB::ShopOrderItem->new(%shipping_pos); |
|
176 |
$shipping_pos_insert->save; |
|
177 |
} |
|
178 |
|
|
161 | 179 |
my $customer = $shop_order->get_customer; |
162 | 180 |
|
163 | 181 |
if(ref($customer)){ |
... | ... | |
176 | 194 |
); |
177 | 195 |
|
178 | 196 |
my $shop_id = $self->config->id; |
197 |
my $tax_included = $self->config->pricetype; |
|
179 | 198 |
|
180 | 199 |
# Mapping to table shoporders. See https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#order-properties |
181 | 200 |
my $d_street; |
... | ... | |
185 | 204 |
$d_street = $import->{billing}->{address_1} . ($import->{billing}->{address_2} ? " " . $import->{billing}->{address_2} : ""); |
186 | 205 |
} |
187 | 206 |
my %columns = ( |
188 |
#billing |
|
207 |
#billing Shop can have different billing addresses, and may have 1 customer_address
|
|
189 | 208 |
billing_firstname => $import->{billing}->{first_name}, |
190 | 209 |
billing_lastname => $import->{billing}->{last_name}, |
191 | 210 |
#address_1 address_2 |
... | ... | |
271 | 290 |
#total_tax |
272 | 291 |
netamount => $import->{total} - $import->{total_tax}, |
273 | 292 |
#prices_include_tax |
274 |
tax_included => $import->{prices_include_tax} eq "true" ? 1 : 0,
|
|
293 |
tax_included => $tax_included,
|
|
275 | 294 |
#payment_method |
276 | 295 |
# ??? payment_id => $import->{payment_method}, |
277 | 296 |
#payment_method_title |
Auch abrufbar als: Unified diff
WooCommerce: Lieferkosten als Position anfügen