Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5878b90c

Von Werner Hahn vor mehr als 6 Jahren hinzugefügt

  • ID 5878b90c0b0b1caa84de692c39fdac9b01a9b103
  • Vorgänger 3c7d9283
  • Nachfolger 56b2b81c

Shopmodul: ActionBar, automatische Prüfung der Shopverbindung beim
speichern
Zusätzliche Felder in der Shopconfig für Pfad, Realm und Protokoll

Unterschiede anzeigen:

SL/ShopConnector/Shopware.pm
26 26
sub get_new_orders {
27 27
  my ($self, $id) = @_;
28 28

  
29
  my $url = $self->url;
30

  
29
  my $url       = $self->url;
31 30
  my $ordnumber = $self->config->last_order_number + 1;
32
  my $otf = $self->config->orders_to_fetch;
31
  my $otf       = $self->config->orders_to_fetch;
33 32

  
34 33
  my $i;
35 34
  for ($i=1;$i<=$otf;$i++) {
36 35

  
37
    my $data = $self->connector->get("http://$url/api/orders/$ordnumber?useNumberAsId=true");
36
    my $data      = $self->connector->get($url . "api/orders/$ordnumber?useNumberAsId=true");
38 37
    my $data_json = $data->content;
39
    my $import = SL::JSON::decode_json($data_json);
38
    my $import    = SL::JSON::decode_json($data_json);
40 39
    if ($import->{success}){
41 40

  
42 41
      # Mapping to table shoporders. See http://community.shopware.com/_detail_1690.html#GET_.28Liste.29
......
131 130
      $shop_order->{positions} = $position-1;
132 131

  
133 132
      # Only Customers which are not found will be applied
134
      my $name = $shop_order->billing_lastname ne '' ? "%" . $shop_order->billing_firstname . "%" . $shop_order->billing_lastname . "%" : '';
133
      my $name     = $shop_order->billing_lastname ne '' ? "%" . $shop_order->billing_firstname . "%" . $shop_order->billing_lastname . "%" : '';
135 134
      my $lastname = $shop_order->billing_lastname ne '' ? "%" . $shop_order->billing_lastname . "%" : '';
136
      my $company = $shop_order->billing_company ne '' ? "%" . $shop_order->billing_company . "%" : '';
137
      my $street = $shop_order->billing_street ne '' ?  $shop_order->billing_street : '';
135
      my $company  = $shop_order->billing_company ne '' ? "%" . $shop_order->billing_company . "%" : '';
136
      my $street   = $shop_order->billing_street ne '' ?  $shop_order->billing_street : '';
138 137
      # Fuzzysearch for street to find e.g. "Dorfstrasse - Dorfstr. - Dorfstraße"
139
      my $dbh = $::form->get_standard_dbh();
138
      my $dbh      = $::form->get_standard_dbh();
140 139
      my $fs_query = "SELECT id FROM customer WHERE ( ( (    name ILIKE ?
141 140
                                                          OR name ILIKE ?
142 141
                                                        )
......
148 147
                                                      OR email ILIKE ?
149 148
                                                    )";
150 149
      my @values = ($lastname, $company, $shop_order->billing_zipcode, $street, $shop_order->billing_zipcode, $shop_order->billing_email);
151
      my @c_ids = selectall_array_query($::form, $dbh, $fs_query, @values);
150
      my @c_ids  = selectall_array_query($::form, $dbh, $fs_query, @values);
152 151

  
153 152
      if(!scalar(@c_ids)){
154 153

  
......
200 199
      $ordnumber++;
201 200
    }
202 201
  }
203
  my $shop = $self->config->description;
202
  my $shop           = $self->config->description;
204 203
  my @fetched_orders = ($shop,$i);
205 204
  return \@fetched_orders;
