Index: /mods/wpsg_mod_productvariants.class.php
===================================================================
--- /mods/wpsg_mod_productvariants.class.php	(revision 6332)
+++ /mods/wpsg_mod_productvariants.class.php	(revision 6333)
@@ -836,5 +836,4 @@
 
 			}
-
 
 		} // public function getStockForVariation($product_key)
@@ -1509,5 +1508,33 @@
 			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()
@@ -1874,4 +1901,6 @@
 
 			$this->db->unlockTables();
+
+			$this->setStockFromVariation($produkt_key);
 
 			// Array zurÃŒckspeichern
Index: /mods/wpsg_mod_stock.class.php
===================================================================
--- /mods/wpsg_mod_stock.class.php	(revision 6332)
+++ /mods/wpsg_mod_stock.class.php	(revision 6333)
@@ -1,14 +1,14 @@
 <?php
-	
+
 	/**
 	 * Dieses Modul erlaubt die Verwaltung des Warenbestandes
 	 *
 	 */
-	class wpsg_mod_stock extends wpsg_mod_basic 
+	class wpsg_mod_stock extends wpsg_mod_basic
 	{
-		
-		var $id = 90;		
+
+		var $id = 90;
 		var $lizenz = 1;
-		
+
 		/**
 		 * Costructor
@@ -16,18 +16,18 @@
 		public function __construct()
 		{
-			
+
 			parent::__construct();
-			
+
 			$this->name = __('Lagerbestand', 'wpsg');
 			$this->group = __('Produkte', 'wpsg');
 			$this->desc = __('Erlaubt die Verwaltung des Lagerbestandes bei den Produkten.', 'wpsg');
-						
+
 		} // public function __construct()
-		
-		public function install() 
+
+		public function install()
 		{
 
 			$this->shop->checkDefault('wpsg_mod_stock_showBackendStock', '1');
-			
+
 			require_once(WPSG_PATH_WP.'/wp-admin/includes/upgrade.php');
 
@@ -38,83 +38,83 @@
 			  	stock int(11) NOT NULL,
 			  	stock_count int(1) NOT NULL,
-				minstockproduct_count int(11) NOT NULL, 	
+				minstockproduct_count int(11) NOT NULL,
 				minstockproduct_mail varchar (255) NOT NULL,
 			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
-			
+
 			dbDelta($sql);
-			
+
 		} // public function install()
-		
+
 		public function settings_edit()
 		{
-			
+
 			// VerfÃŒgbare Produkttemplates
 			$this->shop->view['arTemplates'] = $this->shop->loadProduktTemplates();
-			
+
 			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_stock/settings_edit.phtml');
-			
+
 		} // public function settings_edit()
-		
-		public function settings_save() 
-		{
-						
-			$this->shop->update_option('wpsg_mod_stock_template', $_REQUEST['wpsg_mod_stock_template']);
+
+		public function settings_save()
+		{
+
+			//$this->shop->update_option('wpsg_mod_stock_template', $_REQUEST['wpsg_mod_stock_template']);
 			$this->shop->update_option('wpsg_mod_stock_allow', $_REQUEST['wpsg_mod_stock_allow']);
 			$this->shop->update_option('wpsg_mod_stock_showBackendStock', $_REQUEST['wpsg_mod_stock_showBackendStock']);
 			$this->shop->update_option('wpsg_mod_stock_minstockproduct', $_REQUEST['wpsg_mod_stock_minstockproduct']);
 			$this->shop->update_option('wpsg_mod_stock_hideSoldout', $_REQUEST['wpsg_mod_stock_hideSoldout']);
-			
+
 			if ($this->shop->hasMod('wpsg_mod_productindex'))
 			{
 				$this->shop->update_option('wpsg_mod_stock_showProductindex', $_REQUEST['wpsg_mod_stock_showProductindex']);
 			}
-			
+
 			$this->shop->update_option('wpsg_mod_stock_showProduct', $_REQUEST['wpsg_mod_stock_showProduct']);
-			
-			
+
+
 		} // public function settings_save()
-		
+
 		/**
-		 * 
+		 *
 		 */
-		public function canOrder($product_key) 
-		{ 
-			
+		public function canOrder($product_key)
+		{
+
 			if ($this->getBestand($product_key) - $this->getAmountSession($product_key) <= 0) return -2;
-			
+
 		} // public function canOrder($oProduct)
-		
+
 		public function canDisplay($product_key)
 		{
-			
+
 			if ($this->shop->get_option('wpsg_mod_stock_hideSoldout') === '1' && $this->getBestand($product_key) - $this->getAmountSession($product_key) <= 0) return -2;
-			
+
 		} // public function canDisplay($product_key)
-		
-		public function produkt_ajax() { 
-			
+
+		public function produkt_ajax() {
+
 			if ($_REQUEST['wpsg_cmd'] == 'getVariInfo')
 			{
-				
+
 				if ($this->shop->hasMod('wpsg_mod_productvariants'))
 				{
 
-					$this->shop->callMod('wpsg_mod_productvariants', 'stockVarianten', array($_REQUEST['edit_id']));
-					
+					$this->shop->callMod('wpsg_mod_productvariants', 'stockVarianten', array($_REQUEST['product_id']));
+
 				}
 				else
 				{
-					
+
 					die(wpsg_translate(__('Aufrufsfehler! Fehlercode:#1#', 'wpsg'), '90_1'));
-					
-				}
-				
-			}
-			
-		} // public function produkt_ajax()		
+
+				}
+
+			}
+
+		} // public function produkt_ajax()
 
 		public function produkt_edit(&$data)
 		{
-			
+
 			$data = wpsg_array_merge($data, $this->db->fetchRow("
 				SELECT
@@ -125,143 +125,143 @@
 					`id` = '".wpsg_q($data['id'])."'
 			"));
-												
+
 		} // public function produkt_edit(&$data)
-		
+
 		public function produkt_save(&$produkt_id)
 		{
-		
+
 			$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, array(
 				"stock" => wpsg_q($_REQUEST['wpsg_mod_stock_stock']),
 				"stock_count" => wpsg_q($_REQUEST['wpsg_mod_stock_stock_count'])
 			), "`id` = '".wpsg_q($produkt_id)."'");
-						
+
 		} // public function produkt_save(&$produkt_id)
-		 
+
 		public function produkt_edit_sidebar(&$produkt_data)
 		{
-			
+
 			if (isset($_REQUEST['wpsg_lang'])) return;
-			
+
 			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_stock/produkt_edit_sidebar.phtml');
-			
+
 		} // public function produkt_edit_sidebar(&$produkt_data)
- 
+
 		public function setOrderStatus($order_id, $status_id, $inform)
 		{
 
-			if (in_array($status_id, array(500)) || 
+			if (in_array($status_id, array(500)) ||
 				(isset($this->shop->view['order']) && ($this->shop->view['order']['status'] == 500)))
 			{
-				
+
 				// Entweder ist die Bestellung von Storniert in einen anderen Status gewÃ€chselt oder in Storniert
-				
+
 				// Lagerbestand zurÃŒcksetzen
 				$arProductsBuy = $this->db->fetchAssoc("
-					SELECT 
-						OP.*							
+					SELECT
+						OP.*
 					FROM
 						`".WPSG_TBL_ORDERPRODUCT."` AS OP
 							LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (P.`id` = OP.`p_id`)
 					WHERE
-						OP.`o_id` = '".wpsg_q($order_id)."' 
+						OP.`o_id` = '".wpsg_q($order_id)."'
 				");
- 
+
 				foreach ($arProductsBuy as $p)
 				{
-					
+
 					// Bei gekauften Abo VerlÃ€ngerungen nicht machen
 					if (preg_match('/^abo_\d+(.*)/', $p['productkey'])) continue;
-					
+
 					if ($this->shop->hasMod('wpsg_mod_productgroups'))
 					{
-						
+
 						// Verwaltung des Lagerbestandes in der Produktgruppe
-						
+
 						// Produktdaten laden um die Produktgruppe herauszufinden
 						$product_data = $this->shop->cache->loadProduct($p['p_id']);
-								 
+
 						if (wpsg_isSizedInt($product_data['pgruppe']))
 						{
-					
+
 							$pgruppe_stock_active = $this->db->fetchOne("SELECT `stock_aktiv` FROM `".WPSG_TBL_PRODUCTS_GROUP."` WHERE `id` = '".wpsg_q($product_data['pgruppe'])."' ");
-				 
+
 							if ($pgruppe_stock_active === '1')
 							{
-					
+
 								if ($this->shop->view['order']['status'] == 500) /* war storniert */
 								{
-					
+
 									$this->db->Query("
 										UPDATE ".WPSG_TBL_PRODUCTS_GROUP." SET `stock_value` = `stock_value` - ".wpsg_q($p['menge'])." WHERE `id` = '".wpsg_q($product_data['pgruppe'])."'
 									");
-					
+
 								}
 								else
 								{
-					
+
 									$this->db->Query("
 										UPDATE ".WPSG_TBL_PRODUCTS_GROUP." SET `stock_value` = `stock_value` + ".wpsg_q($p['menge'])." WHERE `id` = '".wpsg_q($product_data['pgruppe'])."'
 									");
-					
-								} 
-									
+
+								}
+
 							}
-					
+
 						}
-						
-					}
-										
+
+					}
+
 					// Verwaltung im Produkt oder Produktgruppenlagerbestand nicht aktiv
 					$product_data =  $this->shop->cache->loadProduct($p['p_id']);
-					
+
 					if ($product_data['stock_count'] != '1') continue;
-					
+
 					$var_key = false;
 
 					if ($this->shop->hasMod('wpsg_mod_productvariants'))
 					{
-					
+
 						if (wpsg_isSizedString($p['mod_vp_varkey']) && preg_match('/^pv_\d+(.*)/', $p['mod_vp_varkey']))
 						{
-							
+
 							$var_key = $p['mod_vp_varkey'];
-							
+
 						}
 						else if (wpsg_isSizedString($p['productkey']) && preg_match('/^pv_\d+(.*)/', $p['productkey']))
 						{
-							
+
 							$var_key = $p['productkey'];
-							
+
 						}
-						
-					}
-					 
+
+					}
+
 					// Normales Produkt
-										 
+
 					if ($this->shop->view['order']['status'] == 500) /* war storniert */
 					{
-					
+
 						$this->db->Query("
 							UPDATE ".WPSG_TBL_PRODUCTS." SET `stock` = `stock` - ".wpsg_q($p['menge'])." WHERE `id` = '".wpsg_q($p['p_id'])."'
 						");
-													
+
 					}
 					else
 					{
-							
+
 						$this->db->Query("
 							UPDATE ".WPSG_TBL_PRODUCTS." SET `stock` = `stock` + ".wpsg_q($p['menge'])." WHERE `id` = '".wpsg_q($p['p_id'])."'
 						");
-							
-					}
-							 		
+
+					}
+
 					if ($var_key !== false)
 					{
-						
+
 						// Variantenprodukt
-						
+
 						if ($this->shop->view['order']['status'] == 500)
 						{
-						
+
 							$this->shop->callMod('wpsg_mod_productvariants', 'reduceStock', array($var_key, $p['menge'], true));
 
@@ -269,96 +269,96 @@
 						else
 						{
-							
+
 							$this->shop->callMod('wpsg_mod_productvariants', 'reduceStock', array($var_key, $p['menge'], false));
-							
+
 						}
-						
-					}	
-					
-				}
-				
-			}
-			
+
+					}
+
+				}
+
+			}
+
 		} // public function setOrderStatus($order_id, $status_id, $inform)
-		
-		public function basket_updateProduktFromSession(&$product_index, &$stock) 
-		{ 
-			
+
+		public function basket_updateProduktFromSession(&$product_index, &$stock)
+		{
+
 			$product_key = $_SESSION['wpsg']['basket'][$product_index]['id'];
-			
+
 			if (!$this->checkBestand($product_key, $stock))
 			{
-				
+
 				/* Nicht mehr ausreichend im Lager */
 				if ($this->shop->get_option('wpsg_mod_stock_allow') === '1')
 				{
-					
+
 					/* Bestellungen mit negativem Lagerbestand verhindern ist aktiv */
 					$stock = $this->getBestand($product_key);
-					 
+
 					$this->shop->addFrontendError(__('Menge wurde korrigiert, da sie den Warenbestand ÃŒberschreitet!', 'wpsg'));
-					
-				}
-				else 
-				{
-					
+
+				}
+				else
+				{
+
 					$this->shop->addFrontendError(__('Menge ÃŒberschreitet Warenbestand!', 'wpsg'));
-					
-				}
-				
-			}
-			
+
+				}
+
+			}
+
 		} // public function basket_updateProduktFromSession(&$product_key, &$stock)
