Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 457e1237

Von Werner Hahn vor mehr als 3 Jahren hinzugefügt

  • ID 457e1237959ddf06c2198e2fba1768adc8053840
  • Vorgänger 84176299
  • Nachfolger ddec2dcd

Revert "ShopConnector get_part in WooCommerce implemented"

This reverts commit 875ae0f6f2ec3de097926910f64d9e6c214e0e82.

Unterschiede anzeigen:

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

  
133 89
sub action_get_categories {
134 90
  my ($self) = @_;
135 91

  
......
179 135
  my $shop = SL::Shop->new( config => $self->shop_part->shop );
180 136

  
181 137
  if($self->shop_part->last_update) {
182
    my $shop_article = $shop->connector->get_article_info($self->shop_part->part->partnumber);
138
    my $shop_article = $shop->connector->get_article($self->shop_part->part->partnumber);
183 139
    $stock_onlineshop = $shop_article->{data}->{mainDetail}->{inStock};
184 140
    $active_online = $shop_article->{data}->{active};
185 141
  }
......
200 156
    my $shop_part = SL::DB::Manager::ShopPart->get_all( where => [id => $part], with_objects => ['part', 'shop'])->[0];
201 157
    require SL::DB::Shop;
202 158
    my $shop = SL::Shop->new( config => $shop_part->shop );
203
    my $online_article = $shop->connector->get_article_info($shop_part->part->partnumber);
159
    my $online_article = $shop->connector->get_article($shop_part->part->partnumber);
204 160
    my $online_cat = $online_article->{data}->{categories};
205 161
    my @cat = ();
206 162
    for(keys %$online_cat){
......
268 224
    $article->{images} = $images;
269 225
  }
270 226

  
271
  $self->_setup_list_action_bar;
272

  
273 227
  $self->render('shop_part/_list_articles', title => t8('Webshops articles'), SHOP_PARTS => $articles);
274 228
}
275 229

  
......
401 355
  return($price,$price_src_str);
402 356
}
403 357

  
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

  
427 358
sub check_auth {
428 359
  $::auth->assert('shop_part_edit');
429 360
}
SL/ShopConnector/Shopware.pm
422 422
  return $upload_content->{success};