206 205
};
......
208 207
sub get_categories {
209 208
  my ($self) = @_;
210 209

  
211
  my $url = $self->url;
212

  
213
  my $data = $self->connector->get("http://$url/api/categories");
214

  
215
  my $data_json = $data->content;
216
  my $import = SL::JSON::decode_json($data_json);
217
  my @daten = @{$import->{data}};
210
  my $url        = $self->url;
211
  my $data       = $self->connector->get($url . "api/categories");
212
  my $data_json  = $data->content;
213
  my $import     = SL::JSON::decode_json($data_json);
214
  my @daten      = @{$import->{data}};
218 215
  my %categories = map { ($_->{id} => $_) } @daten;
219 216

  
220 217
  for(@daten) {
......
226 223
  return \@daten;
227 224
}
228 225

  
226
sub get_version {
227
  my ($self) = @_;
228

  
229
  my $url       = $self->url;
230
  my $data      = $self->connector->get($url . "api/version");
231
  my $type = $data->content_type;
232
  my $status_line = $data->status_line;
233

  
234
  if($data->is_success && $type eq 'application/json'){
235
    my $data_json = $data->content;
236
    return SL::JSON::decode_json($data_json);
237
  }else{
238
    my %return = ( success => 0,
239
                   data  => { version => $url . ": " . $status_line, revision => $type },
240
                   message => "Server not found or wrong data type",
241
                );
242
    return \%return;
243
  }
244
}
245

  
229 246
sub get_articles {
230 247
  my ($self, $json_data) = @_;
231 248

  
232 249
}
233 250

  
234

  
235 251
sub update_part {
236 252
  my ($self, $shop_part, $json, $todo) = @_;
237 253

  
......
253 269
  my $images = SL::DB::Manager::ShopImage->get_all( where => [ 'files.object_id' => $part->{id}, ], with_objects => 'file', sort_by => 'position' );
254 270
  my @upload_img = ();
255 271
  foreach my $img (@{ $images }) {
256
    my $file = SL::File->get(id => $img->file->id );
257
    my $file_path = $file->get_file;
272
    my $file               = SL::File->get(id => $img->file->id );
273
    my $file_path          = $file->get_file;
258 274
    my ($path, $extension) = (split /\./, $file->file_name);
259
    my $content = File::Slurp::read_file($file->get_file);
275
    my $content            = File::Slurp::read_file($file->get_file);
276

  
260 277
    my $temp ={ ( link        => 'data:' . $file->mime_type . ';base64,' . MIME::Base64::encode($content),
261 278
                  description => $img->file->title,
262 279
                  position    => $img->position,
......
271 288
    my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber
272 289
# Shopware RestApi schreibt Fehleremail wenn Artikel nicht gefunden. es braucht aber irgendeine Abfrage, ob der Artikel schon im Shop ist.
273 290
# LWP->post = neuanlegen LWP->put = update
274
    $data = $self->connector->get("http://$url/api/articles/$partnumber?useNumberAsId=true");
275
    $data_json = $data->content;
276
    $import = SL::JSON::decode_json($data_json);
291
    $data       = $self->connector->get($url . "api/articles/$partnumber?useNumberAsId=true");
292
    $data_json  = $data->content;
293
    $import     = SL::JSON::decode_json($data_json);
277 294
#  }
278 295

  
279 296
  # get the right price
......
291 308
  # get the right taxrate for the article
292 309
  # TODO In extra Helper??
293 310
  my $taxrate;
294
  my $dbh = $::form->get_standard_dbh();
311
  my $dbh  = $::form->get_standard_dbh();
295 312
  my $b_id = $part->buchungsgruppen_id;
296 313
  my $t_id = $shop_part->shop->taxzone_id;
297 314

  
......
362 379
  }
363 380

  
364 381
  my $dataString = SL::JSON::to_json(\%shop_data);
365
  $dataString = encode_utf8($dataString);
382
  $dataString    = encode_utf8($dataString);
366 383
  my $upload_content;
367 384
  my $upload;
368 385
  if($import->{success}){
369 386
    #update
370
    my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber
371
    $upload = $self->connector->put("http://$url/api/articles/$partnumber?useNumberAsId=true",Content => $dataString);
372
    my $data_json = $upload->content;
387
    my $partnumber  = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber
388
    $upload         = $self->connector->put($url . "api/articles/$partnumber?useNumberAsId=true", Content => $dataString);
389
    my $data_json   = $upload->content;
373 390
    $upload_content = SL::JSON::decode_json($data_json);
374 391
  }else{
375 392
    #upload
376
    $upload = $self->connector->post("http://$url/api/articles/",Content => $dataString);
377
    my $data_json = $upload->content;
393
    $upload         = $self->connector->post($url . "api/articles/", Content => $dataString);
394
    my $data_json   = $upload->content;
378 395
    $upload_content = SL::JSON::decode_json($data_json);
379 396
  }
380
  # Don't know if this is needed
397
  # don't know if this is needed
381 398
  if(@upload_img) {
382 399
    my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber
383
    my $imgup = $self->connector->put("http://$url/api/generateArticleImages/$partnumber?useNumberAsId=true");
400
    my $imgup      = $self->connector->put($url . "api/generatearticleimages/$partnumber?usenumberasid=true");
384 401
  }
385 402

  
386 403
  return $upload_content->{success};
......
389 406
sub get_article {
390 407
  my ($self,$partnumber) = @_;
391 408

  
392
  my $url = $self->url;
393
  $partnumber = $::form->escape($partnumber);#shopware don't accept / in articlenumber
394
  my $data = $self->connector->get("http://$url/api/articles/$partnumber?useNumberAsId=true");
409
  my $url       = $self->url;
410
  $partnumber   = $::form->escape($partnumber);#shopware don't accept / in articlenumber
411
  my $data      = $self->connector->get($url . "api/articles/$partnumber?usenumberasid=true");
395 412
  my $data_json = $data->content;
396 413
  return SL::JSON::decode_json($data_json);
397 414
}
398 415

  
416

  
399 417
sub set_orderstatus {
400 418
  my ($self,$ordernumber);
401 419
}
402 420

  
403 421
sub init_url {
404 422
  my ($self) = @_;
405
  # TODO: validate url and port Mabey in shopconfig test connection
406
  $self->url($self->config->url . ":" . $self->config->port);
407
};
423
  $self->url($self->config->protocol . "://" . $self->config->server . ":" . $self->config->port . $self->config->path);
424
}
408 425

  
409 426
sub init_connector {
410 427
  my ($self) = @_;
411 428
  my $ua = LWP::UserAgent->new;
412 429
  $ua->credentials(
413
      $self->url,
414
      "Shopware REST-API", # TODO in config
430
      $self->config->server . ":" . $self->config->port,
431
      $self->config->realm,
415 432
      $self->config->login => $self->config->password
416 433
  );
434

  
417 435
  return $ua;
418
};
436
}
419 437

  
420 438
1;
421 439

  
......
425 443

  
426 444
=head1 NAME
427 445

  
428
  SL::ShopConnecter::Shopware - connector for Shopware 5
446
  SL::Shopconnecter::Shopware - connector for shopware 5
429 447

  
430 448
=head1 SYNOPSIS
431 449

  
432 450

  
433 451
=head1 DESCRIPTION
434 452

  
453
=head1 TODO
454

  
455
  Pricesrules, pricessources aren't fully implemented yet.
456
  Payments aren't implemented( need to map payments from Shopware like invoice, paypal etc. to payments in kivitendo)
435 457

  
436 458
=head1 BUGS
437 459

  

Auch abrufbar als: Unified diff