-		
-		public function basket_produkttosession($product_key, &$amount_set, &$ses_data) 
-		{ 
-			 
+
+		public function basket_produkttosession($product_key, &$amount_set, &$ses_data)
+		{
+
 			$ses_amount = max(array($this->getAmountSession($product_key), $this->getAmountSessionById($this->shop->getProduktId($product_key))));
-			$check_amount = $amount_set + $ses_amount; 
-			
+			$check_amount = $amount_set + $ses_amount;
+
  			if (!$this->checkBestand($product_key, $check_amount))
 			{
-								
+
 				/* Nicht mehr ausreichend im Lager */
 				if ($this->shop->get_option('wpsg_mod_stock_allow') === '1')
 				{
-					 
+
 					/* Bestellungen mit negativem Lagerbestand verhindern ist aktiv */
 					$amount_stock = $this->getBestand($product_key);
- 
+
 					$amount_set = $amount_stock - $ses_amount;
-															
+
 					$this->shop->addFrontendError(__('Die ausgewÃ€hlte Menge wurde korrigiert, da sie den Warenbestand ÃŒberschreitet!', 'wpsg'));
-					
+
 					if ($amount_set <= 0) return -2;
-										
+
 				}
 				else
 				{
-					 
+
 					$this->shop->addFrontendError(__('Bitte beachten Sie, dass die ausgewÃ€hlte Menge den Warenbestand ÃŒberschreitet, die Bestellung jedoch abgeschlossen werden kann! Bei Fragen zur Bestellung, wenden Sie sich bitte an uns.', 'wpsg'));
-						
-				}
-				
-			}	
-			
+
+				}
+
+			}
+
 		}
