Index: /mods/wpsg_mod_produktartikel.class.php
===================================================================
--- /mods/wpsg_mod_produktartikel.class.php	(revision 6118)
+++ /mods/wpsg_mod_produktartikel.class.php	(revision 6119)
@@ -389,5 +389,5 @@
 						$arBilder[] = $v['guid'];
 					}
-					if (sizeof($arBilder) > 0) $this->shop->view['data']['bilder'] = $arBilder;
+					if (isset($arBilder) && (sizeof($arBilder) > 0)) $this->shop->view['data']['bilder'] = $arBilder;
 					
 				}
@@ -702,5 +702,5 @@
 			if (!$this->shop->hasMod('wpsg_mod_produktbilder') || !wpsg_isSizedInt($this->shop->get_option('wpsg_mod_produktartikel_postthumbnail'))) return;
 			
-			$post_id = $this->getPostIdFromProductId($product_id);
+			$post_id = $this->getPostIdFromProductId($product_id);	// Parent-ID
 			
 			if ($post_id !== false)
@@ -711,26 +711,41 @@
 				
 				// Die Bilder mÃŒssen in extra Ordner liegen, da Wordpress auch die skallierten Bilder dort ablegt
-				$path_post_thumbnail = $this->shop->callMod('wpsg_mod_produktbilder', 'getPicPath', array($product_id)).'posthumbnail/';
-
-				// Ordner fÃŒr die Thumbnails lÃ¶schen, er beinhaltet die skallierten alten Bilder und wird wieder angelegt sofern ein Bild existiert
-				wpsg_rrmdir($path_post_thumbnail);
-				
+				$path_post_thumbnail = $this->shop->callMod('wpsg_mod_produktbilder', 'getPicPath', array($product_id)).'postthumbnail/';
+
+				// Ordner fÃŒr die Thumbnails lÃ¶schen, er beinhaltet die skalierten alten Bilder und wird wieder angelegt sofern ein Bild existiert
+				//wpsg_rrmdir($path_post_thumbnail);
+
 				// Eventuell bestehendes Thumbnail lÃ¶schen
 				if (wpsg_isSizedInt($post_thumbnail_id))
 				{
 					
+					// Postmeta Typ _thumbnail_id lÃ¶schen
 					delete_post_thumbnail($post_id);
+					// Postmeta Typ _wp_attachment_metadata und _wp_attached_file und Post lÃ¶schen
 					wp_delete_attachment($post_thumbnail_id);
 					
 				}
-				
-				$arBilder = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder', array($product_id));
-				 
+				// Medium weil sonst $attach_data['size'] 0 ist 
+				$arBilder = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id, 'medium'));
+				//$arBilder = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder', array($product_id));
+				
 				if (wpsg_isSizedArray($arBilder))
 				{
-					
-					$img_file = array_shift($arBilder);
-					
-					$filename = $this->shop->callMod('wpsg_mod_produktbilder', 'getPicPath', array($product_id)).$img_file;
+
+					$imgsrc = pathinfo($arBilder[0]['guid'])['basename'];	// hdoval-2-300x300.png
+					$imgdest = pathinfo(get_attached_file($arBilder[0]['post_id']))['basename'];	// hdoval-2.png
+					// alt: C:\xampp\htdocs\wp2\wp-content\uploads\wpsg\wpsg_produktbilder\6\posthumbnail/
+					// neu: C:\xampp\htdocs\wp2/wp-content/uploads/2017/03/postthumbnail/
+					$path_post_thumbnail = pathinfo(get_attached_file($arBilder[0]['post_id']))['dirname'].'/postthumbnail/';
+					// C:\xampp\htdocs\wp2/wp-content/uploads/2017/03/hdoval-2-300x300.png
+					$filename = pathinfo(get_attached_file($arBilder[0]['post_id']))['dirname'].'/'.$imgsrc;
+					// http://shop4.home/wp-content/uploads/2017/03
+					$fileurl = pathinfo($arBilder[0]['guid'])['dirname'].'/'.$imgdest;
+
+					//$img_file = array_shift($arBilder);
+					$img_file = $imgdest;
+					
+					// C:\xampp\htdocs\wp2\wp-content\uploads\wpsg\wpsg_produktbilder\6\hdoval-2-300x300.png
+					//$filename = $this->shop->callMod('wpsg_mod_produktbilder', 'getPicPath', array($product_id)).$img_file;
 					
 					if (!file_exists($path_post_thumbnail)) mkdir($path_post_thumbnail, 0777, true);
@@ -745,6 +760,6 @@
 						
 							$filetype = wp_check_filetype($img_file, null);
-					
-							$fileurl = $this->shop->callMod('wpsg_mod_produktbilder', 'getPicPath', array($product_id, true)).'posthumbnail/'.$img_file;
+							// http://shop4.home/wp-content/uploads/wpsg/wpsg_produktbilder/6/posthumbnail/hdoval-2-150x150.png
+							//$fileurl = $this->shop->callMod('wpsg_mod_produktbilder', 'getPicPath', array($product_id, true)).'posthumbnail/'.$img_file;
 							 
 							$attachment = array(
@@ -755,13 +770,15 @@
 								'post_status' => 'inherit'
 							);
-	
+							// Post und Postmeta Typ _wp_attached_file anlegen
 							$attach_id = wp_insert_attachment($attachment, $path_post_thumbnail.$img_file, $post_id);
 							
 							// Meta Daten schreiben
 							require_once(ABSPATH.'wp-admin/includes/image.php');
-								
+							
+							// Postmeta Typ _wp_attachment_metadata anlegen								
 							$attach_data = wp_generate_attachment_metadata($attach_id, $path_post_thumbnail.$img_file);
 							wp_update_attachment_metadata($attach_id, $attach_data);
 							
+							// Postmeta Typ _thumbnail_id anlegen
 							set_post_thumbnail($post_id, $attach_id);
 							
