Shopware6: Status completed innerhalb des Konnektors mappen
[kivitendo-erp.git] / SL / ShopConnector / Shopware6.pm
index 38ec37f..6d04a1b 100644 (file)
@@ -180,7 +180,11 @@ sub update_part {
     }
     undef $update_p->{partNumber}; # we dont need this one
     $ret = $self->connector->PATCH('api/product/' . $one_d->{id}, to_json($update_p));
     }
     undef $update_p->{partNumber}; # we dont need this one
     $ret = $self->connector->PATCH('api/product/' . $one_d->{id}, to_json($update_p));
-    die "Updating part with " .  $part->partnumber . " failed: " . $ret->responseContent() unless (204 == $ret->responseCode());
+    unless (204 == $ret->responseCode()) {
+      die t8('Part Description is too long for this Shopware version. It should have lower than 255 characters.')
+         if $ret->responseContent() =~ m/Diese Zeichenkette ist zu lang. Sie sollte.*255 Zeichen/;
+      die "Updating part with " .  $part->partnumber . " failed: " . $ret->responseContent() unless (204 == $ret->responseCode());
+    }
   } else {
     # create part
     # 1. get the correct tax for this product
   } else {
     # create part
     # 1. get the correct tax for this product
@@ -697,8 +701,11 @@ sub get_version {
 sub set_orderstatus {
   my ($self, $order_id, $transition) = @_;
 
 sub set_orderstatus {
   my ($self, $order_id, $transition) = @_;
 
-  croak "No order ID, should be in format [0-9a-f]{32}" unless $order_id   =~ m/^[0-9a-f]{32}$/;
-  croak "NO valid transition value"                     unless $transition =~ m/(open|process|cancel|complete)/;
+  # one state differs
+  $transition = 'complete' if $transition eq 'completed';
+
+  croak "No shop order ID, should be in format [0-9a-f]{32}" unless $order_id   =~ m/^[0-9a-f]{32}$/;
+  croak "NO valid transition value"                          unless $transition =~ m/(open|process|cancel|complete)/;
   my $ret;
   $ret = $self->connector->POST("/api/_action/order/$order_id/state/$transition");
   my $response_code = $ret->responseCode();
   my $ret;
   $ret = $self->connector->POST("/api/_action/order/$order_id/state/$transition");
   my $response_code = $ret->responseCode();
@@ -709,10 +716,10 @@ sub set_orderstatus {
 sub init_connector {
   my ($self) = @_;
 
 sub init_connector {
   my ($self) = @_;
 
-  my $client = REST::Client->new(host => $self->config->server);
+  my $protocol = $self->config->server =~ /(^https:\/\/|^http:\/\/)/ ? '' : $self->config->protocol . '://';
+  my $client   = REST::Client->new(host => $protocol . $self->config->server);
 
   $client->getUseragent()->proxy([$self->config->protocol], $self->config->proxy) if $self->config->proxy;
 
   $client->getUseragent()->proxy([$self->config->protocol], $self->config->proxy) if $self->config->proxy;
-
   $client->addHeader('Content-Type', 'application/json');
   $client->addHeader('charset',      'UTF-8');
   $client->addHeader('Accept',       'application/json');
   $client->addHeader('Content-Type', 'application/json');
   $client->addHeader('charset',      'UTF-8');
   $client->addHeader('Accept',       'application/json');
@@ -763,7 +770,7 @@ sub import_data_to_shop_order {
     foreach my $pos (@positions) {
       $position++;
       my $price       = $::form->round_amount($pos->{unitPrice}, 2); # unit
     foreach my $pos (@positions) {
       $position++;
       my $price       = $::form->round_amount($pos->{unitPrice}, 2); # unit
-      my %pos_columns = ( description          => $pos->{product}->{description},
+      my %pos_columns = ( description          => $pos->{product}->{name},
                           partnumber           => $pos->{product}->{productNumber},
                           price                => $price,
                           quantity             => $pos->{quantity},
                           partnumber           => $pos->{product}->{productNumber},
                           price                => $price,
                           quantity             => $pos->{quantity},
@@ -967,15 +974,13 @@ Updates all metadata for a shop part. See base class for a general description.
 Specific Implementation notes:
 =over 4
 
 Specific Implementation notes:
 =over 4
 
-=item Calls sync_all_images with set_cover = 1 and delete_orphaned = 1
+=item Calls sync_all_images with set_cover = 1 and delete_orphaned = 1
 
 
-=item Checks if longdescription should be taken from part or shop_part
+=item Checks if longdescription should be taken from part or shop_part
 
 
-=item Checks if a language with the name 'Englisch' or template_code 'en'
+=item Checks if a language with the name 'Englisch' or template_code 'en'
       is available and sets the shopware6 'en-GB' locales for the product
 
       is available and sets the shopware6 'en-GB' locales for the product
 
-=back
-
 =item C<sync_all_images (set_cover: 0|1, delete_orphaned: 0|1)>
 
 The connecting key for shopware to kivi images is the image name.
 =item C<sync_all_images (set_cover: 0|1, delete_orphaned: 0|1)>
 
 The connecting key for shopware to kivi images is the image name.
@@ -993,6 +998,9 @@ entry for the image is deleted.
 More on media and Shopware6 can be found here:
 https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyNjI1Mzkw-media-handling
 
 More on media and Shopware6 can be found here:
 https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyNjI1Mzkw-media-handling
 
+=back
+
+=over 4
 
 =item C<get_article>
 
 
 =item C<get_article>
 
@@ -1072,6 +1080,12 @@ Right now the returning structure and the common parts of the filter are in two
 
 Many error messages are thrown, but at least the more common cases should be localized.
 
 
 Many error messages are thrown, but at least the more common cases should be localized.
 
+=item * Multi language support
+
+By guessing the correct german name for the english language some translation for parts can
+also be synced. This should be more clear (language configuration for shops) and the order
+synchronisation should also handle this (longdescription is simply copied from part.notes)
+
 =back
 
 =head1 AUTHOR
 =back
 
 =head1 AUTHOR