-		
-		public function checkCheckout(&$state, &$error, &$arCheckout) 
-		{ 
-			
+
+		public function checkCheckout(&$state, &$error, &$arCheckout)
+		{
+
 			if (!wpsg_isSizedInt($this->shop->get_option('wpsg_mod_stock_allow')) || $state !== true) return;
-			
+
 			foreach ((array)$this->shop->basket->arProdukte as $product_data)
 			{
-				
+
 				if (!$this->checkBestand($product_data['id'], $product_data['menge']))
 				{
-					
+
 					$nStockAvailable = $this->getBestand($product_data['id']);
-					
+
 					if ($nStockAvailable <= 0)
 					{
-						
+
 						$this->shop->addFrontendError(
 							wpsg_translate(
@@ -368,37 +368,37 @@
 							)
 						);
-						
+
 						$error = true;
-						
-					}
-					 
-				}
-				
-			} 
-			
+
+					}
+
+				}
+
+			}
+
 		} // public function checkCheckout(&$state, &$error, &$arCheckout)
-		
-		public function product_addedit_content(&$product_content, &$product_data) 
-		{ 
-			
+
+		public function product_addedit_content(&$product_content, &$product_data)
+		{
+
 			if (isset($_REQUEST['wpsg_lang'])) return;
-			
+
 			if (!array_key_exists('stock', $product_content))
 			{
-				
+
 				$this->shop->view['arSubAction']['stock'] = array(
 					'title' => __('Bestand / MaÃe', 'wpsg'),
 					'content' => ''
 				);
-				
-			}
-			
+
+			}
+
 			$this->shop->view['data'] = $product_data;
 			$this->shop->view['arSubAction']['stock']['content'] .= $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_stock/product_addedit_content.phtml', false);
-			
+
 		} // public function produkt_add(&$produkt_data)
