Merge branch 'debian' into b-3.6.1
[kivitendo-erp.git] / SL / ShopConnector / Shopware.pm
index 938f99b..65c42fd 100644 (file)
@@ -11,6 +11,7 @@ use LWP::Authen::Digest;
 use SL::DB::ShopOrder;
 use SL::DB::ShopOrderItem;
 use SL::DB::History;
+use SL::DB::PaymentTerm;
 use DateTime::Format::Strptime;
 use SL::DB::File;
 use Data::Dumper;
@@ -151,6 +152,20 @@ sub import_data_to_shop_order {
   }
   $shop_order->positions($position-1);
 
+  if ( $self->config->shipping_costs_parts_id ) {
+    my $shipping_part = SL::DB::Part->find_by( id => $self->config->shipping_costs_parts_id);
+    my %shipping_pos = ( description    => $import->{data}->{dispatch}->{name},
+                         partnumber     => $shipping_part->partnumber,
+                         price          => $import->{data}->{invoiceShipping},
+                         quantity       => 1,
+                         position       => $position,
+                         shop_trans_id  => 0,
+                         shop_order_id  => $id,
+                       );
+    my $shipping_pos_insert = SL::DB::ShopOrderItem->new(%shipping_pos);
+    $shipping_pos_insert->save;
+  }
+
   my $customer = $shop_order->get_customer;
 
   if(ref($customer)){
@@ -171,6 +186,12 @@ sub map_data_to_shoporder {
   my $shop_id      = $self->config->id;
   my $tax_included = $self->config->pricetype;
 
+  # Mapping Zahlungsmethoden muss an Firmenkonfiguration angepasst werden
+  my %payment_ids_methods = (
+    # shopware_paymentId => kivitendo_payment_id
+  );
+  my $default_payment    = SL::DB::Manager::PaymentTerm->get_first();
+  my $default_payment_id = $default_payment ? $default_payment->id : undef;
   # Mapping to table shoporders. See http://community.shopware.com/_detail_1690.html#GET_.28Liste.29
   my %columns = (
     amount                  => $import->{data}->{invoiceAmount},
@@ -218,7 +239,7 @@ sub map_data_to_shoporder {
     netamount               => $import->{data}->{invoiceAmountNet},
     order_date              => $orderdate,
     payment_description     => $import->{data}->{payment}->{description},
-    payment_id              => $import->{data}->{paymentId},
+    payment_id              => $payment_ids_methods{$import->{data}->{paymentId}} || $default_payment_id,
     remote_ip               => $import->{data}->{remoteAddress},
     sepa_account_holder     => $import->{data}->{paymentIntances}->{accountHolder},
     sepa_bic                => $import->{data}->{paymentIntances}->{bic},
@@ -251,13 +272,22 @@ sub get_categories {
   my @daten      = @{$import->{data}};
   my %categories = map { ($_->{id} => $_) } @daten;
 
+  my @categories_tree;
   for(@daten) {
+    # ignore root with id=1
+    if( $_->{id} == 1) {
+      next;
+    }
     my $parent = $categories{$_->{parentId}};
-    $parent->{children} ||= [];
-    push @{$parent->{children}},$_;
+    if($parent && $parent->{id} != 1) {
+      $parent->{children} ||= [];
+      push @{$parent->{children}},$_;
+    } else {
+      push @categories_tree, $_;
+    }
   }
 
-  return \@daten;
+  return \@categories_tree;
 }
 
 sub get_version {
@@ -438,7 +468,7 @@ __END__
 
 =head1 NAME
 
-SL::Shopconnecter::Shopware - connector for shopware 5
+SL::Shopconnector::Shopware - connector for shopware 5
 
 =head1 SYNOPSIS