Revision 8f9ed9ed
Von Werner Hahn vor mehr als 7 Jahren hinzugefügt
SL/ShopConnector/Shopware.pm | ||
---|---|---|
6 | 6 |
|
7 | 7 |
use parent qw(SL::ShopConnector::Base); |
8 | 8 |
|
9 |
use SL::DBUtils; |
|
9 | 10 |
use SL::JSON; |
10 | 11 |
use LWP::UserAgent; |
11 | 12 |
use LWP::Authen::Digest; |
... | ... | |
15 | 16 |
use Sort::Naturally (); |
16 | 17 |
use SL::Helper::Flash; |
17 | 18 |
use Encode qw(encode_utf8); |
18 |
use SL::Controller::ShopPart; |
|
19 | 19 |
|
20 | 20 |
use Rose::Object::MakeMethods::Generic ( |
21 | 21 |
'scalar --get_set_init' => [ qw(connector url) ], |
... | ... | |
31 | 31 |
|
32 | 32 |
my $i; |
33 | 33 |
for ($i=1;$i<=$otf;$i++) { |
34 |
|
|
34 | 35 |
my $data = $self->connector->get("http://$url/api/orders/$ordnumber?useNumberAsId=true"); |
35 | 36 |
my $data_json = $data->content; |
36 | 37 |
my $import = SL::JSON::decode_json($data_json); |
... | ... | |
97 | 98 |
shop_customer_number => $import->{data}->{billing}->{number}, |
98 | 99 |
shop_customer_comment => $import->{data}->{customerComment}, |
99 | 100 |
shop_data => "", |
100 |
shop_id => $import->{data}->{id},
|
|
101 |
shop_id => $self->config->id,
|
|
101 | 102 |
shop_ordernumber => $import->{data}->{number}, |
102 | 103 |
shop_trans_id => $import->{data}->{id}, |
103 | 104 |
tax_included => ($import->{data}->{net} == 0 ? 0 : 1) |
104 | 105 |
); |
105 |
my $insert = SL::DB::ShopOrder->new(%columns); |
|
106 |
$insert->save; |
|
107 |
my $id = $insert->id; |
|
106 |
my $shop_order = SL::DB::ShopOrder->new(%columns); |
|
107 |
|
|
108 |
$shop_order->save; |
|
109 |
my $id = $shop_order->id; |
|
108 | 110 |
|
109 | 111 |
my @positions = sort { Sort::Naturally::ncmp($a->{"partnumber"}, $b->{"partnumber"}) } @{ $import->{data}->{details} }; |
110 | 112 |
my $position = 1; |
111 | 113 |
foreach my $pos(@positions) { |
114 |
my $price = $::form->round_amount($pos->{price},2); |
|
115 |
|
|
112 | 116 |
my %pos_columns = ( description => $pos->{articleName}, |
113 | 117 |
partnumber => $pos->{articleNumber}, |
114 |
price => $pos->{price},
|
|
118 |
price => $price,
|
|
115 | 119 |
quantity => $pos->{quantity}, |
116 | 120 |
position => $position, |
117 | 121 |
tax_rate => $pos->{taxRate}, |
... | ... | |
122 | 126 |
$pos_insert->save; |
123 | 127 |
$position++; |
124 | 128 |
} |
125 |
# Versandkosten als Position am ende einfügen Dreschflegelspezifisch event. konfigurierbar machen |
|
129 |
$shop_order->{positions} = $position; |
|
130 |
|
|
131 |
# Only Customers which are not found will be applied |
|
132 |
my $proposals = SL::DB::Manager::Customer->get_all_count( |
|
133 |
where => [ |
|
134 |
or => [ |
|
135 |
and => [ # when matching names also match zipcode |
|
136 |
or => [ 'name' => { like => "$shop_order->billing_lastname"}, |
|
137 |
'name' => { like => $shop_order->billing_company }, |
|
138 |
], |
|
139 |
'zipcode' => { like => $shop_order->billing_zipcode }, |
|
140 |
], |
|
141 |
or => [ 'email' => { like => $shop_order->billing_email } ], |
|
142 |
and => [ 'street' => { like => $shop_order->billing_street }, |
|
143 |
'zipcode' => { like => $shop_order->billing_zipcode } ], |
|
144 |
], |
|
145 |
], |
|
146 |
); |
|
126 | 147 |
|
148 |
if(!$proposals){ |
|
149 |
my %address = ( 'name' => $shop_order->billing_firstname . " " . $shop_order->billing_lastname, |
|
150 |
'department_1' => $shop_order->billing_company, |
|
151 |
'department_2' => $shop_order->billing_department, |
|
152 |
'street' => $shop_order->billing_street, |
|
153 |
'zipcode' => $shop_order->billing_zipcode, |
|
154 |
'city' => $shop_order->billing_city, |
|
155 |
'email' => $shop_order->billing_email, |
|
156 |
'country' => $shop_order->billing_country, |
|
157 |
'greeting' => $shop_order->billing_greeting, |
|
158 |
'fax' => $shop_order->billing_fax, |
|
159 |
'phone' => $shop_order->billing_phone, |
|
160 |
'ustid' => $shop_order->billing_vat, |
|
161 |
'taxincluded_checked' => 1, # TODO hardcoded |
|
162 |
'taxincluded' => 1, # TODO hardcoded |
|
163 |
'klass' => 908, # TODO hardcoded |
|
164 |
'taxzone_id' => 4, # TODO hardcoded, use default taxzone instead |
|
165 |
'currency' => 1, # TODO hardcoded |
|
166 |
'payment_id' => 7345,# TODO hardcoded |
|
167 |
); |
|
168 |
my $customer = SL::DB::Customer->new(%address); |
|
169 |
$customer->save; |
|
170 |
|
|
171 |
} |
|
172 |
my %billing_address = ( 'name' => $shop_order->billing_lastname, |
|
173 |
'company' => $shop_order->billing_company, |
|
174 |
'street' => $shop_order->billing_street, |
|
175 |
'zipcode' => $shop_order->billing_zipcode, |
|
176 |
'city' => $shop_order->billing_city, |
|
177 |
); |
|
178 |
my $b_address = SL::Controller::ShopOrder->check_address(%billing_address); |
|
179 |
if ($b_address) { |
|
180 |
$shop_order->{kivi_customer_id} = $b_address->{id}; |
|
181 |
} |
|
182 |
$shop_order->save; |
|
183 |
|
|
184 |
# DF Versandkosten als Position am ende einfügen Dreschflegelspezifisch event. konfigurierbar machen |
|
127 | 185 |
if (my $shipping = $import->{data}->{dispatch}->{name}) { |
128 | 186 |
my %shipping_partnumbers = ( |
129 | 187 |
'Auslandsversand Einschreiben' => { 'partnumber' => '900650'}, |
130 | 188 |
'Auslandsversand' => { 'partnumber' => '900650'}, |
131 |
'Standard Versand' => { 'partnumber' => '905500'},
|
|
189 |
'Versandpauschale Inland' => { 'partnumber' => '905500'},
|
|
132 | 190 |
'Kostenloser Versand' => { 'partnumber' => '905500'}, |
133 | 191 |
); |
192 |
# TODO description für Preis muss angepasst werden |
|
134 | 193 |
my %shipping_pos = ( description => $import->{data}->{dispatch}->{name}, |
135 | 194 |
partnumber => $shipping_partnumbers{$shipping}->{partnumber}, |
136 | 195 |
price => $import->{data}->{invoiceShipping}, |
... | ... | |
143 | 202 |
my $shipping_pos_insert = SL::DB::ShopOrderItem->new(%shipping_pos); |
144 | 203 |
$shipping_pos_insert->save; |
145 | 204 |
|
205 |
} |
|
146 | 206 |
my $attributes->{last_order_number} = $ordnumber; |
147 | 207 |
$self->config->assign_attributes( %{ $attributes } ); |
148 | 208 |
$self->config->save; |
149 | 209 |
$ordnumber++; |
150 |
} |
|
151 |
}else{ |
|
152 |
last; |
|
210 |
# EOT Versandkosten DF |
|
153 | 211 |
} |
212 |
} |
|
154 | 213 |
my $shop = $self->config->description; |
155 | 214 |
|
156 | 215 |
my @fetched_orders = ($shop,$i); |
157 | 216 |
|
158 | 217 |
return \@fetched_orders; |
159 |
} |
|
160 |
# return $import; |
|
161 | 218 |
}; |
162 | 219 |
|
163 | 220 |
sub get_categories { |
... | ... | |
180 | 237 |
return \@daten; |
181 | 238 |
} |
182 | 239 |
|
183 |
sub get_article { |
|
184 |
} |
|
185 |
|
|
186 | 240 |
sub update_part { |
187 | 241 |
my ($self, $shop_part, $json) = @_; |
188 | 242 |
|
189 | 243 |
#shop_part is passed as a param |
190 | 244 |
die unless ref($shop_part) eq 'SL::DB::ShopPart'; |
191 | 245 |
|
192 |
$main::lxdebug->dump(0, 'WH: UPDATE SHOPPART: ', \$shop_part); |
|
193 |
$main::lxdebug->dump(0, 'WH: UPDATE SELF: ', \$self); |
|
194 |
$main::lxdebug->dump(0, 'WH: UPDATE JSON: ', \$json); |
|
195 | 246 |
my $url = $self->url; |
196 | 247 |
my $part = SL::DB::Part->new(id => $shop_part->{part_id})->load; |
197 | 248 |
|
198 | 249 |
# TODO: Prices (pricerules, pricegroups, multiple prices) |
199 | 250 |
my $cvars = { map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } }; |
200 |
#my $categories = { map { ( name => $_) } @{ $shop_part->{shop_category} } }; |
|
251 |
|
|
201 | 252 |
my @cat = (); |
202 | 253 |
foreach my $row_cat ( @{ $shop_part->shop_category } ) { |
203 |
$main::lxdebug->dump(0, 'WH:ROWCAT ',\$row_cat); |
|
204 |
|
|
205 | 254 |
my $temp = { ( id => @{$row_cat}[0], ) }; |
206 |
$main::lxdebug->dump(0, 'WH: TEMP: ', \$temp); |
|
207 |
|
|
208 | 255 |
push ( @cat, $temp ); |
209 | 256 |
} |
210 | 257 |
|
211 | 258 |
my $images = SL::DB::Manager::File->get_all( where => [ modul => 'shop_part', trans_id => $part->{id} ]); |
212 | 259 |
my @upload_img = (); |
213 | 260 |
foreach my $img (@{ $images }) { |
214 |
$main::lxdebug->dump(0, 'WH: FOR: ', \$img); |
|
215 |
|
|
216 | 261 |
my ($path, $extension) = (split /\./, $img->{filename}); |
217 | 262 |
my $temp ={ ( link => 'data:' . $img->{file_content_type} . ';base64,' . MIME::Base64::encode($img->{file_content},''), |
218 | 263 |
description => $img->{title}, |
219 | 264 |
position => $img->{position}, |
220 | 265 |
extension => $extension, |
221 | 266 |
)} ; |
222 |
push( @images3, $temp);
|
|
267 |
push( @upload_img, $temp);
|
|
223 | 268 |
} |
224 |
$main::lxdebug->dump(0, 'WH: IMAGES 3 ',\@images3); |
|
225 | 269 |
|
226 |
my $data = $self->connector->get("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true"); |
|
227 |
my $data_json = $data->content; |
|
228 |
my $import = SL::JSON::decode_json($data_json); |
|
270 |
my ($import,$data,$data_json); |
|
271 |
if( $shop_part->last_update){ |
|
272 |
my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept "/" in articlenumber |
|
273 |
$data = $self->connector->get("http://$url/api/articles/$partnumber?useNumberAsId=true"); |
|
274 |
$data_json = $data->content; |
|
275 |
$import = SL::JSON::decode_json($data_json); |
|
276 |
} |
|
229 | 277 |
|
230 | 278 |
# get the right price |
231 | 279 |
my ( $price_src_str, $price_src_id ) = split(/\//,$shop_part->active_price_source); |
... | ... | |
238 | 286 |
my $part = SL::DB::Manager::Part->get_all( where => [id => $shop_part->part_id, 'prices.'.pricegroup_id => $price_src_id], with_objects => ['prices'],limit => 1)->[0]; |
239 | 287 |
$price = $part->prices->[0]->price; |
240 | 288 |
} |
289 |
|
|
290 |
# get the right taxrate for the article |
|
291 |
my $taxrate; |
|
292 |
my $dbh = $::form->get_standard_dbh(); |
|
293 |
my $b_id = $part->buchungsgruppen_id; |
|
294 |
my $t_id = $shop_part->shop->taxzone_id; |
|
295 |
|
|
296 |
my $sql_str = "SELECT a.rate AS taxrate from tax a |
|
297 |
WHERE a.taxkey = (SELECT b.taxkey_id |
|
298 |
FROM chart b LEFT JOIN taxzone_charts c ON b.id = c.income_accno_id |
|
299 |
WHERE c.taxzone_id = $t_id |
|
300 |
AND c.buchungsgruppen_id = $b_id)"; |
|
301 |
|
|
302 |
my $rate = selectall_hashref_query($::form, $dbh, $sql_str); |
|
303 |
$taxrate = @$rate[0]->{taxrate}*100; |
|
304 |
|
|
241 | 305 |
# mapping to shopware still missing attributes,metatags |
242 | 306 |
my %shop_data = ( name => $part->{description}, |
243 |
taxId => 4, # TODO Hardcoded kann auch der taxwert sein zB. tax => 19.00
|
|
307 |
tax => $taxrate,
|
|
244 | 308 |
mainDetail => { number => $part->{partnumber}, |
245 | 309 |
inStock => $part->{onhand}, |
246 | 310 |
prices => [ { from => 1, |
... | ... | |
249 | 313 |
}, |
250 | 314 |
], |
251 | 315 |
}, |
252 |
supplier => $cvars->{freifeld_7}->{value}, |
|
253 |
description => $shop_part->{shop_description}, |
|
254 |
active => $shop_part->active, |
|
255 |
images => [ @images3 ], |
|
256 |
__options_images => { replace => 1, }, |
|
257 |
categories => [ @cat ], #{ path => 'Deutsch|test2' }, ], #[ $categories ], |
|
316 |
supplier => $cvars->{freifeld_7}->{value}, |
|
317 |
descriptionLong => $shop_part->{shop_description}, |
|
318 |
active => $shop_part->active, |
|
319 |
images => [ @upload_img ], |
|
320 |
__options_images => { replace => 1, }, |
|
321 |
categories => [ @cat ], |
|
322 |
description => $shop_part->{shop_description}, |
|
323 |
active => $shop_part->active, |
|
324 |
images => [ @upload_img ], |
|
325 |
__options_images => { replace => 1, }, |
|
326 |
categories => [ @cat ], #{ path => 'Deutsch|test2' }, ], #[ $categories ], |
|
258 | 327 |
|
259 | 328 |
) |
260 | 329 |
; |
... | ... | |
263 | 332 |
|
264 | 333 |
my $upload_content; |
265 | 334 |
if($import->{success}){ |
266 |
$main::lxdebug->message(0, "WH: if success: ". $import->{success}); |
|
267 | 335 |
my %del_img = ( images => [ {} ], ) ; |
268 | 336 |
my $del_imgString = SL::JSON::to_json(\%del_img); |
269 | 337 |
#my $delImg = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $del_imgString); |
270 | 338 |
#update |
271 |
my $upload = $self->connector->put("http://$url/api/articles/$part->{partnumber}?useNumberAsId=true",Content => $dataString); |
|
339 |
my $partnumber = $::form->escape($part->{partnumber});#shopware dosn't accept / in articlenumber |
|
340 |
my $upload = $self->connector->put("http://$url/api/articles/$partnumber?useNumberAsId=true",Content => $dataString); |
|
272 | 341 |
my $data_json = $upload->content; |
273 | 342 |
$upload_content = SL::JSON::decode_json($data_json); |
274 | 343 |
}else{ |
275 | 344 |
#upload |
276 |
$main::lxdebug->message(0, "WH: else success: ". $import->{success}); |
|
277 | 345 |
my $upload = $self->connector->post("http://$url/api/articles/",Content => $dataString); |
278 | 346 |
my $data_json = $upload->content; |
279 | 347 |
$upload_content = SL::JSON::decode_json($data_json); |
280 | 348 |
} |
281 | 349 |
if(@upload_img) { |
282 |
$self->connector->put("http://$url/api/generateArticleImages/$part->{partnumber}?useNumberAsId=true"); |
|
350 |
my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber |
|
351 |
$self->connector->put("http://$url/api/generateArticleImages/$partnumber?useNumberAsId=true"); |
|
283 | 352 |
} |
284 | 353 |
return $upload_content->{success}; |
285 | 354 |
} |
... | ... | |
295 | 364 |
|
296 | 365 |
sub init_url { |
297 | 366 |
my ($self) = @_; |
298 |
# TODO: validate url and port |
|
367 |
# TODO: validate url and port Mabey in shopconfig test connection
|
|
299 | 368 |
$self->url($self->config->url . ":" . $self->config->port); |
300 | 369 |
}; |
301 | 370 |
|
... | ... | |
304 | 373 |
my $ua = LWP::UserAgent->new; |
305 | 374 |
$ua->credentials( |
306 | 375 |
$self->url, |
307 |
"Shopware REST-API", |
|
376 |
"Shopware REST-API", # TODO in config
|
|
308 | 377 |
$self->config->login => $self->config->password |
309 | 378 |
); |
310 | 379 |
return $ua; |
Auch abrufbar als: Unified diff
Shopmodul: Connector Shopware
Shopmodul: Debugs rausgenommen
Webshop:: ShopConnector Shopware
Webshop: Connector ShopWare
Conflicts:
SL/ShopConnector/Shopware.pm
Webshop: Connector - Es wird nicht nur eine Bestellung abgeholt
Conflicts:
SL/ShopConnector/Shopware.pm
Webshop: Connector Typo
Conflicts:
SL/ShopConnector/Shopware.pm
Webshop: Connector - Klammer vergessen
Conflicts:
SL/ShopConnector/Shopware.pm
Webshop: Connector
Webshop: Connector - payment_id beim anlegen des Kunden mitaufgenommen
Webshop: Connector
Webshop: Connector - richtige shop_id wird übernommen
Conflicts:
SL/ShopConnector/Shopware.pm
Conflicts:
SL/ShopConnector/Shopware.pm