-		
+
 		/* Modulfunktionen */
-		
+
 		/**
 		 * Gibt den aktuellen Bestand fÃŒr ein Produkt zurÃŒck
@@ -406,48 +406,48 @@
 		public function getBestand($produkt_key)
 		{
-			 
+
 			$arStock = array();
-			
+
 			if ($this->shop->hasMod('wpsg_mod_productgroups'))
 			{
-				
+
 				$product_id = $this->shop->getProduktID($produkt_key);
 				$product_data = $this->shop->cache->loadProduct($product_id);
-				
+
 				if (wpsg_isSizedInt($product_data['pgruppe']))
 				{
-					
+
 					$pgroup = $this->db->fetchRow("SELECT `stock_aktiv`, `stock_value` FROM `".WPSG_TBL_PRODUCTS_GROUP."` WHERE `id` = '".wpsg_q($product_data['pgruppe'])."' ");
-					
+
 					if ($pgroup['stock_aktiv'] === '1')
 					{
-						
-						$arStock[] = $pgroup['stock_value'];						
-						
-					}
-					
-				}
-				
-			}
-			
+
+						$arStock[] = $pgroup['stock_value'];
+
+					}
+
+				}
+
+			}
+
 			if (is_numeric($produkt_key))
 			{
-			
+
 				// Lagerbestand in der Datenbank
 				$arStock[] = $this->db->fetchOne("SELECT P.`stock` FROM `".WPSG_TBL_PRODUCTS."` AS P WHERE P.`id` = '".wpsg_q($produkt_key)."'");
-					 				
+
 			}
 			else if ($this->shop->hasMod('wpsg_mod_productvariants'))
 			{
-				
-				$arStock[] = $this->shop->callMod('wpsg_mod_productvariants', 'getStockForVariation', array($produkt_key)); 
-				 				
-			}
-			
+
+				$arStock[] = $this->shop->callMod('wpsg_mod_productvariants', 'getStockForVariation', array($produkt_key));
+
+			}
+
 			if (!wpsg_isSizedArray($arStock)) return 0;
 			else return min($arStock);
-			
+
 		} // public function getBestand($produkt_id)
-		
+
 		/**
 		 * Gibt die aktuelle Menge eines Produktes aus der Session zurÃŒck
@@ -455,23 +455,23 @@
 		public function getAmountSession($product_key)
 		{
-			
+
 			$amount_ses = 0;
-			
+
 			if (wpsg_isSizedArray($_SESSION['wpsg']['basket']))
 			{
-				
+
 				foreach ($_SESSION['wpsg']['basket'] as $product_index => $product_data)
 				{
-					
+
 					if ($product_key == $product_data['id']) $amount_ses += $product_data['menge'];
-					
-				}
-				
-			}
- 
+
+				}
+
+			}
+
 			return $amount_ses;
-			
+
 		} // public function getAmountSession($product_key)
-		
+
 		/**
 		 * Gibt die aktuelle Menge eines Produktes aus der Session zurÃŒck
@@ -480,214 +480,214 @@
 		public function getAmountSessionById($product_id)
 		{
-			
+
 			$amount_ses = 0;
-			
+
 			if (wpsg_isSizedArray($_SESSION['wpsg']['basket']))
 			{
-				
+
 				foreach ($_SESSION['wpsg']['basket'] as $product_index => $product_data)
 				{
-					
-					if ($this->shop->getProduktId($product_data['id']) == $product_id) $amount_ses += $product_data['menge']; 
-					
-				}
-				
-			}
-			
+
+					if ($this->shop->getProduktId($product_data['id']) == $product_id) $amount_ses += $product_data['menge'];
+
+				}
+
+			}
+
 			return $amount_ses;
-			
+
 		} // public function getAmountSessionById($product_id)
-		
+
 		/**
 		 * ÃberprÃŒft ob der Bestand eines Produktes noch ausreichend ist
 		 * @return true|false
 		 */
