Index: /mods/wpsg_mod_productvariants.class.php
===================================================================
--- /mods/wpsg_mod_productvariants.class.php	(revision 6426)
+++ /mods/wpsg_mod_productvariants.class.php	(revision 6427)
@@ -594,5 +594,6 @@
 
         			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['picOrder'] = $_REQUEST['wpsg_reorder'];
-
+        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pidOrder'] = $_REQUEST['wpsg_postids'];
+        			
         		}
 
@@ -881,4 +882,7 @@
         	$vdata['postid'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['postid'];
 
+        	if (isset($vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pidOrder']))
+        		$vdata['pidOrder'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pidOrder'];
+        	
         	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
         			"images" => wpsg_q(serialize($vdata))
@@ -2344,5 +2348,8 @@
 			{
 				$im0 = unserialize($v['images']);
-				
+                $im0['pic'] = trim($im0['pic'], ',');
+                $v['images'] = serialize($im0);
+				var_dump('ALT:'.$v['images'].'<br/>');
+                //die($v['images']);
 				$im1 = array();
 				$im1 = $im0;
@@ -2360,6 +2367,13 @@
 					if (isset($post['ID']))
 					{
-						$postid[] = $post['ID'];
-						$pic[] = sanitize_file_name($post['post_excerpt']);
+                        //die($postid[count($postid) - 1].'/'.$post['ID']);
+                        if (($postid[count($postid) - 1]) != $post['ID']) {
+                            $postid[] = $post['ID'];
+                            $arrf = pathinfo($post['guid']);
+                            $file = $arrf['basename'];
+                            var_dump($file.'<br/>');
+                            $file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
+                            $pic[] = $file;
+                        }
 					}
 				}
@@ -2367,4 +2381,6 @@
 				$im1['postid'] = implode(',', $postid);
 				$images = serialize($im1);
+                var_dump('NEU:'.$images.'<br/>');
+                //die($images);
 				// Update WPSG_TBL_PRODUCTS_VARIATION
 				$data = array('images' => $images);
@@ -2372,4 +2388,5 @@
 				
 			}
+            //die();
 		}	// public function produkt_save(&$produkt_id)
 		
Index: /mods/wpsg_mod_productvariants.class.ppp
===================================================================
--- /mods/wpsg_mod_productvariants.class.ppp	(revision 6427)
+++ /mods/wpsg_mod_productvariants.class.ppp	(revision 6427)
@@ -0,0 +1,2379 @@
+<?php
+
+	/**
+	 * Modulklasse "Produktvarianten"
+	 * @author Daschmi (27.04.2016)
+	 */
+	class wpsg_mod_productvariants extends wpsg_mod_basic
+	{
+
+		var $lizenz = 1;
+		var $id = 99;
+
+		const TYPE_SELECT = 0;
+		const TYPE_RADIO = 1;
+		const TYPE_IMAGE = 2;
+
+		static $arTypeLabel;
+
+		/**
+		 * Constructor
+		 */
+		public function __construct()
+		{
+
+			parent::__construct();
+
+			self::$arTypeLabel = array(
+				self::TYPE_SELECT => __('Select Box', 'wpsg'),
+				self::TYPE_RADIO => __('Radio Boxen', 'wpsg'),
+				self::TYPE_IMAGE => __('Bilderauswahl', 'wpsg')
+			);
+
+			$this->name = __('Produktvarianten', 'wpsg');
+			$this->group = __('Produkte', 'wpsg');
+			$this->desc = __('ErmÃ¶glicht es zentral Varianten anzulegen und diese im Produkt zu aktivieren.', 'wpsg');
+
+			wpsg_define('WPSG_TBL_VARIANTS', $this->shop->prefix.'wpsg_variants');
+			wpsg_define('WPSG_TBL_VARIANTS_VARI', $this->shop->prefix.'wpsg_variants_vari');
+			wpsg_define('WPSG_TBL_PRODUCTS_VARIANT', $this->shop->prefix.'wpsg_products_variant');
+			wpsg_define('WPSG_TBL_PRODUCTS_VARIATION', $this->shop->prefix.'wpsg_products_variation');
+
+		} // public function __construct()
+
+		public function install()
+		{
+
+			require_once(WPSG_PATH_WP.'/wp-admin/includes/upgrade.php');
+
+			$sql = "CREATE TABLE ".WPSG_TBL_VARIANTS." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				name varchar(255) NOT NULL,
+				product_id int(11) NOT NULL,
+				deleted int(1) NOT NULL,
+				pos int(11) NOT NULL,
+				type int(11) NOT NULL,
+				PRIMARY KEY  (id),
+				KEY product_id (product_id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+			$sql = "CREATE TABLE ".WPSG_TBL_VARIANTS_VARI." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				variant_id int(11) NOT NULL,
+				name varchar(255) NOT NULL,
+				shortname varchar(255) NOT NULL,
+				anr varchar(255) NOT NULL,
+				price double(10,2) NOT NULL,
+				stock int(11) NOT NULL,
+				images text NOT NULL,
+				deleted int(1) NOT NULL,
+				pos int(11) NOT NULL,
+				PRIMARY KEY  (id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+			$sql = "CREATE TABLE ".WPSG_TBL_PRODUCTS_VARIANT." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				variant_id int(11) NOT NULL,
+				product_id int(11) NOT NULL,
+				pos int(11) NOT NULL,
+				PRIMARY KEY  (id),
+				KEY product_id (product_id),
+				KEY variant_id (variant_id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+			$sql = "CREATE TABLE ".WPSG_TBL_PRODUCTS_VARIATION." (
+				id int(11) NOT NULL AUTO_INCREMENT,
+				variation_id int(11) NOT NULL,
+				product_id int(11) NOT NULL,
+				active int(1) NOT NULL,
+				anr varchar(255) NOT NULL,
+				price double(10,2) NOT NULL,
+				stock int(11) NOT NULL,
+				images text NOT NULL,
+				weight double(10,2) NOT NULL,
+				fmenge double(10,2) NOT NULL,
+				PRIMARY KEY  (id),
+				KEY product_id (product_id),
+				KEY variation_id (variation_id)
+			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
+
+			dbDelta($sql);
+
+		} // public function install()
+
+		public function settings_edit()
+		{
+
+			$this->shop->view['wpsg_mod_productvariants']['html'] = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_html.phtml', false);
+
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/settings_edit.phtml');
+
+		} // public function settings_edit_afterform()
+
+		public function settings_save()
+		{
+
+			$this->shop->update_option('wpsg_mod_productvariants_price', $_REQUEST['wpsg_mod_productvariants_price']);
+			$this->shop->update_option('wpsg_vp_detailview', $_REQUEST['wpsg_vp_detailview']);
+
+		} // public function settings_save()
+
+		public function be_ajax()
+		{
+
+			$action = $_REQUEST['subaction'].'Action';
+
+			$this->$action();
+
+		} // public function be_ajax()
+
+		public function wpsg_enqueue_scripts()
+		{
+
+			if (!is_admin())
+			{
+
+				wp_enqueue_script('wpsg_mod_productvariants_js', $this->shop->getRessourceURL('mods/mod_productvariants/frontend.js'));
+				wp_localize_script('wpsg_mod_productvariants_js', 'wpsg_vp_showpic', array('wpsg_vp_showpic' => $this->shop->get_option('wpsg_vp_showpic')));
+
+			}
+
+		} // public function wpsg_enqueue_scripts()
+
+		public function product_addedit_content(&$product_content, &$product_data)
+		{
+
+			// Wenn eine Ãbersetzung bearbeitet wird, dann nichts machen
+			if (isset($_REQUEST['wpsg_lang'])) return;
+
+			if (wpsg_isSizedInt($product_data['id']))
+			{
+
+				$this->shop->view['wpsg_mod_productvariants']['html'] = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_html.phtml', false);
+
+			}
+
+			$product_content['wpsg_mod_productvariants'] = array(
+				'title' => __('Produktvarianten', 'wpsg'),
+				'content' => $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt_addedit_content.phtml', false)
+			);
+
+		} // public function product_addedit_content(&$product_content, &$produkt_data)
+
+		public function template_redirect()
+		{
+
+			if (wpsg_isSizedString($_REQUEST['action'], 'wpsg_productvariants_switch'))
+			{
+
+				if (wpsg_isSizedInt($_REQUEST['wpsg_post_id']))
+				{
+
+					global $post;
+					$post = get_post($_REQUEST['wpsg_post_id']);
+
+				}
+
+				// Produkt Key nach der Auswahl bilden
+				parse_str($_REQUEST['form_data'], $form_data);
+
+				$product_id = $this->shop->getProduktId($form_data['wpsg']['produkt_id']);
+                $product_key = '';
+
+                $this->getProductKeyFromRequest($product_key, $product_id, $form_data);
+                //$product_key = $_REQUEST['product_key'];
+
+				$product_data = $this->shop->loadProduktArray($product_id, array(
+					'id' => $product_key,
+					'product_key' => $product_key,
+					'menge' => $form_data['wpsg']['menge'],
+					'referer' => $form_data['myReferer']
+				));
+
+				// Damit das Div die gleiche Index Id bekommt
+				$GLOBALS['wpsg_produkt_index'] = $_REQUEST['product_index'] - 1;
+
+				$this->shop->noReleatedProducts = true;
+
+				if (wpsg_isSizedString($form_data['wpsg']['template'])) $template = $form_data['wpsg']['template'];
+				else $template = false;
+
+				if (wpsg_isSizedInt($form_data['titleDisplayed'])) $this->shop->titleDisplayed = 1;
+
+				die($this->shop->renderProdukt($product_data, $template));
+
+			}
+
+		} // public function template_redirect()
+
+		public function loadProduktArray(&$product_data)
+		{
+
+			//if ($GLOBALS['step'] > 4) return;
+
+			$product_data['arVariant'] = $this->getVariants($product_data['product_id'], true, true, true);
+			$this->unserializeVariant($product_data['arVariant']);
+
+			if (wpsg_isSizedArray($product_data['arVariant']))
+			{
+
+				// Default Kombination setzen
+                if (preg_match('/^pv_/', $product_data['id']))
+                {
+
+                    $product_data['product_key'] = $product_data['id'];
+
+                }
+				else if (!isset($product_data['product_key']) || is_numeric($product_data['product_key']))
+				{
+
+					$arDefaultKey = array();
+
+					foreach ($product_data['arVariant'] as $variant_id => $variant_data)
+					{
+
+						$arDefaultKeyValues = $variant_id.':'.array_keys($variant_data['arVariation'])[0];
+						$arDefaultKey[] = $arDefaultKeyValues;
+
+					}
+
+					$strDefaultKey = 'pv_'.$product_data['id'].'|'.implode('|', $arDefaultKey);
+
+					$product_data['product_key'] = $strDefaultKey;
+					$product_data['id'] = $strDefaultKey;
+
+				}
+
+				$arProductKey = $this->explodeProductKey($product_data['product_key']);
+
+				$arProductImagesPossible = array();
+				$arPostidsImagesPossible = array();
+				
+				// Gesetzte Variante wÃ€hlen und aufwerten
+				foreach ($product_data['arVariant'] as $var_id => $var_data)
+				{
+
+					foreach ($var_data['arVariation'] as $vari_id => $vari_data)
+					{
+
+						if ($arProductKey['arVari'][$var_id] == $vari_id)
+						{
+
+							$pics = unserialize($vari_data['images']);
+							unset($vari_data['pics']);
+							if (wpsg_isSizedArray($pics)) {
+								$pic = explode(',', $pics['pic']);
+								if (strlen($pic[0]) == 0) unset($pic[0]);
+								$postids = explode(',', $pics['postid']);
+								if (strlen($postids[0]) == 0) unset($postids[0]);
+								//$vari_data['images'] = array('pic' => array());
+								//$vari_data['images']['pic'] = $pic;
+								foreach ($pic as $k => &$file) {
+									$file = preg_replace('/\-(\d+)x(\d+)\./', '.', $file);
+								}
+								$vari_data['pics'] = $pic;
+								$vari_data['postids'] = $postids;								
+							}
+
+							if (isset($vari_data['pics'])) {
+								if (wpsg_isSizedArray($arProductImagesPossible)) $arProductImagesPossible = array_intersect($arProductImagesPossible, $vari_data['pics']);
+								else if (wpsg_isSizedArray($vari_data['pics'])) $arProductImagesPossible = $vari_data['pics'];
+
+							}
+							if (isset($vari_data['postids'])) {
+								if (wpsg_isSizedArray($arPostidsImagesPossible)) $arPostidsImagesPossible = array_intersect($arPostidsImagesPossible, $vari_data['postids']);
+								else if (wpsg_isSizedArray($vari_data['postids'])) $arPostidsImagesPossible = $vari_data['postids'];
+								
+							}
+							
+							$product_data['arVariant'][$var_id]['arVariation'][$vari_id]['set'] = true;
+
+						}
+						else $product_data['arVariant'][$var_id]['arVariation'][$vari_id]['set'] = false;
+
+					}
+
+				}
+
+				if (wpsg_isSizedArray($arPostidsImagesPossible)) $product_data['image_postid'] = array_shift($arPostidsImagesPossible);
+				
+				if (wpsg_isSizedArray($arProductImagesPossible)) $product_data['image_show'] = array_shift($arProductImagesPossible);
+				if (wpsg_isSizedString($product_data['image_show']))
+					$product_data['image_show'] = sanitize_file_name($product_data['image_show']);
+					
+				// Preise fÃŒr die Varianten berechnen
+				if (!(isset($product_data['varPriceAdded']) && ($product_data['varPriceAdded'] = 1)))
+				{
+
+					$product_data['preis_netto_preVariants'] = $product_data['preis_netto'];
+					$product_data['preis_brutto_preVariants'] = $product_data['preis_brutto'];
+
+					if ($this->shop->getBackendTaxView() === WPSG_BRUTTO)
+					{
+
+						$product_data['preis_brutto'] = $this->calculateVariantsPrice($product_data['preis_brutto'], $product_data['arVariant'], $product_data['product_key']);
+						$product_data['preis_netto'] = wpsg_calculatePreis($product_data['preis_brutto'], WPSG_NETTO, $product_data['mwst_value']);
+
+					}
+					else
+					{
+
+						$product_data['preis_netto'] = $this->calculateVariantsPrice($product_data['preis_netto'], $product_data['arVariant'], $product_data['product_key']);
+						$product_data['preis_brutto'] = wpsg_calculatePreis($product_data['preis_netto'], WPSG_BRUTTO, $product_data['mwst_value']);
+
+					}
+
+					$product_data['preis_preVariants'] = $product_data['preis'];
+
+				}
+
+				// Preise fÃŒr das Frontend ermitteln
+				if ($this->shop->getFrontendTaxView() === WPSG_BRUTTO)
+				{
+
+					$product_data['preis'] = $product_data['preis_brutto'];
+
+				}
+				else
+				{
+
+					$product_data['preis'] = $product_data['preis_netto'];
+
+				}
+
+			}
+			if ($product_data['preis_brutto'] == 161.00) {
+
+				$product_data['preis'] = $product_data['preis_brutto'];
+			}
+
+		} // public function loadProduktArray(&$produkt_data)
+
+        public function getProductKeyFromRequest(&$product_key, $product_id, $form_data)
+        {
+
+            //if (!wpsg_isSizedArray($form_data['wpsg_mod_productvariants'])) return false;
+
+            //foreach ($form_data['wpsg_mod_productvariants'] as $var_id => $vari_id) $form_data['wpsg_mod_productvariants'][$var_id] = $var_id.':'.$vari_id;
+            //$product_key = 'pv_'.$product_id.'|'.implode('|', $form_data['wpsg_mod_productvariants']);
+
+        	if (!wpsg_isSizedArray($form_data['wpsg_vp'])) return false;
+
+        	foreach ($form_data['wpsg_vp'] as $var_id => $vari_id) $form_data['wpsg_vp'][$var_id] = $var_id.':'.$vari_id;
+        	$product_key = 'pv_'.$product_id.'|'.implode('|', $form_data['wpsg_vp']);
+
+        } // public function getProductKeyFromRequest($product_id, $form_data)
+
+        public function produkt_ajax()
+        {
+
+        	//error_reporting(E_ALL);
+
+        	if (isset($_REQUEST['cmd']) && $_REQUEST['cmd'] == 'wpsg_vp_add')
+        	{
+        		die('wpsg_vp_add');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		$data = array(
+        				"name" => $_REQUEST['name'],
+        				"typ" => $_REQUEST['typ'],
+        				"aktiv" => "1"
+        		);
+
+        		if ($_REQUEST['typ'] == "checkbox")
+        		{
+        			$data['preis'] = "0";
+        		}
+        		else
+        		{
+        			$data['vari'] = array();
+        		}
+
+        		$vp_data[] = $data;
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		$this->shop->view['message'] = array(0, __("Variante erfolgreich angelegt.", "wpsg"));
+
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_var_reorder')
+        	{
+        		die('wpsg_var_reorder');
+        		parse_str($_REQUEST['wpsg_reorder'], $wpsg_reorder);
+
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$vp_data_neu = array();
+
+        		foreach ($wpsg_reorder['variante'] as $order)
+        		{
+
+        			if (array_key_exists($order, $vp_data))
+        			{
+
+        				$vp_data_neu[] = $vp_data[$order];
+        				unset($vp_data[$order]);
+
+        			}
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data_neu);
+
+        		$this->shop->view['message'] = array(0, __('Variantenreihenfolge gespeichert.', 'wpsg'));
+
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vari_reorder')
+        	{
+        		die('wpsg_vari_reorder');
+        		parse_str($_REQUEST['wpsg_reorder'], $wpsg_reorder);
+
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		foreach ($wpsg_reorder as $var_key => $order)
+        		{
+
+        			$var_id = preg_replace('/^variorder\_/', '', $var_key);
+
+        			wpsg_array_reorder($vp_data[$var_id]['vari'], $order);
+
+        			if (wpsg_isSizedArray($vp_data[$var_id]['lang']))
+        			{
+
+        				foreach ($vp_data[$var_id]['lang'] as $lang_key => $lang_vari)
+        				{
+
+        					wpsg_array_reorder($vp_data[$var_id]['lang'][$lang_key]['vari'], $order);
+
+        				}
+
+        			}
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		$this->shop->view['message'] = array(0, __("Variationenreihenfolge gespeichert.", "wpsg"));
+
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vp_refreh')
+        	{
+        		die('wpsg_vp_refreh');
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_del")
+        	{
+        		die('wpsg_vp_del');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		unset($vp_data[$_REQUEST['var_id']]);
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich gelÃ¶scht.", "wpsg"));
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_deaktiv")
+        	{
+        		die('wpsg_vp_deaktiv');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		if ($_REQUEST['status'] == "1")
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['aktiv'] = 1;
+        			$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich aktiviert.", "wpsg"));
+
+        		}
+        		else
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['aktiv'] = 0;
+        			$this->shop->view['message'] = array(0, __("Variante wurde erfolgreich deaktiviert.", "wpsg"));
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_addVariation")
+        	{
+        		die('wpsg_vp_addVariation');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		$vp_data[$_REQUEST['var_id']]['vari'][] = array(
+        				"name" => $_REQUEST['vari_name'],
+        				"preis" => wpsg_tf($_REQUEST['vari_preis']),
+        				"aktiv" => "1"
+        		);
+
+        		$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich angelegt.", "wpsg"));
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_vari_del")
+        	{
+        		die('wpsg_vp_vari_del');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		unset($vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]);
+
+        		if (wpsg_isSizedArray($vp_data[$_REQUEST['var_id']]['lang']))
+        		{
+
+        			foreach ($vp_data[$_REQUEST['var_id']]['lang'] as $lang_key => $lang_vari)
+        			{
+
+        				unset($vp_data[$_REQUEST['var_id']]['lang'][$lang_key]['vari'][$_REQUEST['vari_id']]);
+
+        			}
+
+        		}
+
+        		$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich gelÃ¶scht.", "wpsg"));
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == "wpsg_vp_vari_deaktiv")
+        	{
+        		die('wpsg_vp_vari_deaktiv');
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+
+        		if ($_REQUEST['status'] == "1")
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['aktiv'] = 1;
+        			$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich aktiviert.", "wpsg"));
+
+        		}
+        		else
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['aktiv'] = 0;
+        			$this->shop->view['message'] = array(0, __("Variation wurde erfolgreich deaktiviert.", "wpsg"));
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+        		die($this->drawVarianten($_REQUEST['edit_id']));
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_var_setImageOrder')
+        	{
+
+        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
+        		$this->unserializeVariant($vp_data);
+
+        		if ($_REQUEST['vari_id'] == -1)
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['picOrder'] = $_REQUEST['wpsg_reorder'];
+
+        		}
+        		else
+        		{
+
+        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['picOrder'] = $_REQUEST['wpsg_reorder'];
+
+        		}
+
+        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
+
+        		die("1");
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vp_vari_setPic')
+        	{
+        		//die('wpsg_vp_vari_setPic');
+        		//$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$vp_data = $this->getVariants($_REQUEST['edit_id'], true, true, true);
+        		$this->unserializeVariant($vp_data);
+
+        		if ($_REQUEST['vari_id'] >= 0)
+        		{
+
+        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic']);
+        			$arPostid = explode(",", $vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid']);
+
+        			$pic = $_REQUEST['pic'];
+        			$postid = $_REQUEST['post_id'];
+
+        			$pic = preg_replace('/\-(\d+)x(\d+)\./', '.', $pic);
+
+        			if (in_array($pic, $arPic))
+        			{
+        				unset($arPic[array_search($pic, $arPic)]);
+        				unset($arPostid[array_search($postid, $arPostid)]);
+        			}
+        			else
+        			{
+        				$arPic[] = $pic;
+        				$arPostid[] = $postid;
+        			}
+
+        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['pic'] = implode(",", $arPic);
+        			$vp_data[$_REQUEST['var_id']]['arVariation'][$_REQUEST['iid']]['postid'] = implode(",", $arPostid);
+
+        		}
+        		else
+        		{
+
+        			$arPic = explode(",", $vp_data[$_REQUEST['var_id']]['pic']);
+
+        			if (in_array($_REQUEST['pic'], $arPic))
+        			{
+        				unset($arPic[array_search($_REQUEST['pic'], $arPic)]);
+        			}
+        			else
+        			{
+        				$arPic[] = $_REQUEST['pic'];
+        			}
+
+        			$vp_data[$_REQUEST['var_id']]['pic'] = implode(",", $arPic);
+
+        		}
+
+        		$this->saveVariation($_REQUEST['edit_id'], $vp_data);
+
+        		die("1");
+
+        	}
+        	else if ($_REQUEST['cmd'] == 'wpsg_vp_vari_inlineEdit')
+        	{
+        		die('wpsg_vp_vari_inlineEdit');
+
+        		$vp_data = $this->loadVarianten($_REQUEST['edit_id']);
+        		$product_data = $this->shop->cache->loadProduct($_REQUEST['edit_id']);
+
+        		if ($_REQUEST['typ'] == "vari_name")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['vari'][$_REQUEST['vari_id']]['name'] = wpsg_q($_REQUEST['value']);
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['name'] = wpsg_q($_REQUEST['value']);
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_artnr")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['vari'][$_REQUEST['vari_id']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_preis")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['preis'] = $_REQUEST['value'];
+        			$_REQUEST['value'] = wpsg_ff($_REQUEST['value'], $this->shop->get_option('wpsg_currency'));
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_fmenge")
+        		{
+
+        			$arFeinheiten = explode(',', $this->shop->get_option('wpsg_mod_fuellmenge_einheit'));
+
+        			$_REQUEST['value'] = wpsg_ff(wpsg_tf($_REQUEST['value']), $arFeinheiten[$product_data['feinheit']]);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['fmenge'] = wpsg_tf($_REQUEST['value']);
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_weight")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['weight'] = $_REQUEST['value'];
+
+        		}
+        		else if ($_REQUEST['typ'] == "vari_stock")
+        		{
+
+        			$_REQUEST['value'] = intval($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['stock'] = $_REQUEST['value'];
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_name")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['name'] = $_REQUEST['value'];
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['name'] = $_REQUEST['value'];
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_preis")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['preis'] = $_REQUEST['value'];
+        			$_REQUEST['value'] = wpsg_ff($_REQUEST['value'], $this->shop->get_option('wpsg_currency'));
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_weight")
+        		{
+
+        			$_REQUEST['value'] = wpsg_tf($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['weight'] = $_REQUEST['value'];
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_fmenge")
+        		{
+
+        			$arFeinheiten = explode(',', $this->shop->get_option('wpsg_mod_fuellmenge_einheit'));
+
+        			$_REQUEST['value'] = wpsg_ff(wpsg_tf($_REQUEST['value']), $arFeinheiten[$product_data['feinheit']]);
+        			$vp_data[$_REQUEST['var_id']]['fmenge'] = wpsg_tf($_REQUEST['value']);
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_artnr")
+        		{
+
+        			if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        			{
+        				$vp_data[$_REQUEST['var_id']]['lang'][$_REQUEST['wpsg_lang']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+        			else
+        			{
+        				$vp_data[$_REQUEST['var_id']]['artnr'] = wpsg_q($_REQUEST['value']);
+        			}
+
+        		}
+        		else if ($_REQUEST['typ'] == "var_stock")
+        		{
+
+        			$_REQUEST['value'] = intval($_REQUEST['value']);
+        			$vp_data[$_REQUEST['var_id']]['stock'] = $_REQUEST['value'];
+
+        		}
+
+        		$this->saveVarianten($_REQUEST['edit_id'], $vp_data);
+
+        		die(strval($_REQUEST['value']));
+
+        	}
+
+        } // public function produkt_ajax()
+
+		/**
+		 * Darf das Produkt gekauft werden?
+		 */
+		public function canOrder($product_key)
+		{
+
+			$product_id = $this->shop->getProduktID($product_key);
+
+			if ($this->isVariantsProduct($product_id))
+			{
+
+				$nActive = 0;
+
+				$variants = $this->getVariants($product_id);
+
+				foreach ($variants as $var_id => $var_info)
+				{
+
+					$nActive += $var_info['count_active'];
+
+				}
+
+				if ($nActive <= 0) return -2;
+
+			}
+
+		}
+
+		/* Modulfunktionen */
+
+		/**
+		 * Gibt den Bestand fÃŒr eine Variation zurÃŒck
+		 * @var $product_key String
+		 * Beispiel: pv_1|1:1
+		 *
+		 * Wird vom Lagerbestandsmodul aufgerufen, sollte NUR mit einem VariantenschlÃŒssel aufgerufen werden
+		 */
+		public function getStockForVariation($product_key)
+		{
+
+			$arVariInfo = $this->explodeProductKey($product_key);
+			$oProduct = wpsg_product::getInstance($arVariInfo['product_id']);
+
+			if (!wpsg_isSizedArray($arVariInfo['arVari'])) return $oProduct->stock;
+			else
+			{
+
+				$nStock = 0;
+				$variConf = $this->getVariants($arVariInfo['product_id'], true, true, true);
+
+				foreach ($arVariInfo['arVari'] as $var_id => $vari_id)
+				{
+
+					$nStock += $variConf[$var_id]['arVariation'][$vari_id]['stock'];
+
+				}
+
+				return $nStock;
+
+			}
+
+		} // public function getStockForVariation($product_key)
+
+        /**
+         * Speichert die Varianten
+         */
+        public function saveVarianten($produkt_id, $vp_data)
+        {
+
+        	$vp_data = $this->clearArrayForSerialization($vp_data);
+
+        	$temp = wpsg_q(serialize($vp_data));
+        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+        		"images" => wpsg_q(serialize($vp_data))
+        	), "`id` = '".wpsg_q($_REQUEST['vari_id'])."'");
+
+        } // public function saveVarianten($produkt_id, $vp_data)
+
+        /**
+         * Speichert die Variationen
+         */
+        public function saveVariation($produkt_id, $vp_data)
+        {
+
+        	$vp_data = $this->clearArrayForSerialization($vp_data);
+
+        	$temp = wpsg_q(serialize($vp_data));
+        	$vdata['pic'] = '';
+        	if (isset($vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic']))
+        		$vdata['pic'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['pic'];
+        	$vdata['picOrder'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['picOrder'];
+        	$vdata['postid'] = $vp_data[wpsg_q($_REQUEST['var_id'])]['arVariation'][wpsg_q($_REQUEST['iid'])]['postid'];
+
+        	$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+        			"images" => wpsg_q(serialize($vdata))
+        	), "`variation_id` = '".wpsg_q($_REQUEST['vari_id'])."'");
+
+        } // public function saveVariation($produkt_id, $vp_data)
+
+        /**
+         * LÃ€dt die Varianteninformationen aus dem serialisierten Array
+         * @param $noTrans Wird diese Variable auf true gesetzt, so wird die Ãbersetzung nicht geladen (Wie Backend) Wichtig wenn die Varianten wieder gespeichert werden sollen!
+         */
+        public function loadVarianten($produkt_id, $noTrans = false, $noCache = false)
+        {
+
+        	if (is_admin()) $noCache = true;
+
+        	if (!$noCache && array_key_exists($produkt_id.$noTrans, wpsg_getArray($this->cache_variData))) return $this->cache_variData[$produkt_id.$noTrans];
+
+        	// Ãbersetzung verarbeiten
+        	if (is_admin() || $noTrans === true)
+        	{
+
+        		//$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($produkt_id)."'"));
+        		$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($_REQUEST['vari_id'])."'"));
+        		if (!is_array($vp_data)) $vp_data = array();
+
+        	}
+        	else
+        	{
+
+        		// Im Frontend geht es nach der Sprache auf der der Shop aktuell lÃ€uft
+        		if ($this->shop->isOtherLang())
+        		{
+
+        			$parent_lang_id = $this->db->fetchOne("SELECT `lang_parent` FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($produkt_id)."'");
+        			if (!wpsg_isSizedInt($parent_lang_id)) $parent_lang_id = $produkt_id;
+
+        			$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($parent_lang_id)."'"));
+        			if (!is_array($vp_data)) $vp_data = array();
+
+        			foreach ($vp_data as $k => $v)
+        			{
+
+        				// Den Namen der Variante auf die aktuelle Sprache stellen
+        				if (wpsg_isSizedString($vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['name'])) $vp_data[$k]['name'] = $vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['name'];
+
+        				if (wpsg_isSizedArray($vp_data[$k]['vari']))
+        				{
+
+        					foreach ($vp_data[$k]['vari'] as $k2 => $vari)
+        					{
+
+        						// Den Namen der Variation auf die aktuelle Sprache korrigieren
+        						if (wpsg_isSizedString($vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['vari'][$k2]['name'])) $vp_data[$k]['vari'][$k2]['name'] = $vp_data[$k]['lang'][$this->shop->getCurrentLanguageCode()]['vari'][$k2]['name'];
+
+        					}
+
+        				}
+
+        			}
+
+        		}
+        		else
+        		{
+
+        			if (isset($_REQUEST['vari_id']))
+					{
+
+        				$vp_data = @unserialize($this->db->fetchOne("SELECT `images` FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `id` = '".wpsg_q($_REQUEST['vari_id'])."'"));
+        				if (!is_array($vp_data)) $vp_data = array();
+
+        			}
+        			else
+        			{
+
+        				$strQuery =
+        				"SELECT PVV.`id`, PVV.`variation_id`, PVV.`product_id`, PVV.`anr`, PVV.`price`, PVV.`stock`, PVV.`images`, PVV.`weight`, PVV.`fmenge`, PVV.`active`,
+        				 VV.`variant_id`, VV.`name` AS VVname, VV.`shortname`, PV.`pos` AS PVpos, VV.`pos` AS VVpos,
+        				 V.`name` AS Vname, V.`type`
+        				 FROM ".WPSG_TBL_VARIANTS." AS V, ".WPSG_TBL_VARIANTS_VARI." AS VV,
+        				 ".WPSG_TBL_PRODUCTS_VARIATION." AS PVV, ".WPSG_TBL_PRODUCTS_VARIANT." AS PV
+        				 WHERE V.`id` = VV.`variant_id` AND VV.`id` = PVV.`variation_id` AND PV.`variant_id` = VV.`variant_id` AND
+        				 PVV.`product_id` = '".wpsg_q($produkt_id)."' AND VV.`deleted` != 1 AND V.`deleted` != 1
+        				 ORDER BY PV.`pos`, VV.`pos`";
+
+        				//$vp_data = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id` = '".wpsg_q($produkt_id)."'");
+        				$vp_data = $this->db->fetchAssoc($strQuery);
+        				if (!is_array($vp_data)) $vp_data = array();
+        				$this->unserializeVariation($vp_data);
+
+        			}
+
+        		}
+
+        	}
+
+        	$this->cache_variData[$produkt_id.$noTrans] = $vp_data;
+
+        	return $vp_data;
+
+        } // public function loadVarianten($produkt_id)
+
+        private function clearArrayForSerialization($ar)
+        {
+
+        	foreach ((array)$ar as $k => $v)
+        	{
+
+        		if (wpsg_isSizedArray($v))
+        		{
+
+        			$ar[$k] = $this->clearArrayForSerialization($v);
+
+        		}
+        		else
+        		{
+
+        			$ar[$k] = preg_replace('/\'|\`|\ÂŽ|\"/', '', $v);
+
+        		}
+
+        	}
+
+        	return $ar;
+
+        } // private function clearArrayForSerialization($ar)
+
+        /**
+         * Gibt die Bilder als Array fÃŒr die Variation zurÃŒck
+         * Beachtet die Reihenfolge die im Backend ÃŒber Drag&Drop definiert ist
+         * @param int $var_id Key der Variante
+         * @param int $vari_id Key der Variation
+         */
+        public function getVariImages($product_id, $var_id, $vari_id)
+        {
+
+        	$_REQUEST['var_id'] = $var_id;
+        	$_REQUEST['vari_id'] = $vari_id;
+
+        	//$vp_data = $this->loadVarianten($product_id);
+        	$vp_data = $this->getVariants($product_id, true, true, true);
+        	$this->unserializeVariant($vp_data);
+
+        	$arProductBilder = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
+
+        	$arReturn = array();
+
+        	if (!isset($vp_data[$var_id])) return $arProductBilder;
+        	//if (!wpsg_isSizedArray($vp_data[$var_id]['vari'][$vari_id]['picOrder']) && !wpsg_isSizedArray($vp_data[$var_id]['picOrder'])) return $arProductBilder;
+        	if (!wpsg_isSizedArray($vp_data[$var_id]['arVariation'][$vari_id]['picOrder'])) return $arProductBilder;
+
+        	// Sortierung
+        	// Bilder in Reihenfolge von picOrder
+        	if (isset($vp_data[$var_id]['typ']) && ($vp_data[$var_id]['typ'] == 'checkbox') && wpsg_isSizedArray($vp_data[$var_id]['picOrder'])) $arReturn = $vp_data[$var_id]['picOrder'];
+        	else if (wpsg_isSizedArray($vp_data[$var_id]['arVariation'][$vari_id]['picOrder'])) $arReturn = $vp_data[$var_id]['arVariation'][$vari_id]['picOrder'];
+
+        	/*
+        	// PrÃŒfen ob die Bilder noch in Produktbilder Array drin sind
+        	foreach ($arReturn as $k => $v)
+        	{
+
+        		if (!in_array($v, $arProductBilder)) unset($arReturn[$k]);
+        		else unset($arProductBilder[array_search($v, $arProductBilder)]);
+
+        	}
+        	*/
+
+        	$arProductBilderSort = Array();
+        	foreach ($arProductBilder as $v) {
+        		$k = array_search($v['basenameori'], $arReturn);
+        		if ($k !== false)
+        			$arProductBilderSort[$k] = $v;
+
+        	}
+        	ksort($arProductBilderSort);
+
+        	// Bilder aus dem ProduktArray noch hinzufÃŒgen, die eventuell nicht im sortierten Array enthalten sind
+        	foreach ($arProductBilder as $k => $v)
+        	{
+
+        		//$arReturn[] = $v['basenameori'];
+        		$k = array_search($v['basenameori'], $arReturn);
+        		if ($k === false)
+        			$arProductBilderSort[] = $v;
+
+        	}
+        	//$arReturn = array_unique($arReturn);
+
+        	$arImageSelect = array();
+
+        	// Sind die Bilder in der Variante ausgewÃ€hlt?
+        	if (!is_admin())
+        	{
+
+        		//if ($vp_data[$var_id]['typ'] == 'checkbox' && wpsg_isSizedString($vp_data[$var_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['pic']);
+        		if ($vp_data[$var_id]['type'] == '3' && wpsg_isSizedString($vp_data[$var_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['pic']);
+        		else if (wpsg_isSizedString($vp_data[$var_id]['arVariation'][$vari_id]['pic'])) $arImageSelect = explode(',', $vp_data[$var_id]['arVariation'][$vari_id]['pic']);
+
+        		foreach ($arReturn as $k => $v)
+        		{
+
+        			if (!in_array($v, $arImageSelect)) unset($arReturn[$k]);
+
+        		}
+
+        	}
+
+        	//return $arReturn;
+        	return $arProductBilderSort;
+
+        } // public function getVariImages($product_id, $var_id, $vari_id)
+
+        /**
+         * Gibt den Namen der Variante zurÃŒck
+         */
+        public function getVariantenName($vp_data, $var_id)
+        {
+
+        	$name = $vp_data[$var_id]['name'];
+
+        	if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        	{
+        		if ($vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['name'] != "")
+        		{
+        			$name = $vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['name'];
+        		}
+        	}
+
+        	return ((trim($name) == "")?"----":$name);
+
+        } // public function getVariantenName($vp_data, $v_id)
+
+        /**
+         * Gibt den Namen der Variation zurÃŒck
+         */
+        public function getVariName($vp_data, $var_id, $vari_id)
+        {
+
+        	$name = $vp_data[$var_id]['arVariation'][$vari_id]['name'];
+
+        	if (wpsg_isSizedString($_REQUEST['wpsg_lang']))
+        	{
+        		if ($vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['arVariation'][$vari_id]['name'] != "")
+        		{
+        			$name = $vp_data[$var_id]['lang'][$_REQUEST['wpsg_lang']]['arVariation'][$vari_id]['name'];
+        		}
+        	}
+
+        	return ((trim($name) == "")?"----":$name);
+
+        } // public function getVariName($vp_data, $var_id, $vari_id)
+
+		/**
+		 * PrÃŒft ob das Produkt ein Variantenprodukt ist oder nicht
+		 */
+		public function isVariantsProduct($product_id)
+		{
+
+			$strQuery = "
+					SELECT
+						COUNT(*)
+					FROM
+						`".WPSG_TBL_VARIANTS_VARI."` AS VI
+							LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+					WHERE
+						PVI.`product_id` = '".wpsg_q($product_id)."' AND
+						PVI.`active` = '1' AND
+						VI.`deleted` != '1'
+			";
+
+			$nActiveVariants = $this->db->fetchOne($strQuery);
+
+			if ($nActiveVariants > 0) return true; else return false;
+
+		} // public function isVariantsProduct($product_id)
+
+		/**
+		 * Integration in das Produkttemplate
+		 */
+		public function productTemplate($product_data)
+		{
+
+			die("Veraltet");
+
+			if (!wpsg_isSizedArray($product_data['arVariant'])) return;
+
+			$this->shop->view['wpsg_mod_productvariants']['product_id'] = $product_data['product_id'];
+			$this->shop->view['wpsg_mod_productvariants']['arVariants'] = $product_data['arVariant'];
+			$this->shop->view['wpsg_mod_productvariants']['product_variants'] = $this->explodeProductKey($product_data['product_key'])['arVari'];
+
+			$this->shop->render(WPSG_PATH_VIEW.'mods/mod_productvariants/productTemplate.phtml');
+
+		} // public function productTemplate($product_key)
+
+		/**
+		 * Ãbernimmt die Auswahl der Variante im Produkttemplate
+		 */
+		public function renderTemplate($product_key)
+		{
+
+			$produkt_id = $this->shop->getProduktId($product_key);
+			$produkt_data = $this->shop->cache->loadProduct($produkt_id);
+			$tax_value = $this->shop->getCalcTaxValue($produkt_data['mwst_key']);
+
+			if ($this->shop->isOtherLang())
+			{
+
+				$produkt_trans_id = $this->db->fetchOne("SELECT `id` FROM `".WPSG_TBL_PRODUCTS."` WHERE `lang_parent` = '".wpsg_q($produkt_id)."' AND `lang_locale` = '".wpsg_q($this->shop->getCurrentLanguageCode())."'");
+
+				if (wpsg_isSizedInt($produkt_trans_id)) $produkt_id = $produkt_trans_id;
+
+			}
+
+			//public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false)
+			$vp_data = $this->getVariants($produkt_id, true, true, true);
+			$this->unserializeVariant($vp_data);
+
+			if ($this->isVariantsProductKey($product_key)) {
+				$arVar = $this->explodeProductKey($product_key);
+				foreach ($arVar['arVari'] as $v => $vv) {
+					$vp_data[$v]['arVariation'][$vv]['sel'] = 1;
+
+				}
+
+			}
+
+			if (is_array($vp_data) && sizeof($vp_data) > 0)
+			{
+
+				$arpb = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array(&$produkt_id));
+
+				//$this->shop->view['data']['vp_data'] = $vp_data;
+				$this->shop->view['wpsg_mod_productvariants']['set'] = $this->getSetVariArray($product_key);
+
+				// Rabattpreise vorkalkulieren
+				//$this->shop->callMod('wpsg_mod_discount', 'addDiscountToVari', array(&$produkt_id, &$this->shop->view['data']['vp_data']));
+
+				$arPossibleImages = array();
+
+				// Bilddaten ergÃ€nzen
+				foreach ($vp_data as $k1 => &$v1) {
+					foreach ($v1['arVariation'] as $k2 => &$v2) {
+						$arpic = explode(',', $v2['pic']);
+						$v2['showpic'] = '';
+						if (wpsg_isSizedArray($v2['picOrder'])) {
+							// Bilder umsortiert, Reihenfolge checken
+							$k = 5000;
+							foreach ($arpic as $ap)
+								foreach ($v2['picOrder'] as $kp => $vp) {
+									if ($ap == $vp)
+										if ($kp < $k) $k = $kp;
+
+								}
+							$v2['showpic'] = $v2['picOrder'][$k];
+						}
+						else
+						{
+							$max = sizeof($arpic);
+							if (isset($arpic[$max - 1]))
+								$v2['showpic'] = $arpic[$max - 1];		// 1 wegen Komma am Anfang
+						}
+						$found = -1;
+						$v2['guid'] = '';
+						$v2['post_id'] = 0;
+						foreach ($arpb as $k3 => $v3) {
+							if ($v2['showpic'] === $v3['basenameori']) $found = $k3;
+						}
+						if ($found != -1) {
+							$v2['guid'] = $arpb[$found]['guid'];
+							$v2['post_id'] = $arpb[$found]['post_id'];
+						}
+
+					}
+				}
+
+				unset($v1);
+				unset($v2);
+
+				$this->shop->view['data']['vp_data'] = $vp_data;
+
+				foreach ($this->shop->view['data']['vp_data'] as $k => $v)
+				{
+
+					if ($v['typ'] == "checkbox")	// 0 = checkbox
+					{
+
+						if (get_option("wpsg_vp_showpic") == "1" && wpsg_isSizedString($v['pic']))
+						{
+
+							//$this->shop->view['data']['vp_data'][$k]['showpic'] = $this->getImageSelectImage($produkt_id, $k, $k2, $product_key);
+
+						}
+
+						// Preis an Ausgabe im Frontend anpassen
+						//if ($this->shop->getFrontendTaxview() == WPSG_NETTO && $this->shop->getBackendTaxview() == WPSG_BRUTTO) $this->shop->view['data']['vp_data'][$k]['preis'] = wpsg_calculatePreis($v['preis'], WPSG_NETTO, $tax_value);
+						//else if ($this->shop->getFrontendTaxview() == WPSG_BRUTTO && $this->shop->getBackendTaxview() == WPSG_NETTO) $this->shop->view['data']['vp_data'][$k]['preis'] = wpsg_calculatePreis($v['preis'], WPSG_BRUTTO, $tax_value);
+
+					}
+					else
+					{
+
+						foreach ($v['arVariation'] as $k2 => $v2)
+						{
+
+							if (get_option("wpsg_vp_showpic") == "1" && wpsg_isSizedString($v2['pic']))
+							{
+
+								//$this->shop->view['data']['vp_data'][$k]['vari'][$k2]['showpic'] = $this->getImageSelectImage($produkt_id, $k, $k2, $product_key);
+
+							}
+
+							// Preis an Ausgabe im Frontend anpassen
+							if ($this->shop->getFrontendTaxview() == WPSG_NETTO && $this->shop->getBackendTaxview() == WPSG_BRUTTO) $this->shop->view['data']['vp_data'][$k]['arVariation'][$k2]['price'] = wpsg_calculatePreis($v2['price'], WPSG_NETTO, $tax_value);
+							else if ($this->shop->getFrontendTaxview() == WPSG_BRUTTO && $this->shop->getBackendTaxview() == WPSG_NETTO) $this->shop->view['data']['vp_data'][$k]['arVariation'][$k2]['price'] = wpsg_calculatePreis($v2['price'], WPSG_BRUTTO, $tax_value);
+
+						}
+
+					}
+
+				}
+
+				return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/produkt.phtml', false);
+
+			}
+
+		} // public function renderTemplate($produkt_id)
+
+		/**
+		 * Gibt ein Array mit Informationen aus dem VariantenschlÃŒssel zurÃŒck
+		 * Besp: pv_1|1:1
+		 * Array
+			(
+    			[product_id] => 1
+    			[arVari] => Array
+		 		(
+            		[1] => 1
+        		)
+
+			)
+		 * Anhand des ProduktschlÃŒssels z.B. pv|4:6|1:8|6:11|5:10
+		 */
+		public function explodeProductKey($product_key)
+		{
+
+			if (is_numeric($product_key)) return array(
+				'product_id' => $product_key,
+				'arVari' => array()
+			);
+
+			$arKey = explode('|', $product_key);
+			$arReturn = array();
+
+			for ($i = 1; $i < sizeof($arKey); $i ++)
+			{
+
+				$arKeyValue = explode(':', $arKey[$i]);
+				$arReturn[$arKeyValue[0]] = $arKeyValue[1];
+
+			}
+
+			return array(
+				'product_id' => substr($arKey[0], 3),
+				'arVari' => $arReturn
+			);
+
+		} // public function explodeProductKey($product_key)
+
+		/**
+		 * Gibt true zurÃŒck, wenn der Preis im Produkttemplate angezeigt werden soll
+		 * Andersrum programmiert, da die Default Einstellung anzeigen ist????
+		 */
+		public function showVariPrice($vari_price)
+		{
+
+			switch ($this->shop->get_option('wpsg_mod_productvariants_price'))
+			{
+
+				case '1': // nur wenn grÃ¶Ãer 0
+
+					if ($vari_price <= 0) return false;
+
+					break;
+
+				case '0': // nie anzeigen
+
+					return false;
+
+					break;
+
+			}
+
+			return true;
+
+		} // public function showVariPrice($vari_price)
+
+		private function calculateVariantsPrice($price, $arVariant, $product_key)
+		{
+
+			$arProductVariant = $this->explodeProductKey($product_key)['arVari'];
+
+			foreach ($arProductVariant as $variant_id => $variation_id)
+			{
+
+				$price += $arVariant[$variant_id]['arVariation'][$variation_id]['price'];
+
+			}
+
+			return $price;
+		}
+
+		private function admin_showAction()
+		{
+
+			$this->shop->view['product_id'] = $_REQUEST['product_id'];
+			$this->shop->view['arVariants'] = $this->getVariants($_REQUEST['product_id'], true);
+
+			die($this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_show.phtml'));
+
+		} // private function showAction()
+
+		private function admin_addAction()
+		{
+
+			$this->db->ImportQuery(WPSG_TBL_VARIANTS, array(
+				'name' => wpsg_q(__('', 'wpsg')),
+				'product_id' => wpsg_q($_REQUEST['product_id']),
+				'deleted' => '0',
+				'pos' => '5000'
+			));
+
+			$this->admin_showAction();
+
+		} // private function admin_addAction()
+
+		private function admin_editAction()
+		{
+
+			$this->shop->view['product_id'] = wpsg_getStr($_REQUEST['product_id'], '0');
+			$this->shop->view['variant'] = $this->getVariant($_REQUEST['variant_id']);
+			$this->shop->view['arVariation'] = $this->getVariationOfVariant($_REQUEST['variant_id'], $_REQUEST['product_id']);
+
+			die($this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/admin_edit.phtml'));
+
+		} // private function admin_editAction()
+
+		private function admin_variation_addAction()
+		{
+
+			$variation_id = $this->db->ImportQuery(WPSG_TBL_VARIANTS_VARI, array(
+				'variant_id' => wpsg_q($_REQUEST['variant_id']),
+				'name' => __('', 'wpsg'),
+				'deleted' => '0'
+			));
+
+			if (wpsg_isSizedInt($_REQUEST['product_id']))
+			{
+
+				$this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, array(
+					'variation_id' => wpsg_q($variation_id),
+					'product_id' => wpsg_q($_REQUEST['product_id'])
+				));
+
+			}
+
+			$this->admin_editAction();
+
+		} // private function admin_variation_addAction()
+
+		private function admin_delAction()
+		{
+
+			$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array(
+				'deleted' => '1'
+			), " `id` = '".wpsg_q($_REQUEST['variant_id'])."' ");
+
+			$this->admin_showAction();
+
+		} // private function admin_delAction()
+
+		private function admin_variation_delAction()
+		{
+
+			$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array(
+				'deleted' => '1'
+			), " `id` = '".wpsg_q($_REQUEST['variation_id'])."' ");
+
+			$this->admin_editAction();
+
+		} // private function admin_variation_delAction()
+
+		private function setProductVariant($product_id, $variant_id, $field, $value)
+		{
+
+			if (!wpsg_isSizedInt($product_id) || !wpsg_isSizedInt($variant_id)) die("Systemfehler");
+
+			$id_exist = $this->db->fetchOne("
+				SELECT
+					`id`
+				FROM
+					`".WPSG_TBL_PRODUCTS_VARIANT."`
+				WHERE
+					`variant_id` = '".wpsg_q($variant_id)."' AND
+					`product_id` = '".wpsg_q($product_id)."'
+			");
+
+			$data = array(
+				$field => wpsg_q($value),
+				'product_id' => wpsg_q($product_id),
+				'variant_id' => wpsg_q($variant_id)
+			);
+
+			if (wpsg_isSizedInt($id_exist)) $this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIANT, $data, " `id` = '".wpsg_q($id_exist)."' ");
+			else $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIANT, $data);
+
+		} // private function setProductVariant($product_id, $variant_id, $field, $value)
+
+		private function setProductVariation($product_id, $variation_id, $field, $value)
+		{
+
+			if (!wpsg_isSizedInt($product_id) || !wpsg_isSizedInt($variation_id)) die("Systemfehler");
+
+			$id_exist = $this->db->fetchOne("
+				SELECT
+					`id`
+				FROM
+					`".WPSG_TBL_PRODUCTS_VARIATION."`
+				WHERE
+					`variation_id` = '".wpsg_q($variation_id)."' AND
+					`product_id` = '".wpsg_q($product_id)."'
+			");
+
+			$data = array(
+				$field => wpsg_q($value),
+				'product_id' => wpsg_q($product_id),
+				'variation_id' => wpsg_q($variation_id)
+			);
+
+			if (wpsg_isSizedInt($id_exist)) $this->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, $data, " `id` = '".wpsg_q($id_exist)."' ");
+			else $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, $data);
+
+			if (($field == 'stock') || ($field == 'active'))
+			{
+				$this->setStockFromVariation($product_id);
+			}
+
+		} // private function setProductVariation($product_id, $field, $value)
+
+		private function setStockFromVariation($product_id)
+		{
+
+			if ($this->isVariantsProductKey($product_id)) {
+				$arr = $this->explodeProductKey($product_id);
+				$product_id = $arr['product_id'];
+			}
+
+			$sql = "SELECT SUM(PVI.`stock`) AS SU FROM `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI
+						LEFT JOIN `".WPSG_TBL_VARIANTS_VARI."` AS VVI ON PVI.`variation_id`= VVI.`id`
+						WHERE PVI.`product_id`='".wpsg_q($product_id)."' AND VVI.`deleted`!='1' AND PVI.`active`='1'
+				";
+			$stock = $this->db->fetchOne($sql);
+
+			$data = array('stock' => wpsg_q($stock));
+
+			$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, $data, " `id` = '".wpsg_q($product_id)."' ");
+
+			//getProductKeyFromRequest(&$product_key, $product_id, $form_data)
+			//$stock = $this->shop->callMod('wpsg_mod_productvariants', 'getStockForVariation', array());
+
+		}	// private function setStockFromVariation($product_id)
+
+		private function admin_inlineEditAction()
+		{
+
+			if (wpsg_isSizedString($_REQUEST['field'], 'name'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('name' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'type'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('type' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+				die(self::$arTypeLabel[$_REQUEST['value']]);
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'pos'))
+			{
+
+				$i = 0; foreach ($_REQUEST['value'] as $var)
+				{
+
+					$var_id = substr($var, 4);
+
+					if (wpsg_isSizedInt($_REQUEST['product_id'])) $this->setProductVariant($_REQUEST['product_id'], $var_id, 'pos', $i);
+					else $this->db->UpdateQuery(WPSG_TBL_VARIANTS, array('pos' => wpsg_q($i)), " `id` = '".wpsg_q($var_id)."' ");
+
+					$i ++;
+
+				}
+
+				die('1');
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_name'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('name' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_shortname'))
+			{
+
+				$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('shortname' => wpsg_q($_REQUEST['value'])), " `id` = '".wpsg_q($_REQUEST['field_id'])."' ");
+
+			}
+			else if (wpsg_isSizedString($_REQUEST['field'], 'vari_pos'))
+			{
+
+				$i = 0; foreach ($_REQUEST['value'] as $vari)
+				{
+
+					$vari_id = substr($vari, 5);
+
+					$this->db->UpdateQuery(WPSG_TBL_VARIANTS_VARI, array('pos' => wpsg_q($i)), " `id` = '".wpsg_q($vari_id)."' ");
+
+					$i ++;
+
+				}
+
+				die('1');
+
+			}
+			else if (preg_match('/vari_(.*)/', $_REQUEST['field']))
+			{
+				$value = $_REQUEST['value'];
+				$f = $_REQUEST['field'];
+				if (($f == 'vari_price') || ($f == 'vari_stock') || ($f == 'vari_weight')) {
+					$value =  wpsg_tf($value);
+				}
+				$this->setProductVariation($_REQUEST['product_id'], $_REQUEST['field_id'], substr($_REQUEST['field'], 5), $value);
+
+			}
+
+			// TODO: Ãbersetzung
+
+			die($_REQUEST['value']);
+
+		} // private function admin_inlineEditAction()
+
+		/**
+		 * Gibt die MÃ¶glichken Bilder einer Variantenkombination zurÃŒck
+		 */
+		public function getKombiVariImages($var_key, $var_id = false)
+		{
+
+			if (!$this->shop->hasMod('wpsg_mod_produktbilder')) return false;
+
+			$arVarSelected = $this->getSetVariArray($var_key);
+			$product_id = $this->shop->getProduktID($var_key);
+			//$arVari = $this->loadVarianten($product_id);
+			$arVari = $this->getVariants($product_id, true, true, true);
+			$this->unserializeVariant($arVari);
+
+			$arTemp = $this->shop->callMod('wpsg_mod_produktbilder', 'getProduktBilder_MT', array($product_id));
+
+			if (!$this->isVariantsProductKey($var_key)) return $arTemp;
+
+			$arBilder = array();
+			foreach ($arTemp as $bild) {
+				$arBilder[] = $bild['basenameori'];
+			}
+
+			/*
+			// Schauen ob ein Bild nach dem Dateinamen dabei ist
+			foreach ($arBilder as $bild)
+			{
+				$image = false;
+				$filename = preg_replace("/\.([^\.]*)/", "", $bild);
+				if ($filename == "vp_".str_replace(":", "-", $var_key)) $image = $bild;
+
+				if ($image !== false) return array($image);
+			}
+			*/
+			foreach ($arVari as $var_key => $var)
+			{
+				if (array_key_exists($var_key, $arVarSelected))
+				{
+					if ($var_id === $var_key) continue;
+					if ($var['typ'] == "checkbox")
+					{
+						if ($arVarSelected[$var_key] == "1")
+						{
+							$arBilder = array_intersect($arBilder, explode(",", $var['pic']));
+						}
+						else
+						{
+							$arBilder = array_diff($arBilder, explode(",", $var['pic']));
+						}
+					}
+					else
+					{
+						$pics = wpsg_getStr($var['arVariation'][$arVarSelected[$var_key]]['pic']);
+						$arBilder = array_intersect($arBilder, explode(",", wpsg_getStr($var['arVariation'][$arVarSelected[$var_key]]['pic'])));
+					}
+				}
+			}
+			//$arBilder = $this->checkPics($arBilder, $product_id);
+
+			if (wpsg_isSizedArray($arBilder))
+			{
+				$arBilder = array_values($arBilder);
+				foreach ($arTemp as $k => $bild) {
+					if ($arBilder[0] != $bild['basenameori']) unset($arTemp[$k]);
+				}
+				//return $arBilder;
+				$arTemp = array_values($arTemp);
+				return $arTemp;
+			}
+			else
+			{
+				return array();
+			}
+		}
+
+		/**
+		 * Gibt einen Array zurÃŒck, bei denen die SchlÃŒssel die Varianten sind und die Werte die gewÃ€hlten Variationen
+		 */
+		private function getSetVariArray($product_key)
+		{
+
+			if (!$this->isVariantsProductKey($product_key)) return array();
+
+			$arVariSet = explode('|', preg_replace('/^pv_\d*\//', '', $product_key));
+			$arReturn = array();
+			unset($arVariSet[0]);
+
+			foreach ($arVariSet as $var_combi)
+			{
+
+				$var_combi = explode(':', $var_combi);
+				$var = $var_combi[0];
+				$vari = $var_combi[1];
+
+				$arReturn[$var] = $vari;
+
+			}
+
+			return $arReturn;
+
+		}	// private function getSetVariArray($product_key)
+
+		/**
+		 * Gibt die Variationen einer Variante zurÃŒck
+		 * @param Integer $variant_id ID der Variante
+		 */
+		public function getVariationOfVariant($variant_id, $product_id = false, $arProductFilter = array())
+		{
+
+			$strQuerySELECT = "";
+			$strQueryJOIN = "";
+			$strQueryWHERE = "";
+			$strQueryHAVING = "";
+
+			if (wpsg_isSizedArray($arProductFilter))
+			{
+
+				//return array($strQuerySELECT, $strQueryWHERE, $strQueryJOIN, $strQueryHAVING, $strQueryORDER);
+				//list($strQueryP_WHERE, $strQueryP_JOIN, $strQueryP_HAVING, $strQueryP_ORDER) = wpsg_product::getQueryParts($arProductFilter);
+
+				list($strQueryP_SELECT, $strQueryP_WHERE, $strQueryP_JOIN, $strQueryP_HAVING, $strQueryP_ORDER) = wpsg_product::getQueryParts($arProductFilter);
+
+				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PV ON (PV.`variation_id` = VI.`id`) ";
+				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (P.`id` = PV.`product_id`) ";
+
+				$strQuerySELECT .= $strQueryP_SELECT;
+				$strQueryJOIN .= $strQueryP_JOIN;
+				$strQueryWHERE .= $strQueryP_WHERE;
+				$strQueryHAVING .= $strQueryP_HAVING;
+
+			}
+			else if (wpsg_isSizedInt($product_id))
+			{
+
+				$strQueryJOIN .= " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PV ON (PV.`variation_id` = VI.`id` AND PV.`product_id` = '".wpsg_q($product_id)."') ";
+				$strQuerySELECT .= " , PV.`id` AS iid, PV.`variation_id`, PV.`active`, PV.`anr`, PV.`price`, PV.`stock`, PV.`images`, PV.`weight`, PV.`fmenge` ";
+
+			}
+
+			$strQuery = "
+				SELECT
+					VI.`id`, VI.`name`, VI.`shortname`, VI.`deleted`, VI.`pos`
+					".$strQuerySELECT."
+				FROM
+					`".WPSG_TBL_VARIANTS_VARI."` AS VI
+						".$strQueryJOIN."
+				WHERE
+					VI.`variant_id` = '".wpsg_q($variant_id)."' AND
+					VI.`deleted` != '1'
+					".$strQueryWHERE."
+				GROUP BY
+					VI.`id`
+				HAVING
+					1
+					".$strQueryHAVING."
+				ORDER BY
+					VI.`pos`
+			";
+
+			$arVari = $this->db->fetchAssoc($strQuery);
+			$this->unserializeVariation($arVari);
+
+			// TODO: Ãbersetzung
+
+			return $arVari;
+
+		} // public function getVariationOfVariant($variant_id)
+
+		private function unserializeVariation(&$arVari) {
+			foreach ($arVari as &$vi) {
+				$ar = @unserialize($vi['images']);
+				$vi['pic'] = '';
+				$vi['sel'] = 0;
+				$vi['picOrder'] = Array();
+				if (wpsg_isSizedArray($ar)) {
+					foreach($ar as $k => $v) {
+						$v = preg_replace('/\-(\d+)x(\d+)\./', '.', $v);
+						$vi[$k] = $v;
+					}
+				}
+			}
+		}	// private function unserializeVariation(&$arVari)
+
+		private function unserializeVariant(&$arVar) {
+			foreach ($arVar as &$va) {
+				if ($va['type'] == 0) $va['typ'] = 'select';
+				if ($va['type'] == 1) $va['typ'] = 'radio';
+				if ($va['type'] == 2) $va['typ'] = 'image';
+
+				foreach ($va['arVariation'] as &$vi) {
+					$ar = @unserialize($vi['images']);
+					$vi['pic'] = '';
+					$vi['sel'] = 0;
+					$vi['picOrder'] = Array();
+					if (wpsg_isSizedArray($ar)) {
+						foreach($ar as $k => $v) {
+							$v = preg_replace('/\-(\d+)x(\d+)\./', '.', $v);
+							$vi[$k] = $v;
+						}
+					}
+				}
+			}
+		}	// private function unserializeVariant(&$arVar)
+
+		public function stockVarianten($product_id)
+		{
+
+			$this->shop->view['product_id'] = wpsg_getStr($product_id, '0');
+			//$this->shop->view['variant'] = $this->getVariant($_REQUEST['variant_id']);
+			//$this->shop->view['arVariation'] = $this->getVariationOfVariant($_REQUEST['variant_id'], $_REQUEST['product_id']);
+			//$this->shop->view['arVariant']
+			$vp_data = $this->getVariants($product_id, true, true, true);
+			$this->unserializeVariant($vp_data);
+
+			$html = '<table>';
+			foreach ($vp_data as $var) {
+				$html .= '<tr>';
+				$html .= '<td class="col_shortname" colspan="3">'.wpsg_hspc($var['name']).'</td>';
+				$html .= '</tr>';
+			    foreach ($var['arVariation'] as $vari) {
+			    	$html .= '<tr>';
+			    	$html .= '<td class="col_active">&nbsp;';
+			    	$html .= '</td>';
+			    	$txt = wpsg_hspc($vari['name']).' : '.wpsg_hspc($vari['stock']);
+			    	$html .= '<td class="col_shortname">'.$txt.'</td>';
+			    	$html .= '<td class="col_1">';
+			    	$html .= '</td>';
+			    	$html .= '</tr>';
+				}
+			}
+			$html .= '</table>';
+			die($html);
+
+		} // private function stockVarianten($product_id)
+
+		/**
+		 * Reduziert den Bestand der Variationen in dem Array
+		 */
+		public function reduceStock($produkt_key, $menge, $reduce = true)
+		{
+
+			//$produkt_id = preg_replace('/(^pv_)|(\|(.*)$)/', '', $produkt_key);
+			//$vari_teil = preg_replace('/(.*)\//', '', $produkt_key);
+			//$arVarianten = explode('|', $vari_teil);
+			$arVar = $this->explodeProductKey($produkt_key);
+
+			//$vari_data = $this->loadVarianten($produkt_id, true, true);
+
+			// Tabellen sperren
+			if ($this->shop->get_option('wpsg_lockOrderTables') != '1')
+			{
+
+				$arLockTables[WPSG_TBL_PRODUCTS_VARIATION] = "WRITE";
+				$strQuery = "LOCK TABLES ";
+				foreach ($arLockTables as $table_name => $locktype) $strQuery .= " `".$table_name."` ".$locktype.",";
+				$this->db->Query(substr($strQuery, 0, -1));
+			}
+
+			foreach ($arVar['arVari'] as $v => $vv)
+			{
+
+				if ($reduce === true)
+				{
+
+					//$vari_data[$variante_id]['vari'][$vari_id]['stock'] -= $menge;
+					$this->db->Query("
+							UPDATE ".WPSG_TBL_PRODUCTS_VARIATION." SET `stock` = `stock` - ".wpsg_q($menge)." WHERE `id` = '".wpsg_q($vv)."'
+						");
+
+				}
+				else
+				{
+
+					//$vari_data[$variante_id]['vari'][$vari_id]['stock'] += $menge;
+					$this->db->Query("
+							UPDATE ".WPSG_TBL_PRODUCTS_VARIATION." SET `stock` = `stock` + ".wpsg_q($menge)." WHERE `id` = '".wpsg_q($vv)."'
+						");
+
+				}
+
+			}
+
+			$this->db->unlockTables();
+
+			$this->setStockFromVariation($produkt_key);
+
+			// Array zurÃŒckspeichern
+			//$this->saveVarianten($produkt_id, $vari_data);
+
+		} // public function reduceStock($produkt_id, $menge)
+
+		/**
+		 * Gibt true zurÃŒck, wenn der ÃŒbergebene Produktkey ein Varianten Produktkey ist. Sonst false.
+		 * @param \String $productkey
+		 */
+		public function isVariantsProductKey($productkey)
+		{
+
+			if (preg_match('/^pv_\d+/', $productkey))
+			{
+
+				return true;
+
+			}
+			else
+			{
+
+				return false;
+
+			}
+
+		} // public function isVariantsProductKey($productkey)
+
+		/**
+		 * Gibt eine einzelne Variante zurÃŒck
+		 * @param unknown $variant_id
+		 */
+		public function getVariant($variant_id, $bHideDeleted = true)
+		{
+
+			$strQueryWHERE = "";
+
+			if ($bHideDeleted === true) $strQueryWHERE .= " AND V.`deleted` != '1' ";
+
+			$strQuery = "
+				SELECT
+					V.*
+				FROM
+					`".WPSG_TBL_VARIANTS."` AS V
+				WHERE
+					V.`id` = '".wpsg_q($variant_id)."'
+					".$strQueryWHERE."
+			";
+
+			$arVariant = $this->db->fetchRow($strQuery);
+
+			if (!wpsg_isSizedInt($arVariant['id'])) return false;
+
+			// TODO: Ãbersetzung
+
+			return $arVariant;
+
+		} // public function getVariant($variant_id)
+
+		public function getVariation($variation_id)
+		{
+
+			$arVariation = $this->db->fetchRow("
+				SELECT
+					VI.*
+				FROM
+					`".WPSG_TBL_VARIANTS_VARI."` AS VI
+				WHERE
+					VI.`id` = '".wpsg_q($variant_id)."'
+			");
+
+			$arVariation['images'] = wpsg_trim(explode(',', $arVariation['images']));
+
+			// TODO: Ãbersetzung
+
+			return $arVariation;
+
+		} // public function getVariation($variation_id)
+
+		/**
+		 * Gibt einen Array der Produktvarianten zurÃŒck
+		 * @param Integer|Boolean $product_id Produkt ID
+		 * @param Boolean $global Globale Varianten?
+		 */
+		public function getVariants($product_id = false, $global = true, $onlyActive = false, $loadVariationen = false, $serVariationen = false)
+		{
+
+			$strQuerySELECT = "";
+			$strQueryORDER = "";
+			$strQueryJOIN = "";
+			$strProductQuery = " AND ( 0 ";
+
+			if (wpsg_isSizedInt($product_id))
+			{
+
+				$strProductQuery .= " OR V.`product_id` = '".wpsg_q($product_id)."' ";
+
+				$strQueryWHERE = "";
+
+				// Wenn Lagerbestand aktiv, dann nur Veriationen mit Lagerbestand zÃ€hlen
+				// Im Backend zÃ€hle ich auch ausverkaufte Variationen mit, sonst steht in der Ãbersicht 0/2 auch wenn bei einem der Haken gesetzt ist
+				if ($this->shop->hasMod('wpsg_mod_stock') && !is_admin()) $strQueryWHERE .= " AND PVI.`stock` > 0 ";
+
+				$strQuerySELECT .= ", (
+					SELECT
+						COUNT(*)
+					FROM
+						`".WPSG_TBL_VARIANTS_VARI."` AS VI
+							LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+					WHERE
+						PVI.`product_id` = '".wpsg_q($product_id)."' AND
+						PVI.`active` = '1' AND
+						VI.`variant_id` = V.`id` AND
+						VI.`deleted` != '1'
+						".$strQueryWHERE."
+				) AS `count_active` ";
+
+				$strQueryJOIN = " LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIANT."` AS PV ON (PV.`variant_id` = V.`id` AND PV.`product_id` = '".wpsg_q($product_id)."') ";
+
+				$strQueryORDER .= " PV.`pos` ASC, ";
+
+			}
+			else
+			{
+
+				$strQuerySELECT .= ", '0' AS `count_active` ";
+
+			}
+
+			if ($global === true)
+			{
+
+				$strProductQuery .= " OR V.`product_id` = '0' ";
+
+			}
+
+			$strProductQuery .= " ) ";
+
+			$arData = $this->db->fetchAssoc("
+				SELECT
+					V.*,
+					(SELECT COUNT(*) FROM `".WPSG_TBL_VARIANTS_VARI."` AS VI WHERE VI.`variant_id` = V.`id` AND VI.`deleted` != '1') AS `count_variation`,
+					(
+						SELECT
+							COUNT(DISTINCT `product_id`)
+						FROM
+							`".WPSG_TBL_VARIANTS_VARI."` AS VI
+								LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+								LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (PVI.`product_id` = P.`id`)
+						WHERE
+							VI.`variant_id` = V.`id` AND
+							PVI.`active` = '1' AND
+							P.`id` > 0 AND
+							P.`deleted` != '1'
+					) AS `count_produkte`
+					".$strQuerySELECT."
+				FROM
+					`".WPSG_TBL_VARIANTS."` AS V
+						".$strQueryJOIN."
+				WHERE
+					V.`deleted` != '1'
+					".$strProductQuery."
+				GROUP BY
+					V.`id`
+				ORDER BY
+					".$strQueryORDER."
+					V.`product_id` ASC, V.`pos`
+			", "id");
+
+			foreach ($arData as $k => $v)
+			{
+
+				if ($onlyActive === true && !wpsg_isSizedInt($v['count_active'])) unset($arData[$k]);
+				else
+				{
+
+					$arData[$k]['type_label'] = self::$arTypeLabel[$arData[$k]['type']];
+
+					if ($loadVariationen === true && wpsg_isSizedInt($product_id))
+					{
+
+						$arData[$k]['arVariation'] = $this->db->fetchAssoc("
+							SELECT
+								PVI.*,
+								VI.`name`
+							FROM
+								`".WPSG_TBL_VARIANTS_VARI."` AS VI
+									LEFT JOIN `".WPSG_TBL_PRODUCTS_VARIATION."` AS PVI ON (PVI.`variation_id` = VI.`id`)
+							WHERE
+								VI.`deleted` != '1' AND
+								VI.`variant_id` = '".wpsg_q($v['id'])."' AND
+								PVI.`product_id` = '".wpsg_q($product_id)."' AND
+								PVI.`active` = '1'
+							ORDER BY
+								VI.`pos` ASC
+						", "variation_id");
+
+						// Bilder deserialisieren
+						foreach ($arData[$k]['arVariation'] as $vari_id => $vari_data)
+						{
+
+							if ($serVariationen == true) {
+								$arData[$k]['arVariation'][$vari_id]['images'] = @unserialize($vari_data['images']);
+								if (wpsg_isSizedString($arData[$k]['arVariation'][$vari_id]['images'])) $arData[$k]['arVariation'][$vari_id]['images'] = wpsg_trim(explode(',', $arData[$k]['arVariation'][$vari_id]['images']));
+								else $arData[$k]['arVariation'][$vari_id]['images'] = array();
+
+							}
+
+						}
+
+					}
+				}
+
+			}
+
+			// TODO: Ãbersetzung
+
+			return $arData;
+
+		}
+
+		public function basket_preInsertDefekt()
+		{
+
+			if (is_array($_REQUEST['wpsg_vp']) && sizeof($_REQUEST['wpsg_vp']) > 0)
+			{
+
+				$var_key = 'pv_'.$_REQUEST['wpsg']['produkt_id'].'|';
+
+				foreach ($_REQUEST['wpsg_vp'] as $var => $var_value)
+				{
+
+					$var_key .= $var.":".$var_value."|";
+
+				}
+
+				$var_key = substr($var_key, 0, -1);
+
+				$_REQUEST['wpsg']['produkt_id'] = $var_key;
+
+			}
+
+		} // public function basket_preInsert()
+
+		public function basket_row(&$p, $i)
+		{
+
+			if (!preg_match('/pv_(.*)/', $p['id'])) return;
+
+			$this->shop->view['variante'] = $this->getVariantenInfoArray($p['id']);
+
+			$this->shop->view['i'] = $i;
+
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/basket_row.phtml');
+
+		} // public function basket_row(&$p)
+
+		public function overview_row(&$p, $i)
+		{
+
+			if (!preg_match('/pv_(.*)/', $p['id'])) return;
+
+			$this->shop->view['variante'] = $this->getVariantenInfoArray($p['id']);
+
+			$this->shop->view['i'] = $i;
+
+			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_productvariants/overview_row.phtml');
+
+		} // public function basket_row(&$p)
+
+		/**
+		 * Liest die Informationen anhand eines VariantenschlÃŒssels aus
+		 */
+		public function getVariantenInfoArray($vari_key)
+		{
+
+			//$produkt_id = preg_replace('/(vp_)|(\/(.*))/', '', $vari_key);
+			$produkt_id = preg_replace('/(pv_)|(\|(.*))/', '', $vari_key);
+			//$arVari = explode('|', preg_replace('/vp_'.$produkt_id.'\//', '', $vari_key));
+			$arVari = explode('|', preg_replace('/pv_'.$produkt_id.'\|/', '', $vari_key));
+
+			//$vp_data = $this->loadVarianten($produkt_id);
+			$vp_data = $this->getVariants($produkt_id, true, true, true);
+			$this->unserializeVariant($vp_data);
+
+			$arKey = array();
+			$arAKey = array();
+			$arPics = array();
+
+			$arReturn = array();
+
+			// kein Produkt-Key dann keine Weiterarbeit nÃ¶tig
+			if (is_numeric($vari_key)) {
+				$arReturn['key'] = '';
+				$arReturn['akey'] = '';
+				$arReturn['pics'] = array();
+				return $arReturn;
+
+			}
+
+			if ($this->shop->hasMod('wpsg_mod_fuellmenge')) $arReturn['fmenge'] = 0;
+			if ($this->shop->hasMod('wpsg_mod_weight')) $arReturn['weight'] = 0;
+
+			foreach ($arVari as $var_key)
+			{
+
+				$var_id = preg_replace('/\:(.*)/', '', $var_key);
+				$var_value = preg_replace('/(.*)\:/', '', $var_key);
+
+				if ($vp_data[$var_id]['typ'] == 'checkbox')
+				{
+
+					$arPicsVariante = array();
+
+					if (isset($vp_data[$var_id]['pic']))
+					{
+
+						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['pic']));
+
+					}
+
+					if ($var_value == '1')
+					{
+
+						$r = array(
+								'name' => $vp_data[$var_id]['name'],
+								'preis' => $vp_data[$var_id]['price'],
+								'artnr'	=> $vp_data[$var_id]['arVariation'][2]['anr'],
+								'pics' => $arPicsVariante
+						);
+
+						if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['weight']))
+						{
+
+							$r['weight'] = $vp_data[$var_id]['weight'];
+							$arReturn['weight'] += $r['weight'];
+
+						}
+
+						if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['fmenge']))
+						{
+
+							$r['fmenge'] = $vp_data[$var_id]['fmenge'];
+							$arReturn['fmenge'] += $r['fmenge'];
+
+						}
+
+						$arReturn[] = $r;
+
+						$arKey[] = $vp_data[$var_id]['name'];
+
+						$arPics = array_intersect($arPics, $arPicsVariante);
+
+					}
+					else
+					{
+
+						// Checkbox ist nicht markiert
+						//$arPics = array_unique(array_merge($arPics, $arPicsVariante));
+
+					}
+
+				}
+				else
+				{
+
+					$arPicsVariante = array();
+
+					if (isset($vp_data[$var_id]['arVariation'][$var_value]['pic']))
+					{
+
+						$arPicsVariante = wpsg_trim(explode(',', $vp_data[$var_id]['arVariation'][$var_value]['pic']));
+						$arPics = array_unique(array_merge($arPics, $arPicsVariante));
+
+					}
+
+					$r = array(
+							'name' 	=> $vp_data[$var_id]['name'],
+							'value' => $vp_data[$var_id]['arVariation'][$var_value]['name'],
+							'preis'	=> $vp_data[$var_id]['arVariation'][$var_value]['price'],
+							'artnr'	=> @$vp_data[$var_id]['arVariation'][$var_value]['artnr'],
+							'pics' => $arPicsVariante
+					);
+
+					if ($this->shop->hasMod('wpsg_mod_weight') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['weight']))
+					{
+
+						$r['weight'] = $vp_data[$var_id]['arVariation'][$var_value]['weight'];
+						$arReturn['weight'] += $r['weight'];
+
+					}
+
+					if ($this->shop->hasMod('wpsg_mod_fuellmenge') && wpsg_isSizedInt($vp_data[$var_id]['arVariation'][$var_value]['fmenge']))
+					{
+
+						$r['fmenge'] = $vp_data[$var_id]['arVariation'][$var_value]['fmenge'];
+						$arReturn['fmenge'] += $r['fmenge'];
+
+					}
+
+					$arReturn[] = $r;
+
+					$arKey[] = $vp_data[$var_id]['arVariation'][$var_value]['name'];
+					$arAKey[] = @$vp_data[$var_id]['arVariation'][$var_value]['anr'];
+
+				}
+
+			}
+
+			$arReturn['key'] = implode(' / ', $arKey);
+			$arReturn['akey'] = implode(' / ', $arAKey);
+			$arReturn['pics'] = array_unique($arPics);
+
+			return $arReturn;
+
+		} // public function getVariantenInfoArray($vari_key)
+
+		/**
+		 * Wird nach dem speichern des Produktes aus der saveAction des 
+		 * Produktcontrollers aufgerufen
+		 * 
+		*/
+		public function produkt_save(&$produkt_id) {
+			
+			$varis = $GLOBALS['wpsg_sc']->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_PRODUCTS_VARIATION."` WHERE `product_id`='".wpsg_q($produkt_id)."' ");
+			
+			foreach ($varis as $v)
+			{
+				$im0 = unserialize($v['images']);
+				
+				$im1 = array();
+				$im1 = $im0;
+				//$im1['pic'] = array();
+				//$im1['picOrder'] = $im0['picOrder'];
+				//$im1['postid'] = array();
+				
+				$pids = explode(',', $im0['postid']);
+				$postid = array();
+				$pic = array();
+				foreach ($pids as $pid)
+				{
+					
+					$post = $GLOBALS['wpsg_sc']->db->fetchRow("SELECT * FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID` = '".wpsg_q($pid)."' ");
+					if (isset($post['ID']))
+					{
+						$postid[] = $post['ID'];
+						$pic[] = sanitize_file_name($post['post_excerpt']);
+					}
+				}
+				$im1['pic'] = implode(',', $pic);
+				$im1['postid'] = implode(',', $postid);
+				$images = serialize($im1);
+				// Update WPSG_TBL_PRODUCTS_VARIATION
+				$data = array('images' => $images);
+				$GLOBALS['wpsg_sc']->db->UpdateQuery(WPSG_TBL_PRODUCTS_VARIATION, $data, "`id` = '".wpsg_q($v['id'])."'");
+				
+			}
+		}	// public function produkt_save(&$produkt_id)
+		
+
+	} // class wpsg_mod_productvariants extends wpsg_mod_basic
+
+?>
Index: /views/mods/mod_productvariants/admin_edit.phtml
===================================================================
--- /views/mods/mod_productvariants/admin_edit.phtml	(revision 6426)
+++ /views/mods/mod_productvariants/admin_edit.phtml	(revision 6427)
@@ -185,5 +185,5 @@
 							$href = wp_get_attachment_image_src($b['post_id'], Array(25, 25));
 							?>	
-							<a class="<?php echo ((in_array($file2, explode(",", $vari['pic'])))?'mark':''); ?> pic" id="<?php echo $file2; ?>" 
+							<a class="<?php echo ((in_array($file2, explode(",", $vari['pic'])))?'mark':''); ?> pic" id="<?php echo $file2; ?>" data-pid="<?php echo $b['post_id']; ?>" 
 							onclick="return wpsg_vp_vari_setPic(this, <?php echo $k; ?>, <?php echo $kv; ?>, '<?php echo $file2; ?>', <?php echo $j; ?>, <?php echo $b['post_id']; ?>);">
 							<img src="<?php echo $href[0]; ?>" alt="" width="25px" height="25px"/>
@@ -204,7 +204,8 @@
 									
 									var wpsg_reorder = jQuery(this).sortable('toArray');
+									var wpsg_postids = jQuery(this).sortable('toArray', {attribute: 'data-pid'});
+									alert(wpsg_postids + ' ' + wpsg_reorder);
 									var iid = jQuery('#productvariation_iid_' + <?php echo $kv; ?>).val();
 									//alert('iid: ' + iid);
-														
 
 									jQuery.ajax( {			
@@ -215,4 +216,5 @@
 											'vari_id': <?php echo $kv; ?>,
 											'iid': iid,
+											'wpsg_postids': wpsg_postids,
 											'wpsg_reorder': wpsg_reorder
 										},
Index: /views/produkt/select.phtml
===================================================================
--- /views/produkt/select.phtml	(revision 6426)
+++ /views/produkt/select.phtml	(revision 6427)
@@ -133,7 +133,6 @@
 				insertProdukt();
 				
-				//jQuery('#wpsg_mod_relatedproducts_dialog').html('').dialog('close');
-				jQuery('#wpsg_mod_relatedproducts_dialog').modal( { } ).modal('hide');
-
+				//jQuery('#wpsg_mod_relatedproducts_dialog').modal( { } ).modal('hide');
+				jQuery("#wpsg_mod_relatedproducts_dialog .close").click()
 				return false;
 				