423 423
}
424 424

  
425
sub get_parts_info {
425
sub get_article {
426 426
  my ($self,$partnumber) = @_;
427 427

  
428 428
  my $url       = $self->url;
SL/ShopConnector/WooCommerce.pm
154 154
                        shop_order_id        => $id,
155 155
                        active_price_source  => $active_price_source,
156 156
                      );
157
    #$main::lxdebug->dump(0, "TST: WooCommerce save pos", $pos);
158
    #$main::lxdebug->dump(0, "TST: WooCommerce save pos_columns", \%pos_columns);
159 157
    my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
160 158
    $pos_insert->save;
161 159
    $position++;
......
346 344
  #};
347 345

  
348 346
  my @categories = ();
349
  if ($shop_part->shop_category) {
350
    foreach my $row_cat ( @{ $shop_part->shop_category } ) {
351
      my $temp = { ( id => @{$row_cat}[0], ) };
352
      push ( @categories, $temp );
353
    }
347
  foreach my $row_cat ( @{ $shop_part->shop_category } ) {
348
    my $temp = { ( id => @{$row_cat}[0], ) };
349
    push ( @categories, $temp );
354 350
  }
355 351

  
356 352
  #my @upload_img = $shop_part->get_images;
357
  my $partnumber = $::form->escape($part->partnumber);#don't accept / in partnumber
353
  my $partnumber = $::form->escape($part->partnumber);#don't accept / in articlenumber
358 354
  my $stock_status = ($part->onhand ? "instock" : "outofstock");
359 355
  my $status = ($shop_part->active ? "publish" : "private");
360 356
  my $tax_n_price = $shop_part->get_tax_and_price;
......
413 409

  
414 410
  # don't know if this is needed
415 411
  #if(@upload_img) {
416
  #  my $partnumber = $::form->escape($part->partnumber);#shopware don't accept / in partnumber
417
  #  my $imgup      = $self->connector->put($url . "api/generatepartimages/$partnumber?useNumberAsId=true");
412
  #  my $partnumber = $::form->escape($part->partnumber);#shopware don't accept / in articlenumber
413
  #  my $imgup      = $self->connector->put($url . "api/generatearticleimages/$partnumber?useNumberAsId=true");
418 414
  #}
419 415

  
420 416
  return $answer->{success};
421 417
}
422 418

  
423
sub get_article_info {
419
sub get_article {
424 420
  my ($self) = @_;
425 421
  my $partnumber = $_[1];
426 422

  
427 423
  $partnumber   = $::form->escape($partnumber);#don't accept / in partnumber
428 424
  my $answer = $self->send_request("products/", undef , "get" , "&sku=$partnumber");
429 425

  
430
  $answer->{data} = $answer->{data}[0];
431
  #$main::lxdebug->dump(0, "TST: WooCommerce get_part_info ", $answer);
432
  return $answer;
433

  
434 426
  if($answer->{success} && scalar @{$answer->{data}}){
435
    my $part = $self->map_data_to_part($answer->{data}[0]);
436
    #$main::lxdebug->dump(0, "TST: WooCommerce get_part_info part", $part);
437
    return $part;
427
    my $article = $answer->{data}[0];
428
    return $article;
438 429
  } else {
439 430
    #What shut be here?
440 431
    return $answer
441 432
  }
442 433
}
443 434

  
444
sub map_data_to_part {
445
  my ($self, $part_data) = @_;
446

  
447
  my %map_part_data =  (
448
    #id                 => $part_data->{},
449
    partnumber         => $part_data->{sku},
450
    description        => $part_data->{name},
451
    #listprice          => $part_data->{},
452
    #sellprice          => $part_data->{},
453
    #lastcost           => $part_data->{},
454
    #priceupdate        => $part_data->{},
455
    #weight             => $part_data->{},
456
    notes              => $part_data->{description},
457
    #makemodel          => $part_data->{},
458
    #rop                => $part_data->{},
459
    shop               => 1,
460
    obsolete           => 0,
461
    #bom                => $part_data->{},
462
    #image              => $part_data->{},
463
    #drawing            => $part_data->{},
464
    #microfiche         => $part_data->{},
465
    #partsgroup_id      => $part_data->{},
466
    #ve                 => $part_data->{},
467
    #gv                 => $part_data->{},
468
    #itime              => $part_data->{},
469
    #mtime              => $part_data->{},
470
    #unit               => $part_data->{},
471
    unit               => 'Stck',
472
    #formel             => $part_data->{},
473
    #not_discountable   => $part_data->{},
474
    #buchungsgruppen_id => $part_data->{},
475
    #payment_id         => $part_data->{},
476
    #ean                => $part_data->{},
477
    #price_factor_id    => $part_data->{},
478
    #onhand             => $part_data->{},
479
    #stockable          => $part_data->{},
480
    #has_sernumber      => $part_data->{},
481
    #warehouse_id       => $part_data->{},
482
    #bin_id             => $part_data->{},
483
    #df_status_aktuell  => $part_data->{},
484
    #df_status_verlauf  => $part_data->{},
485
    #active             => $part_data->{},
486
    #classification_id  => $part_data->{},
487
    part_type          => 'part',
488
  );
489
  return SL::DB::Part->new(%map_part_data);
490
}
491

  
492
sub map_data_to_shop_part {
493
  my ($self, $part_data, $part) = @_;
494

  
495
  my @categories = ();
496
  foreach my $row_cat ( @{ $part_data->{categories} } ) {
497
    my @tmp;
498
    push( @tmp,$row_cat->{id} );
499
    push( @tmp,$row_cat->{name} );
500
    push( @categories,\@tmp );
501
  }
502
  my %map_shop_part_data =  (
503
    #id                  => ,
504
    shop_id             => $self->config->id,
505
    part_id             => $part->id,
506
    shop_description    => $part_data->{description},
507
    #itime               => ,
508
    #mtime               => ,
509
    #last_update         => ,
510
    #show_date           => ,
511
    sortorder           => $part_data->{menu_order},
512
    #front_page          => ,
513
    active              => 1,
514
    shop_category       => \@categories,
515
    #active_price_source => ,
516
    #metatag_keywords    => ,
517
    #metatag_description => ,
518
    #metatag_title       => ,
519
    #shop_versandhinweis => ,
520
  );
521
  return SL::DB::ShopPart->new(%map_shop_part_data);
522
}
523
sub get_shop_parts {
524
  my ($self, $partnumber) = @_;
525

  
526
  my $dbh       = SL::DB::client;
527
  my @errors;
528
  my $number_of_parts = 0;
529
  my %fetched_parts;
530
  my $answer;
531

  
532
  if ($partnumber) {
533
    $partnumber   = $::form->escape($partnumber);#don't accept / in partnumber
534
    $answer = $self->send_request("products/", undef , "get" , "&sku=$partnumber");
535
  } else {
536
    #TODO
537
    $answer = $self->send_request("products/", undef , "get");
538
    if ($answer->{total_pages} > 1) {
539
      my $current_page = 2;
540
      while ($current_page <= $answer->{total_pages}) {
541
        my $tmp_answer = $self->send_request("products/", undef , "get", "&page=$current_page");
542
        foreach my $part (@{$tmp_answer->{data}}) {
543
          push @{$answer->{data}} , $part;
544
        }
545
        $current_page++;
546
      }
547
    }
548
  }
549

  
550
  if($answer->{success} && scalar @{$answer->{data}}){
551
    $dbh->with_transaction( sub{
552
      foreach my $part_data (@{$answer->{data}}) {
553
      unless (!$part_data->{sku} || SL::DB::Manager::Part->get_all_count( query => [ partnumber => $part_data->{sku} ] )) {
554
          my $part = $self->map_data_to_part($part_data);
555
          #$main::lxdebug->dump(0, "TST: WooCommerce get_shop_parts part ", $part);
556
          $part->save;
557
          my $shop_part = $self->map_data_to_shop_part($part_data, $part);
558
          #$main::lxdebug->dump(0, "TST: WooCommerce get_shop_parts shop_part ", $shop_part);
559
          $shop_part->save;
560
          $number_of_parts++;
561
        }
562
      }
563
      return 1;
564
    })or do {
565
      push @errors,($::locale->text('Saving failed. Error message from the database: #1', $dbh->error));
566
    };
567

  
568
    if(@errors){
569
      flash_later('error', $::locale->text('Errors: #1', @errors));
570
    }
571
    %fetched_parts = (
572
      shop_id          => $self->config->id,
573
      shop_description => $self->config->description,
574
      number_of_parts => $number_of_parts,
575
    );
576
  } else {
577
    my %error_msg  = (
578
      shop_id          => $self->config->id,
579
      shop_description => $self->config->description,
580
      message          => $answer->{message},
581
      error            => 1,
582
    );
583
    %fetched_parts = %error_msg;
584
  }
585
  return \%fetched_parts;
586
}
587

  
588 435
sub get_categories {
589 436
  my ($self) = @_;
590 437

  
......
678 525
  my %return;
679 526
  if($answer->is_success && $type eq 'application/json'){
680 527
    my $data_json = $answer->content;
681
    #$main::lxdebug->dump(0, "TST: WooCommerce send_request header ", $answer->header( 'Link'));
682 528
    my $json = SL::JSON::decode_json($data_json);
683 529
    %return = (
684 530
      success => 1,
685 531
      data    => $json,
686
      total_pages => $answer->header( 'X-WP-TotalPages'),
687
      total_elements => $answer->header( 'X-WP-Total'),
688 532
    );
689 533
  }else{
690 534
    %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
  };
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
  };
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
  };
143
  }
166 144

  
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
  };
171 145

  
172 146
  ns.setup = function() {
173 147
    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')) %]
24 25
 </p>
25 26
</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' %]
4 3
<h1>[% title %]</h1>
5 4
[%- PROCESS 'shop_part/_filter.html' filter=SELF.models.filtered.laundered %]
6 5
<hr>
......
124 123
    [%- INCLUDE 'shop_part/_upload_status.html' %]
125 124
  </div>
126 125
</form>
127
 <div id="get_one" style="display:none;">
128
   [% INCLUDE 'shop_part/_get_one.html' %]
129
 </div>
130 126
<hr>
131 127
<script type="text/javascript">
132 128
<!--

Auch abrufbar als: Unified diff