-		public function checkBestand($produkt_key, $menge) 
-		{
-			
+		public function checkBestand($produkt_key, $menge)
+		{
+
 			if (substr($produkt_key, 0, 3) == 'abo') return;
-			
+
 			$product_id = $this->shop->getProduktID($produkt_key);
 			$product_data = $this->shop->cache->loadProduct($product_id);
-									
+
 			if ($this->shop->hasMod('wpsg_mod_productgroups'))
 			{
-				
+
 				if (wpsg_isSizedInt($product_data['pgruppe']))
 				{
-					
+
 					$pgroup = $this->db->fetchRow("SELECT `stock_aktiv`, `stock_value` FROM `".WPSG_TBL_PRODUCTS_GROUP."` WHERE `id` = '".wpsg_q($product_data['pgruppe'])."' ");
-					
+
 					if ($pgroup['stock_aktiv'] === '1')
 					{
-						
+
 						$stock = $pgroup['stock_value'];
-						
-						/* Lagerbestand der Produktgruppe ist aktiv */						
+
+						/* Lagerbestand der Produktgruppe ist aktiv */
 						if ($menge > $stock)
 						{
 
 							return false;
-							
+
 						}
-						
-					}
-					
-				}
-				
-			}
-						
+
+					}
+
+				}
+
+			}
+
 			$product_stock = $this->getBestand($produkt_key);
-			 
+
 			if ($menge > $product_stock)
 			{
-				
+
 				return false;
-				
-			}
-			
+
+			}
+
 			return true;
-			
-						
+
+
 		} // public function checkBestand(&$produkt_key, $menge)
