Revision 2f5ea2de
Von Tamino vor mehr als 3 Jahren hinzugefügt
SL/Controller/ShopPart.pm | ||
---|---|---|
86 | 86 |
->render(); |
87 | 87 |
} |
88 | 88 |
|
89 |
sub action_get_shop_parts { |
|
90 |
my ( $self ) = @_; |
|
91 |
$main::lxdebug->dump(0, "TST: ShopPart get_shop_parts form", $::form); |
|
92 |
my $parts_fetched; |
|
93 |
my $new_parts; |
|
94 |
|
|
95 |
my $type = $::form->{type}; |
|
96 |
if ( $type eq "get_one" ) { |
|
97 |
my $shop_id = $::form->{shop_id}; |
|
98 |
my $part_number = $::form->{part_number}; |
|
99 |
|
|
100 |
if ( $shop_id && $part_number ) { |
|
101 |
my $shop_config = SL::DB::Manager::Shop->get_first(query => [ id => $shop_id, obsolete => 0 ]); |
|
102 |
my $shop = SL::Shop->new( config => $shop_config ); |
|
103 |
unless ( SL::DB::Manager::Part->get_all_count( query => [ partnumber => $part_number ] )) { |
|
104 |
$new_parts = $shop->connector->get_shop_parts($part_number); |
|
105 |
push @{ $parts_fetched }, $new_parts ; |
|
106 |
} else { |
|
107 |
flash_later('error', t8('From shop "#1" : Number: #2 #3 ', $shop->config->description, $part_number, t8('Partnumber is already exist'))); |
|
108 |
} |
|
109 |
} else { |
|
110 |
flash_later('error', t8('Shop or partnumber not selected.')); |
|
111 |
} |
|
112 |
} elsif ( $type eq "get_new" ) { |
|
113 |
my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]); |
|
114 |
foreach my $shop_config ( @{ $active_shops } ) { |
|
115 |
my $shop = SL::Shop->new( config => $shop_config ); |
|
116 |
|
|
117 |
$new_parts = $shop->connector->get_shop_parts; |
|
118 |
push @{ $parts_fetched }, $new_parts ; |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
foreach my $shop_fetched(@{ $parts_fetched }) { |
|
123 |
if($shop_fetched->{error}){ |
|
124 |
flash_later('error', t8('From shop "#1" : #2 ', $shop_fetched->{shop_description}, $shop_fetched->{message},)); |
|
125 |
}else{ |
|
126 |
flash_later('info', t8('From shop #1 : #2 parts have been imported.', $shop_fetched->{description}, $shop_fetched->{number_of_parts},)); |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
$self->redirect_to(controller => "ShopPart", action => 'list_articles'); |
|
131 |
} |
|
132 |
|
|
89 | 133 |
sub action_get_categories { |
90 | 134 |
my ($self) = @_; |
91 | 135 |
|
... | ... | |
135 | 179 |
my $shop = SL::Shop->new( config => $self->shop_part->shop ); |
136 | 180 |
|
137 | 181 |
if($self->shop_part->last_update) { |
138 |
my $shop_article = $shop->connector->get_article($self->shop_part->part->partnumber); |
|
182 |
my $shop_article = $shop->connector->get_article_info($self->shop_part->part->partnumber);
|
|
139 | 183 |
$stock_onlineshop = $shop_article->{data}->{mainDetail}->{inStock}; |
140 | 184 |
$active_online = $shop_article->{data}->{active}; |
141 | 185 |
} |
... | ... | |
156 | 200 |
my $shop_part = SL::DB::Manager::ShopPart->get_all( where => [id => $part], with_objects => ['part', 'shop'])->[0]; |
157 | 201 |
require SL::DB::Shop; |
158 | 202 |
my $shop = SL::Shop->new( config => $shop_part->shop ); |
159 |
my $online_article = $shop->connector->get_article($shop_part->part->partnumber); |
|
203 |
my $online_article = $shop->connector->get_article_info($shop_part->part->partnumber);
|
|
160 | 204 |
my $online_cat = $online_article->{data}->{categories}; |
161 | 205 |
my @cat = (); |
162 | 206 |
for(keys %$online_cat){ |
... | ... | |
224 | 268 |
$article->{images} = $images; |
225 | 269 |
} |
226 | 270 |
|
271 |
$self->_setup_list_action_bar; |
|
272 |
|
|
227 | 273 |
$self->render('shop_part/_list_articles', title => t8('Webshops articles'), SHOP_PARTS => $articles); |
228 | 274 |
} |
229 | 275 |
|
... | ... | |
355 | 401 |
return($price,$price_src_str); |
356 | 402 |
} |
357 | 403 |
|
404 |
sub _setup_list_action_bar { |
|
405 |
my ($self) = @_; |
|
406 |
|
|
407 |
for my $bar ($::request->layout->get('actionbar')) { |
|
408 |
$bar->add( |
|
409 |
action => [ |
|
410 |
t8('Search'), |
|
411 |
submit => [ '#shop_part_filter', { action => "ShopPart/list_articles" } ], |
|
412 |
], |
|
413 |
action => [ |
|
414 |
t8('Get one part'), |
|
415 |
call => [ 'kivi.ShopPart.get_shop_parts_one_setup' ], |
|
416 |
tooltip => t8('Get one part by partnumber'), |
|
417 |
], |
|
418 |
action => [ |
|
419 |
t8('Get new parts'), |
|
420 |
call => [ 'kivi.ShopPart.get_shop_parts_new' ], |
|
421 |
tooltip => t8('Get all new parts'), |
|
422 |
], |
|
423 |
); |
|
424 |
} |
|
425 |
} |
|
426 |
|
|
358 | 427 |
sub check_auth { |
359 | 428 |
$::auth->assert('shop_part_edit'); |
360 | 429 |
} |
SL/ShopConnector/Shopware.pm | ||
---|---|---|
416 | 416 |
return $upload_content->{success}; |
417 | 417 |
} |
418 | 418 |
|
419 |
sub get_article {
|
|
419 |
sub get_parts_info {
|
|
420 | 420 |
my ($self,$partnumber) = @_; |
421 | 421 |
|
422 | 422 |
my $url = $self->url; |
SL/ShopConnector/WooCommerce.pm | ||
---|---|---|
34 | 34 |
$dbh->with_transaction( sub{ |
35 | 35 |
#update status on server |
36 | 36 |
$shoporder->{status} = "processing"; |
37 |
my $anser = $self->set_orderstatus($$shoporder->{id}, "fetched");
|
|
37 |
my $answer = $self->set_orderstatus($shoporder->{id}, "fetched");
|
|
38 | 38 |
unless($answer){ |
39 | 39 |
push @errors,($::locale->text('Saving failed. Error message from the server: #1', $answer->message)); |
40 | 40 |
return 0; |
... | ... | |
151 | 151 |
shop_order_id => $id, |
152 | 152 |
active_price_source => $active_price_source, |
153 | 153 |
); |
154 |
#$main::lxdebug->dump(0, "TST: WooCommerce save pos", $pos); |
|
155 |
#$main::lxdebug->dump(0, "TST: WooCommerce save pos_columns", \%pos_columns); |
|
154 | 156 |
my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns); |
155 | 157 |
$pos_insert->save; |
156 | 158 |
$position++; |
... | ... | |
314 | 316 |
#}; |
315 | 317 |
|
316 | 318 |
my @categories = (); |
317 |
foreach my $row_cat ( @{ $shop_part->shop_category } ) { |
|
318 |
my $temp = { ( id => @{$row_cat}[0], ) }; |
|
319 |
push ( @categories, $temp ); |
|
319 |
if ($shop_part->shop_category) { |
|
320 |
foreach my $row_cat ( @{ $shop_part->shop_category } ) { |
|
321 |
my $temp = { ( id => @{$row_cat}[0], ) }; |
|
322 |
push ( @categories, $temp ); |
|
323 |
} |
|
320 | 324 |
} |
321 | 325 |
|
322 | 326 |
#my @upload_img = $shop_part->get_images; |
323 |
my $partnumber = $::form->escape($part->partnumber);#don't accept / in articlenumber
|
|
327 |
my $partnumber = $::form->escape($part->partnumber);#don't accept / in partnumber
|
|
324 | 328 |
my $stock_status = ($part->onhand ? "instock" : "outofstock"); |
325 | 329 |
my $status = ($shop_part->active ? "publish" : "private"); |
326 | 330 |
my $tax_n_price = $shop_part->get_tax_and_price; |
... | ... | |
379 | 383 |
|
380 | 384 |
# don't know if this is needed |
381 | 385 |
#if(@upload_img) { |
382 |
# my $partnumber = $::form->escape($part->partnumber);#shopware don't accept / in articlenumber
|
|
383 |
# my $imgup = $self->connector->put($url . "api/generatearticleimages/$partnumber?useNumberAsId=true");
|
|
386 |
# my $partnumber = $::form->escape($part->partnumber);#shopware don't accept / in partnumber
|
|
387 |
# my $imgup = $self->connector->put($url . "api/generatepartimages/$partnumber?useNumberAsId=true");
|
|
384 | 388 |
#} |
385 | 389 |
|
386 | 390 |
return $answer->{success}; |
387 | 391 |
} |
388 | 392 |
|
389 |
sub get_article { |
|
393 |
sub get_article_info {
|
|
390 | 394 |
my ($self) = @_; |
391 | 395 |
my $partnumber = $_[1]; |
392 | 396 |
|
393 | 397 |
$partnumber = $::form->escape($partnumber);#don't accept / in partnumber |
394 | 398 |
my $answer = $self->send_request("products/", undef , "get" , "&sku=$partnumber"); |
395 | 399 |
|
400 |
$answer->{data} = $answer->{data}[0]; |
|
401 |
#$main::lxdebug->dump(0, "TST: WooCommerce get_part_info ", $answer); |
|
402 |
return $answer; |
|
403 |
|
|
396 | 404 |
if($answer->{success} && scalar @{$answer->{data}}){ |
397 |
my $article = $answer->{data}[0]; |
|
398 |
return $article; |
|
405 |
my $part = $self->map_data_to_part($answer->{data}[0]); |
|
406 |
#$main::lxdebug->dump(0, "TST: WooCommerce get_part_info part", $part); |
|
407 |
return $part; |
|
399 | 408 |
} else { |
400 | 409 |
#What shut be here? |
401 | 410 |
return $answer |
402 | 411 |
} |
403 | 412 |
} |
404 | 413 |
|
414 |
sub map_data_to_part { |
|
415 |
my ($self, $part_data) = @_; |
|
416 |
|
|
417 |
my %map_part_data = ( |
|
418 |
#id => $part_data->{}, |
|
419 |
partnumber => $part_data->{sku}, |
|
420 |
description => $part_data->{name}, |
|
421 |
#listprice => $part_data->{}, |
|
422 |
#sellprice => $part_data->{}, |
|
423 |
#lastcost => $part_data->{}, |
|
424 |
#priceupdate => $part_data->{}, |
|
425 |
#weight => $part_data->{}, |
|
426 |
notes => $part_data->{description}, |
|
427 |
#makemodel => $part_data->{}, |
|
428 |
#rop => $part_data->{}, |
|
429 |
shop => 1, |
|
430 |
obsolete => 0, |
|
431 |
#bom => $part_data->{}, |
|
432 |
#image => $part_data->{}, |
|
433 |
#drawing => $part_data->{}, |
|
434 |
#microfiche => $part_data->{}, |
|
435 |
#partsgroup_id => $part_data->{}, |
|
436 |
#ve => $part_data->{}, |
|
437 |
#gv => $part_data->{}, |
|
438 |
#itime => $part_data->{}, |
|
439 |
#mtime => $part_data->{}, |
|
440 |
#unit => $part_data->{}, |
|
441 |
unit => 'Stck', |
|
442 |
#formel => $part_data->{}, |
|
443 |
#not_discountable => $part_data->{}, |
|
444 |
#buchungsgruppen_id => $part_data->{}, |
|
445 |
#payment_id => $part_data->{}, |
|
446 |
#ean => $part_data->{}, |
|
447 |
#price_factor_id => $part_data->{}, |
|
448 |
#onhand => $part_data->{}, |
|
449 |
#stockable => $part_data->{}, |
|
450 |
#has_sernumber => $part_data->{}, |
|
451 |
#warehouse_id => $part_data->{}, |
|
452 |
#bin_id => $part_data->{}, |
|
453 |
#df_status_aktuell => $part_data->{}, |
|
454 |
#df_status_verlauf => $part_data->{}, |
|
455 |
#active => $part_data->{}, |
|
456 |
#classification_id => $part_data->{}, |
|
457 |
part_type => 'part', |
|
458 |
); |
|
459 |
return SL::DB::Part->new(%map_part_data); |
|
460 |
} |
|
461 |
|
|
462 |
sub map_data_to_shop_part { |
|
463 |
my ($self, $part_data, $part) = @_; |
|
464 |
|
|
465 |
my @categories = (); |
|
466 |
foreach my $row_cat ( @{ $part_data->{categories} } ) { |
|
467 |
my @tmp; |
|
468 |
push( @tmp,$row_cat->{id} ); |
|
469 |
push( @tmp,$row_cat->{name} ); |
|
470 |
push( @categories,\@tmp ); |
|
471 |
} |
|
472 |
my %map_shop_part_data = ( |
|
473 |
#id => , |
|
474 |
shop_id => $self->config->id, |
|
475 |
part_id => $part->id, |
|
476 |
shop_description => $part_data->{description}, |
|
477 |
#itime => , |
|
478 |
#mtime => , |
|
479 |
#last_update => , |
|
480 |
#show_date => , |
|
481 |
sortorder => $part_data->{menu_order}, |
|
482 |
#front_page => , |
|
483 |
active => 1, |
|
484 |
shop_category => \@categories, |
|
485 |
#active_price_source => , |
|
486 |
#metatag_keywords => , |
|
487 |
#metatag_description => , |
|
488 |
#metatag_title => , |
|
489 |
#shop_versandhinweis => , |
|
490 |
); |
|
491 |
return SL::DB::ShopPart->new(%map_shop_part_data); |
|
492 |
} |
|
493 |
sub get_shop_parts { |
|
494 |
my ($self, $partnumber) = @_; |
|
495 |
|
|
496 |
my $dbh = SL::DB::client; |
|
497 |
my @errors; |
|
498 |
my $number_of_parts = 0; |
|
499 |
my %fetched_parts; |
|
500 |
my $answer; |
|
501 |
|
|
502 |
if ($partnumber) { |
|
503 |
$partnumber = $::form->escape($partnumber);#don't accept / in partnumber |
|
504 |
$answer = $self->send_request("products/", undef , "get" , "&sku=$partnumber"); |
|
505 |
} else { |
|
506 |
#TODO |
|
507 |
$answer = $self->send_request("products/", undef , "get"); |
|
508 |
if ($answer->{total_pages} > 1) { |
|
509 |
my $current_page = 2; |
|
510 |
while ($current_page <= $answer->{total_pages}) { |
|
511 |
my $tmp_answer = $self->send_request("products/", undef , "get", "&page=$current_page"); |
|
512 |
foreach my $part (@{$tmp_answer->{data}}) { |
|
513 |
push @{$answer->{data}} , $part; |
|
514 |
} |
|
515 |
$current_page++; |
|
516 |
} |
|
517 |
} |
|
518 |
} |
|
519 |
|
|
520 |
if($answer->{success} && scalar @{$answer->{data}}){ |
|
521 |
$dbh->with_transaction( sub{ |
|
522 |
foreach my $part_data (@{$answer->{data}}) { |
|
523 |
unless (!$part_data->{sku} || SL::DB::Manager::Part->get_all_count( query => [ partnumber => $part_data->{sku} ] )) { |
|
524 |
my $part = $self->map_data_to_part($part_data); |
|
525 |
#$main::lxdebug->dump(0, "TST: WooCommerce get_shop_parts part ", $part); |
|
526 |
$part->save; |
|
527 |
my $shop_part = $self->map_data_to_shop_part($part_data, $part); |
|
528 |
#$main::lxdebug->dump(0, "TST: WooCommerce get_shop_parts shop_part ", $shop_part); |
|
529 |
$shop_part->save; |
|
530 |
$number_of_parts++; |
|
531 |
} |
|
532 |
} |
|
533 |
return 1; |
|
534 |
})or do { |
|
535 |
push @errors,($::locale->text('Saving failed. Error message from the database: #1', $dbh->error)); |
|
536 |
}; |
|
537 |
|
|
538 |
if(@errors){ |
|
539 |
flash_later('error', $::locale->text('Errors: #1', @errors)); |
|
540 |
} |
|
541 |
%fetched_parts = ( |
|
542 |
shop_id => $self->config->id, |
|
543 |
shop_description => $self->config->description, |
|
544 |
number_of_parts => $number_of_parts, |
|
545 |
); |
|
546 |
} else { |
|
547 |
my %error_msg = ( |
|
548 |
shop_id => $self->config->id, |
|
549 |
shop_description => $self->config->description, |
|
550 |
message => $answer->{message}, |
|
551 |
error => 1, |
|
552 |
); |
|
553 |
%fetched_parts = %error_msg; |
|
554 |
} |
|
555 |
return \%fetched_parts; |
|
556 |
} |
|
557 |
|
|
405 | 558 |
sub get_categories { |
406 | 559 |
my ($self) = @_; |
407 | 560 |
|
... | ... | |
495 | 648 |
my %return; |
496 | 649 |
if($answer->is_success && $type eq 'application/json'){ |
497 | 650 |
my $data_json = $answer->content; |
651 |
#$main::lxdebug->dump(0, "TST: WooCommerce send_request header ", $answer->header( 'Link')); |
|
498 | 652 |
my $json = SL::JSON::decode_json($data_json); |
499 | 653 |
%return = ( |
500 | 654 |
success => 1, |
501 | 655 |
data => $json, |
656 |
total_pages => $answer->header( 'X-WP-TotalPages'), |
|
657 |
total_elements => $answer->header( 'X-WP-Total'), |
|
502 | 658 |
); |
503 | 659 |
}else{ |
504 | 660 |
%return = ( |
js/kivi.ShopPart.js | ||
---|---|---|
140 | 140 |
id: 'files_upload', |
141 | 141 |
dialog: { title: kivi.t8('File upload'), width: 650, height: 240 } }); |
142 | 142 |
return true; |
143 |
} |
|
143 |
}; |
|
144 |
|
|
145 |
ns.get_shop_parts_one = function() { |
|
146 |
|
|
147 |
var data = $('#get_one_shop_part_form').serializeArray(); |
|
148 |
data.push({ name: 'type', value: 'get_one'}); |
|
149 |
data.push({ name: 'action', value: 'ShopPart/get_shop_parts' }); |
|
150 |
|
|
151 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
152 |
}; |
|
153 |
|
|
154 |
ns.get_shop_parts_new = function() { |
|
155 |
$.post("controller.pl", { action: 'ShopPart/get_shop_parts', type: 'get_new'}, kivi.eval_json_result); |
|
156 |
}; |
|
144 | 157 |
|
158 |
ns.get_shop_order_one_initialize = function() { |
|
159 |
kivi.popup_dialog({ |
|
160 |
id: 'get_one', |
|
161 |
dialog: { |
|
162 |
title: kivi.t8('Get one shoppart'), |
|
163 |
} |
|
164 |
}); |
|
165 |
}; |
|
166 |
|
|
167 |
ns.get_shop_parts_one_setup = function() { |
|
168 |
kivi.ShopPart.get_shop_order_one_initialize(); |
|
169 |
//kivi.submit_ajax_form('controller.pl?action=ShopOrder/get_orders', $('#shoporder')); |
|
170 |
}; |
|
145 | 171 |
|
146 | 172 |
ns.setup = function() { |
147 | 173 |
kivi.ShopPart.massUploadInitialize(); |
templates/webpages/shop_part/_filter.html | ||
---|---|---|
21 | 21 |
</p> |
22 | 22 |
<p> |
23 | 23 |
[% L.hidden_tag('action', 'ShopPart/dispatch') %] |
24 |
[% L.submit_tag('action_list_articles',LxERP.t8('renew')) %] |
|
25 | 24 |
</p> |
26 | 25 |
</form> |
templates/webpages/shop_part/_get_one.html | ||
---|---|---|
1 |
[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%] |
|
2 |
[% USE Dumper %] |
|
3 |
[% L.stylesheet_tag('webshop') %] |
|
4 |
[%- INCLUDE 'common/flash.html' %] |
|
5 |
<form id="get_one_shop_part_form" action="controller.pl" method="post" style="padding-left:1em;"> |
|
6 |
<table> |
|
7 |
<tr> |
|
8 |
<th align="right">[% 'Shop' | $T8 %]</th> |
|
9 |
<td>[% L.select_tag('shop_id', SELF.shops, value_key = 'value', title_key = 'title', default=1) %]</td> |
|
10 |
</tr> |
|
11 |
<tr> |
|
12 |
<th align="right">[% 'Shop partnumber' | $T8 %]</th> |
|
13 |
<td>[% L.input_tag('part_number', "") %]</td> |
|
14 |
</tr> |
|
15 |
</table> |
|
16 |
[% L.button_tag("kivi.ShopPart.get_shop_parts_one()", LxERP.t8('Import part')) %] |
|
17 |
</form> |
templates/webpages/shop_part/_list_articles.html | ||
---|---|---|
1 | 1 |
[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%] |
2 | 2 |
|
3 |
[%- INCLUDE 'common/flash.html' %] |
|
3 | 4 |
<h1>[% title %]</h1> |
4 | 5 |
[%- PROCESS 'shop_part/_filter.html' filter=SELF.models.filtered.laundered %] |
5 | 6 |
<hr> |
... | ... | |
123 | 124 |
[%- INCLUDE 'shop_part/_upload_status.html' %] |
124 | 125 |
</div> |
125 | 126 |
</form> |
127 |
<div id="get_one" style="display:none;"> |
|
128 |
[% INCLUDE 'shop_part/_get_one.html' %] |
|
129 |
</div> |
|
126 | 130 |
<hr> |
127 | 131 |
<script type="text/javascript"> |
128 | 132 |
<!-- |
Auch abrufbar als: Unified diff
ShopConnector get_part in WooCommerce implemented