commit bf624ffb110751bb243105d15434953e2562d0a1
Author: Werner Hahn <wh@futureworldsearch.net>
Date:   Fri Aug 11 10:26:17 2017 +0200

    shopmodul: Shoppart: Kommentare und nicht benötigte Zeilen raus

diff --git a/SL/Controller/File.pm b/SL/Controller/File.pm
index 539c05f15..5ed91c363 100644
--- a/SL/Controller/File.pm
+++ b/SL/Controller/File.pm
@@ -289,27 +289,6 @@ sub action_download {
   my ($id,$version) = split /_/, $::form->{id};
   my $file = SL::File->get(id => $id );
   $file->version($version) if $version;
-  my $ref  = $file->get_content;
-                                     );
-          unlink($sfile->file_name);
-        }
-        1;
-      } or do {
-        $self->js->flash(       'error', t8('internal error (see details)'))
-                 ->flash_detail('error', $@)->render;
-        return;
-      }
-    }
-  }
-  $self->existing(\@existing);
-  $self->_do_list(1);
-}
-
-sub action_download {
-  my ($self) = @_;
-  my ($id, $version) = split /_/, $::form->{id};
-  my $file = SL::File->get(id => $id );
-  $file->version($version) if $version;
   my $ref  = $file->get_content;
   if ( $file && $ref ) {
     return $self->send_file($ref,
@@ -400,7 +379,14 @@ sub _do_list {
                                 );
   }
   $self->files(\@files);
-  $self->_mk_render('file/list', 1, 0, $json);
+
+  if($self->object_type eq 'shop_image'){
+    $self->js
+      ->run('kivi.ShopPart.show_images', $self->object_id)
+      ->render();
+  }else{
+    $self->_mk_render('file/list', 1, 0, $json);
+  }
 }
 
 sub _get_from_import {
diff --git a/SL/Controller/ShopPart.pm b/SL/Controller/ShopPart.pm
index 429bda27b..c8a801ad1 100644
--- a/SL/Controller/ShopPart.pm
+++ b/SL/Controller/ShopPart.pm
@@ -71,61 +71,6 @@ sub action_show_files {
   $self->render('shop_part/_list_images', { header => 0 }, IMAGES => $images);
 }
 
-sub action_ajax_upload_file{
-  my ($self, %params) = @_;
-
-  my $attributes                   = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
-
-  $attributes->{filename} = ((($::form->{ATTACHMENTS} || {})->{ $::form->{form_prefix} } || {})->{file_content} || {})->{filename};
-
-  my @errors;
-  my @file_errors = SL::DB::File->new(%{ $attributes })->validate;
-  push @errors,@file_errors if @file_errors;
-
-  my @type_error = SL::Controller::FileUploader->validate_filetype($attributes->{filename},$::form->{aft});
-  push @errors,@type_error if @type_error;
-
-  return $self->js->error(@errors)->render($self) if @errors;
-
-  $self->file->assign_attributes(%{ $attributes });
-  $self->file->file_update_type_and_dimensions;
-  $self->file->save;
-
-  $self->js
-    ->dialog->close('#jqueryui_popup_dialog')
-    ->run('kivi.ShopPart.show_images',$self->file->trans_id)
-    ->render();
-}
-
-#sub action_ajax_update_file{
-# my ($self, %params) = @_;
-
-# my $attributes                   = $::form->{ $::form->{form_prefix} } || die "Missing attributes";
-
-# if (!$attributes->{file_content}) {
-#   delete $attributes->{file_content};
-# } else {
-#   $attributes->{filename} = ((($::form->{ATTACHMENTS} || {})->{ $::form->{form_prefix} } || {})->{file_content} || {})->{filename};
-# }
-
-# my @errors;
-# my @type_error = SL::Controller::FileUploader->validate_filetype($attributes->{filename},$::form->{aft});
-# push @errors,@type_error if @type_error;
-# $self->file->assign_attributes(%{ $attributes });
-# my @file_errors = $self->file->validate if $attributes->{file_content};;
-# push @errors,@file_errors if @file_errors;
-
-# return $self->js->error(@errors)->render($self) if @errors;
-
-# $self->file->file_update_type_and_dimensions if $attributes->{file_content};
-# $self->file->save;
-
-# $self->js
-#   ->dialog->close('#jqueryui_popup_dialog')
-#   ->run('kivi.ShopPart.show_images',$self->file->trans_id)
-#   ->render();
-#}
-
 sub action_ajax_delete_file {
   my ( $self ) = @_;
   $self->file->delete;
@@ -232,7 +177,6 @@ sub create_or_update {
 
   my ( $price, $price_src_str ) = $self->get_price_n_pricesource($self->shop_part->active_price_source);
 
-  #TODO Price must be formatted. $price_src_str must be translated
   flash('info', $is_new ? t8('The shop part has been created.') : t8('The shop part has been saved.'));
   $self->js->html('#shop_part_description_' . $self->shop_part->id, $self->shop_part->shop_description)
            ->html('#shop_part_active_' . $self->shop_part->id, $self->shop_part->active)
@@ -252,7 +196,7 @@ sub render_shop_part_edit_dialog {
     ->run(
       'kivi.ShopPart.shop_part_dialog',
       t8('Shop part'),
-      $self->render('shop_part/edit', { output => 0 }) #, shop_part => $self->shop_part)
+      $self->render('shop_part/edit', { output => 0 })
     )
     ->reinit_widgets;
 
@@ -309,7 +253,7 @@ sub action_list_articles {
   my $articles = SL::DB::Manager::ShopPart->get_all(where => [ 'shop.obsolete' => 0 ],with_objects => [ 'part','shop' ], sort_by => $sort_by );
 
   foreach my $article (@{ $articles}) {
-    my $images = SL::DB::Manager::File->get_all_count( where => [ trans_id => $article->part->id, modul => 'shop_part', file_content_type => { like => 'image/%' } ], sort_by => 'position' );
+    my $images = SL::DB::Manager::ShopImage->get_all_count( where => [ 'files.object_id' => $article->part->id, ], with_objects => 'file', sort_by => 'position' );
     $article->{images} = $images;
   }
 
@@ -385,7 +329,6 @@ sub get_price_n_pricesource {
 
   require SL::DB::Pricegroup;
   require SL::DB::Part;
-  #TODO Price must be formatted. Translations for $price_grp_str
   my $price;
   if ($price_src_str eq "master_data") {
     my $part       = SL::DB::Manager::Part->get_all( where => [id => $self->shop_part->part_id], with_objects => ['prices'],limit => 1)->[0];
@@ -410,7 +353,6 @@ sub init_shop_part {
     SL::DB::Manager::ShopPart->find_by(id => $::form->{shop_part_id});
   } else {
     SL::DB::ShopPart->new(shop_id => $::form->{shop_id}, part_id => $::form->{part_id});
-    #SL::DB::ShopPart->new;
   };
 }
 
@@ -466,6 +408,10 @@ __END__
 
 =back
 
+=head1 TODO
+
+  Pricesrules, pricessources aren't fully implemented yet.
+
 =head1 AUTHORS
 
   G. Richardson E<lt>information@kivitendo-premium.deE<gt>
diff --git a/SL/ShopConnector/Shopware.pm b/SL/ShopConnector/Shopware.pm
index 2109a857f..050ac3241 100644
--- a/SL/ShopConnector/Shopware.pm
+++ b/SL/ShopConnector/Shopware.pm
@@ -250,7 +250,6 @@ sub update_part {
     push ( @cat, $temp );
   }
 
-  # my $images = SL::DB::Manager::File->get_all( where => [ modul => 'shop_part', trans_id => $part->{id} ]);
   my $images = SL::DB::Manager::ShopImage->get_all( where => [ 'files.object_id' => $part->{id}, ], with_objects => 'file', sort_by => 'position' );
   my @upload_img = ();
   foreach my $img (@{ $images }) {
@@ -270,6 +269,8 @@ sub update_part {
   my ($import,$data,$data_json);
 #  if( $shop_part->last_update){
     my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber
+# Shopware RestApi schreibt Fehleremail wenn Artikel nicht gefunden. es braucht aber irgendeine Abfrage, ob der Artikel schon im Shop ist.
+# LWP->post = neuanlegen LWP->put = update
     $data = $self->connector->get("http://$url/api/articles/$partnumber?useNumberAsId=true");
     $data_json = $data->content;
     $import = SL::JSON::decode_json($data_json);
@@ -288,6 +289,7 @@ sub update_part {
   }
 
   # get the right taxrate for the article
+  # TODO In extra Helper??
   my $taxrate;
   my $dbh = $::form->get_standard_dbh();
   my $b_id = $part->buchungsgruppen_id;
@@ -361,25 +363,26 @@ sub update_part {
 
   my $dataString = SL::JSON::to_json(\%shop_data);
   $dataString = encode_utf8($dataString);
-  $main::lxdebug->dump(0, 'WH:UPLOAD ', $dataString);
   my $upload_content;
+  my $upload;
   if($import->{success}){
     #update
     my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber
-    my $upload = $self->connector->put("http://$url/api/articles/$partnumber?useNumberAsId=true",Content => $dataString);
+    $upload = $self->connector->put("http://$url/api/articles/$partnumber?useNumberAsId=true",Content => $dataString);
     my $data_json = $upload->content;
     $upload_content = SL::JSON::decode_json($data_json);
   }else{
     #upload
-    my $upload = $self->connector->post("http://$url/api/articles/",Content => $dataString);
+    $upload = $self->connector->post("http://$url/api/articles/",Content => $dataString);
     my $data_json = $upload->content;
     $upload_content = SL::JSON::decode_json($data_json);
   }
   # Don't know if this is needed
   if(@upload_img) {
     my $partnumber = $::form->escape($part->{partnumber});#shopware don't accept / in articlenumber
-    $self->connector->put("http://$url/api/generateArticleImages/$partnumber?useNumberAsId=true");
+    my $imgup = $self->connector->put("http://$url/api/generateArticleImages/$partnumber?useNumberAsId=true");
   }
+
   return $upload_content->{success};
 }
 
diff --git a/js/kivi.ShopPart.js b/js/kivi.ShopPart.js
index 9065aeeb6..329ea6695 100644
--- a/js/kivi.ShopPart.js
+++ b/js/kivi.ShopPart.js
@@ -154,7 +154,6 @@ namespace('kivi.ShopPart', function(ns) {
                                  },
                         id:     'files_upload',
                         dialog: { title: upload_title, width: 650, height: 240 } });
-    kivi.ShopPart.show_image(id);
     return true;
   }
 