-		
-		public function basket_save_product(&$data, &$product_data_db, $finish_order) 
-		{ 
-			
+
+		public function basket_save_product(&$data, &$product_data_db, $finish_order)
+		{
+
 			return;		// Bestand wird sonst doppelt verringert
 			if ($finish_order !== true) return;
-			
+
 			$product_id = $this->shop->getProduktID($data['productkey']);
 			$product_data = $this->shop->cache->loadProduct($product_id);
 			$stock = $data['menge'];
-			  
+
 			/* Produktgruppe runterzÃ€hlen */
 			if ($this->shop->hasMod('wpsg_mod_productgroups'))
 			{
-			
+
 				$pgroup = $this->db->fetchRow("SELECT `stock_aktiv`, `stock_value` FROM `".WPSG_TBL_PRODUCTS_GROUP."` WHERE `id` = '".wpsg_q($product_data['pgruppe'])."' ");
-			
+
 				if ($pgroup['stock_aktiv'] == '1')
 				{
-						
-					$this->db->Query("
-						UPDATE `".WPSG_TBL_PRODUCTS_GROUP."` SET `stock_value` = `stock_value` - '".wpsg_q($stock)."' WHERE `id` = '".wpsg_q($product_data['pgruppe'])."' 
-					");
-				}
-			
-			}
-				
-			// Produkt runterzÃ€hlen
-				
-			// Wenn ZÃ€hlung im Produkt deaktiviert, dann breche ich hier ab
-			if ($product_data['stock_count'] != '1') return;
-			 
-			if ($this->shop->hasMod('wpsg_mod_productvariants') && preg_match('/^pv_(.*)/', $data['productkey']))
-			{
-					
-				// Bestand der Variationen runterzÃ€hlen
-				$this->shop->callMod('wpsg_mod_productvariants', 'reduceStock', array($data['productkey'], $stock));
-					
-			}
-				
-			// Im Produkt selbst runterzÃ€hlen
-			$this->db->Query("
-				UPDATE `".WPSG_TBL_PRODUCTS."` SET `stock` = `stock` - '".wpsg_q($stock)."' WHERE `id` = '".wpsg_q($product_id)."' 
-			");
-			
-		} // public function basket_save_product(&$data, &$product_data)
-				
-		/* Modulfunktionen */
-		
-		public function checkReduceStock(&$data, &$product_data)
-		{
-			
-			$product_id = $this->shop->getProduktID($data['productkey']);
-			
-			// Tabellen sperren
-			if ($this->shop->get_option('wpsg_lockOrderTables') != '1')
-			{
-				
-				$arLockTables[WPSG_TBL_PRODUCTS] = "WRITE";				
-				if ($this->shop->hasMod('wpsg_mod_productgroups')) $arLockTables[WPSG_TBL_PRODUCTS_GROUP] = "WRITE";
-								
-				$strQuery = "LOCK TABLES ";					
-				foreach ($arLockTables as $table_name => $locktype) $strQuery .= " `".$table_name."` ".$locktype.",";
-				$this->db->Query(substr($strQuery, 0, -1));
-				
-			}
-			
-			//sleep(20);
-			
-			$product_data = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($product_id)."' ");
-			$stock = $data['menge'];
-			
-			// Fehlerbehandlung fÃŒr Produktbestand
-			//if ($product_data['stock_count'] == '1' && $stock > $product_data['stock']) return false;
-			if ($product_data['stock_count'] == '1' && 
-				(($this->shop->get_option('wpsg_mod_stock_allow') === '1') && ($stock > $product_data['stock'])))
-			{
-				$this->db->unlockTables();
-				return false;
-			}
-				
-			/* Produktgruppe runterzÃ€hlen */
-			if ($this->shop->hasMod('wpsg_mod_productgroups'))
-			{
-					
-				$pgroup = $this->db->fetchRow("SELECT `stock_aktiv`, `stock_value` FROM `".WPSG_TBL_PRODUCTS_GROUP."` WHERE `id` = '".wpsg_q($product_data['pgruppe'])."' ");
-					
-				if ($pgroup['stock_aktiv'] == '1')
-				{
-					
-					//if ($pgroup['stock_aktiv'] == '1' && ($stock > $pgroup['stock_value'])) return false;
-					if (($this->shop->get_option('wpsg_mod_stock_allow') === '1') && ($stock > $pgroup['stock_value']))
-					{
-						$this->db->unlockTables();
-						return false;
-					}
-						
+
 					$this->db->Query("
 						UPDATE `".WPSG_TBL_PRODUCTS_GROUP."` SET `stock_value` = `stock_value` - '".wpsg_q($stock)."' WHERE `id` = '".wpsg_q($product_data['pgruppe'])."'
 					");
 				}
-					
-			}
-			
+
+			}
+
+			// Produkt runterzÃ€hlen
+
+			// Wenn ZÃ€hlung im Produkt deaktiviert, dann breche ich hier ab
+			if ($product_data['stock_count'] != '1') return;
+
+			if ($this->shop->hasMod('wpsg_mod_productvariants') && preg_match('/^pv_(.*)/', $data['productkey']))
+			{
+
+				// Bestand der Variationen runterzÃ€hlen
+				$this->shop->callMod('wpsg_mod_productvariants', 'reduceStock', array($data['productkey'], $stock));
+
+			}
+
+			// Im Produkt selbst runterzÃ€hlen
+			$this->db->Query("
+				UPDATE `".WPSG_TBL_PRODUCTS."` SET `stock` = `stock` - '".wpsg_q($stock)."' WHERE `id` = '".wpsg_q($product_id)."'
+			");
+
+		} // public function basket_save_product(&$data, &$product_data)
+
+		/* Modulfunktionen */
+
+		public function checkReduceStock(&$data, &$product_data)
+		{
+
+			$product_id = $this->shop->getProduktID($data['productkey']);
+
+			// Tabellen sperren
+			if ($this->shop->get_option('wpsg_lockOrderTables') != '1')
+			{
+
+				$arLockTables[WPSG_TBL_PRODUCTS] = "WRITE";
+				if ($this->shop->hasMod('wpsg_mod_productgroups')) $arLockTables[WPSG_TBL_PRODUCTS_GROUP] = "WRITE";
+
+				$strQuery = "LOCK TABLES ";
+				foreach ($arLockTables as $table_name => $locktype) $strQuery .= " `".$table_name."` ".$locktype.",";
+				$this->db->Query(substr($strQuery, 0, -1));
+
+			}
+
+			//sleep(20);
+
+			$product_data = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($product_id)."' ");
+			$stock = $data['menge'];
+
+			// Fehlerbehandlung fÃŒr Produktbestand
+			//if ($product_data['stock_count'] == '1' && $stock > $product_data['stock']) return false;
+			if ($product_data['stock_count'] == '1' &&
+				(($this->shop->get_option('wpsg_mod_stock_allow') === '1') && ($stock > $product_data['stock'])))
+			{
+				$this->db->unlockTables();
+				return false;
+			}
+
+			/* Produktgruppe runterzÃ€hlen */
+			if ($this->shop->hasMod('wpsg_mod_productgroups'))
+			{
+
+				$pgroup = $this->db->fetchRow("SELECT `stock_aktiv`, `stock_value` FROM `".WPSG_TBL_PRODUCTS_GROUP."` WHERE `id` = '".wpsg_q($product_data['pgruppe'])."' ");
+
+				if ($pgroup['stock_aktiv'] == '1')
+				{
+
+					//if ($pgroup['stock_aktiv'] == '1' && ($stock > $pgroup['stock_value'])) return false;
+					if (($this->shop->get_option('wpsg_mod_stock_allow') === '1') && ($stock > $pgroup['stock_value']))
+					{
+						$this->db->unlockTables();
+						return false;
+					}
+
+					$this->db->Query("
+						UPDATE `".WPSG_TBL_PRODUCTS_GROUP."` SET `stock_value` = `stock_value` - '".wpsg_q($stock)."' WHERE `id` = '".wpsg_q($product_data['pgruppe'])."'
+					");
+				}
+
+			}
+
 			// Lagerbestand im Produkt zÃ€hlen?
 			if ($product_data['stock_count'] == '1')
 			{
-				
+
 				if ($this->shop->hasMod('wpsg_mod_productvariants') && preg_match('/^pv_(.*)/', $data['productkey']))
 				{
-						
+
 					// Bestand der Variationen runterzÃ€hlen
 					$this->shop->callMod('wpsg_mod_productvariants', 'reduceStock', array($data['productkey'], $stock));
-						
-				}
-				
+
+				}
+
 				// Im Produkt selbst runterzÃ€hlen
 				$this->db->Query("UPDATE `".WPSG_TBL_PRODUCTS."` SET `stock` = `stock` - '".wpsg_q($stock)."' WHERE `id` = '".wpsg_q($product_id)."' ");
-				
+
 				// Benachrichtigung bei Unterschreiten von mindest Menge
 				if (wpsg_isSizedInt($this->shop->get_option('wpsg_mod_stock_minstockproduct')))
 				{
-					
+
 					$product_data = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_PRODUCTS."` WHERE `id` = '".wpsg_q($product_id)."' ");
 					$aktStock = $product_data['stock'];
 					// Wenn Mindestbestellmenge unterschritten oder gleich
 					if ($aktstock <= $product_data['minstockproduct_count']) $this->sendMinStockMail($data['productkey']);
-						
-				}
-				
-			}
-			
-			// Tabellen entsperren			
+
+				}
+
+			}
+
+			// Tabellen entsperren
 			$this->db->Query("UNLOCK TABLES");
-			
+
 			return true;
-			
+
 		} // public function checkReduceStock(&$data, &$product_data)
-		
+
 		/**
 		 * Sendet eine Mail bei erreichen des Mindestbestandes
@@ -695,30 +695,30 @@
 		public function sendMinStockMail($product_key)
 		{
-				
+
 			$product_id = $this->shop->getProduktID($product_key);
 			$product_data = $this->shop->cache->loadProduct($product_id);
-				
+
 			if ($this->shop->get_option('wpsg_htmlmail') === '1')
 			{
-		
+
 				$mail_html = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_stock/stockmail_html.phtml', false);
-		
+
 			}
 			else
 			{
-		
+
 				$mail_html = false;
-		
-			}
-				
+
+			}
+
 			$mail_text = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_stock/stockmail.phtml', false);
-				
+
 			$to = $product_data['minstockproduct_mail'];
 			if (!wpsg_isSizedString($to)) $to = get_bloginfo('admin_email');
-				
+
 			list($subject, $text) = $this->shop->sendMail($mail_text, $to, 'wpsgmodstockminstockmail', array(), false, false, $mail_html, wpsg_translate(__('Der Minimalbestand im Produkt #1# wurde erreicht.', 'wpsg'), $product_data['name']));
-				
+
 		} // public function sendMinStockMail($product_key)
-		
+
 	} // class wpsg_mod_stock extends wpsg_mod_basic
 
Index: /views/mods/mod_stock/product_addedit_content.phtml
===================================================================
--- /views/mods/mod_stock/product_addedit_content.phtml	(revision 6332)
+++ /views/mods/mod_stock/product_addedit_content.phtml	(revision 6333)
@@ -9,5 +9,14 @@
 <?php echo wpsg_drawForm_AdminboxStart(__('Lagerbestand', 'wpsg')); ?>
 
-    <?php echo wpsg_drawForm_Input('wpsg_mod_stock_stock', __('Lagerbestand', 'wpsg'), wpsg_getStr($this->view['data']['stock'], '0')); ?>
+    <?php
+		// $this->view['oProduct']['loadedData']['id/product_key']
+		$key = $this->view['oProduct']->id;
+
+		if ($this->callMod('wpsg_mod_productvariants', 'isVariantsProduct', array($key)) == true) {
+			echo wpsg_drawForm_Input('wpsg_mod_stock_stock', __('Lagerbestand', 'wpsg'), wpsg_getStr($this->view['data']['stock']), array('readonly' => true));
+		} else {
+			echo wpsg_drawForm_Input('wpsg_mod_stock_stock', __('Lagerbestand', 'wpsg'), wpsg_getStr($this->view['data']['stock']), array());
+		}
+    ?>
     <?php echo wpsg_drawForm_Checkbox('wpsg_mod_stock_stock_count', __('Lagerbestand zÃ€hlen', 'wpsg'), wpsg_getStr($this->view['data']['stock_count'], '0')); ?>
 
@@ -15,9 +24,9 @@
 
     <div class="info"><?php echo __('Lagerbestand = Bestand(Variante 1) + Bestand(Variante 2) + Bestand(Variante X)','wpsg'); ?></div>
-    
+
     <?php /* Mailbenachrichtigung beim Erreichen des Minimalbestandes des Produktes */ ?>
     <?php if ($this->get_option('wpsg_mod_stock_minstockproduct') == '1') { ?>
     <?php echo wpsg_drawForm_Input('wpsg_mod_minstockproduct', __('Mindestlagerbestand', 'wpsg'), wpsg_getStr($this->view['data']['minstockproduct_count'])); ?>
-    <?php echo wpsg_drawForm_Input('wpsg_mod_stock_minstockproduct_mail', __('Benachrichtigung an', 'wpsg'), wpsg_getStr($this->view['data']['minstockproduct_mail'])); ?>	
+    <?php echo wpsg_drawForm_Input('wpsg_mod_stock_minstockproduct_mail', __('Benachrichtigung an', 'wpsg'), wpsg_getStr($this->view['data']['minstockproduct_mail'])); ?>
     <?php }?>
 
