Index: /mods/wpsg_mod_productvariants.class.php
===================================================================
--- /mods/wpsg_mod_productvariants.class.php	(revision 7095)
+++ /mods/wpsg_mod_productvariants.class.php	(revision 7096)
@@ -93,4 +93,5 @@
 				price double(10,2) NOT NULL,
 				stock int(11) NOT NULL,
+				min_stock int(11) NOT NULL,
 				images text NOT NULL,
 				images_set text NOT NULL,
@@ -168,11 +169,11 @@
 		public function produkt_copy(&$produkt_id, &$copy_id)
 		{
-			
+
 			// Kopieren der Varianten/Variationen
 			$variants = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_VARIANTS."` WHERE `product_id` = '".wpsg_q($produkt_id)."'");
 			$pos = 0;
-			
+
 			foreach ($variants as $v) {
-				
+
 				$v['product_id'] = $copy_id;
 				$v['pos'] = $pos;
@@ -180,5 +181,5 @@
 				unset($v['id']);
 				$newvid = $this->db->ImportQuery(WPSG_TBL_VARIANTS, $v);
-				
+
 				// WPSG_TBL_PRODUCTS_VARIANT schreiben
 				$pv = array();
@@ -189,9 +190,9 @@
 				$newpvid = $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIANT, $pv);
 				$pos++;
-				
+
 				$varis = $this->db->fetchAssoc("SELECT * FROM `".WPSG_TBL_VARIANTS_VARI."` WHERE `variant_id` = '".wpsg_q($vid)."'");
 
 				$mimages = array();
-				
+
 				foreach ($varis as $vv) {
 					$vv['variant_id'] = $newvid;
@@ -203,23 +204,23 @@
 					$pvari['variation_id'] = $newvvid;
 					$pvari['product_id'] = $copy_id;
-					
+
 					// images/images_set
 					$images = explode(',', $pvari['images']);
 					$images_set = explode(',', $pvari['images_set']);
 					$ih = new wpsg_imagehandler();
-					
+
 					$nimages = array();
 					$nimages_set = array();
-					
+
 					foreach ($images as $postid) {
 
 						if (!in_array($postid, $mimages['alt'])) {
 							$mimages['alt'][] = $postid;
-							$post = $this->db->fetchRow("SELECT * FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID`='".wpsg_q($postid)."'");  
+							$post = $this->db->fetchRow("SELECT * FROM `".$GLOBALS['wpdb']->prefix."posts` WHERE `ID`='".wpsg_q($postid)."'");
 							// addImageToProduct($file, $product_id)
 							$npostid = $ih->addImageToProduct($post['guid'], $copy_id);
 							//$nimages[] = $npostid;
 							$mimages['neu'][] = $npostid;
-							
+
 						}
 
@@ -234,16 +235,16 @@
 						$nimages[] = $mimages['neu'][$ak];
 					}
-					
+
 					$pvari['images'] = implode(',', $nimages);
 					$pvari[images_set] = implode(',', $nimages_set);
 					unset($pvari['id']);
 					$newpvid = $this->db->ImportQuery(WPSG_TBL_PRODUCTS_VARIATION, $pvari);
-					
-				}
-				
-			}
-			
+
+				}
+
+			}
+
 		}	// public function produkt_copy($produkt_id, $copy_id)
-		
+
 		public function template_redirect()
 		{
@@ -251,5 +252,5 @@
 			if (wpsg_isSizedString($_REQUEST['action'], 'wpsg_productvariants_switch'))
 			{
-				
+
 				if (wpsg_isSizedInt($_REQUEST['wpsg_post_id']))
 				{
@@ -267,5 +268,5 @@
 
                 $this->getProductKeyFromRequest($product_key, $product_id, $form_data);
-                
+
 				$product_data = $this->shop->loadProduktArray($product_id, array(
 					'id' => $product_key,
@@ -286,5 +287,5 @@
 
 				//$dat = $this->shop->renderProdukt($product_data, $template);
-				
+
 				die($this->shop->renderProdukt($product_data, $template));
 
@@ -295,9 +296,9 @@
 		public function loadProduktArray(&$product_data)
 		{
-            
+
 			//if ($GLOBALS['step'] > 4) return;
 
 			$product_data['arVariant'] = $this->getVariants($product_data['product_id'], true, true, true);
-			
+
 			if (wpsg_isSizedArray($product_data['arVariant']))
 			{
@@ -314,8 +315,8 @@
 
 					$arDefaultKey = array();
-                    
+
 					foreach ($product_data['arVariant'] as $variant_id => $variant_data)
 					{
- 
+
 						$arDefaultKeyValues = $variant_id.':'.array_keys($variant_data['arVariation'])[0];
 						$arDefaultKey[] = $arDefaultKeyValues;
@@ -327,20 +328,20 @@
 					$product_data['product_key'] = $strDefaultKey;
 					$product_data['id'] = $strDefaultKey;
- 
-				}
-				               
+
+				}
+
 				$arProductKey = $this->explodeProductKey($product_data['product_key']);
 
                 $product_data['stock'] = 0;
-                
+
                 foreach ($arProductKey['arVari'] as $var_id => $vari_id) {
 
                     $product_data['stock'] += $product_data['arVariant'][$var_id]['arVariation'][$vari_id]['stock'];
-                    
+
                 }
-                
+
 				$arProductImagesPossible = array();
 				$arPostidsImagesPossible = array();
-				
+
 				// Gesetzte Variante wÃ€hlen und aufwerten
 				foreach ($product_data['arVariant'] as $var_id => $var_data)
@@ -380,7 +381,7 @@
 								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;
 
@@ -393,8 +394,8 @@
 
 				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)))
@@ -422,5 +423,5 @@
 
 				}
-				
+
 				// Preise fÃŒr das Frontend ermitteln
 				if ($this->shop->getFrontendTaxView() === WPSG_BRUTTO)
@@ -775,4 +776,11 @@
 
         		}
+		        else if ($_REQUEST['typ'] == "vari_min_stock")
+		        {
+
+			        $_REQUEST['value'] = intval($_REQUEST['value']);
+			        $vp_data[$_REQUEST['var_id']]['vari'][$_REQUEST['vari_id']]['min_stock'] = $_REQUEST['value'];
+
+		        }
         		else if ($_REQUEST['typ'] == "var_name")
         		{
@@ -832,4 +840,11 @@
 
         		}
+		        else if ($_REQUEST['typ'] == "var_min_stock")
+		        {
+
+			        $_REQUEST['value'] = intval($_REQUEST['value']);
+			        $vp_data[$_REQUEST['var_id']]['min_stock'] = $_REQUEST['value'];
+
+		        }
 
         		$this->saveVariantsData($vp_data);
@@ -1029,5 +1044,5 @@
 
         				$strQuery =
-        				"SELECT PVV.`id`, PVV.`variation_id`, PVV.`product_id`, PVV.`anr`, PVV.`price`, PVV.`stock`, PVV.`images`, PVV.`weight`, PVV.`fmenge`, PVV.`active`,
+        				"SELECT PVV.`id`, PVV.`variation_id`, PVV.`product_id`, PVV.`anr`, PVV.`price`, PVV.`stock`, PVV.`min_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`
@@ -1495,5 +1510,5 @@
 				$value = $_REQUEST['value'];
 				$f = $_REQUEST['field'];
-				if (($f == 'vari_price') || ($f == 'vari_stock') || ($f == 'vari_weight')) {
+				if (($f == 'vari_price') || ($f == 'vari_stock') || ($f == 'vari_min_stock') || ($f == 'vari_weight')) {
 					$value =  wpsg_tf($value);
 				}
@@ -1568,5 +1583,5 @@
 
 				$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.`images_set`, PV.`weight`, PV.`fmenge` ";
+				$strQuerySELECT .= " , PV.`id` AS iid, PV.`variation_id`, PV.`active`, PV.`anr`, PV.`price`, PV.`stock`, PV.`min_stock`, PV.`images`, PV.`images_set`, PV.`weight`, PV.`fmenge` ";
 
 			}
@@ -1594,7 +1609,55 @@
 			$arVari = $this->db->fetchAssoc($strQuery, "id");
 
+			$this->checkMinStock($arVari, $product_id);
+
 			return $arVari;
 
 		} // public function getVariationOfVariant($variant_id)
+
+		/*
+		 * PrÃŒft, ob der Minimallagerbestand erreicht wurde und schickt - sofern dieser Fall eintritt - eine E-Mail
+		 */
+		public function checkMinStock($arVari, $product_id)
+		{
+
+			$product_data = $this->shop->cache->loadProduct($product_id);
+
+			$variation_id = 0;
+			if(wpsg_isSizedArray($arVari) && count($arVari) === 1)
+				foreach($arVari as $i) $variation_id = $i['id'];
+
+			if((int)$arVari[$variation_id]['stock'] === (int)$arVari[$variation_id]['min_stock'])
+			{
+
+				// Spezifischen Index setzen um Email als "Varianten-Information" zu identifizieren
+				$adminName = $this->shop->get_option('wpsg_shopdata_owner')?:__("Administrator", "wpsg");
+				$GLOBALS['stockemail_prodvariant'] = array("produkt" => $product_data, "variant" => $arVari[$variation_id], "admin_name" => $adminName);
+
+				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 der Variation #1# des Produkts #2# wurde erreicht.', 'wpsg'), $arVari[$variation_id]['name'], $product_data['name']));
+
+				// Wenn Email gesendet, spezifischen Index lÃ¶schen
+				if(isset($subject) && wpsg_isSized($subject) && isset($text) && wpsg_isSized($text))
+					unset($GLOBALS['stockemail_prodvariant']);
+
+			}
+
+		} // public static function checkMinStock($arVari)
 
 		private function unserializeVariation(&$arVari) {
@@ -1694,4 +1757,6 @@
 
 			$this->setStockFromVariation($produkt_key);
+
+			$this->checkMinStock($arVar, $produkt_key);
 
 			// Array zurÃŒckspeichern
Index: /views/mods/mod_productvariants/admin_edit.phtml
===================================================================
--- /views/mods/mod_productvariants/admin_edit.phtml	(revision 7095)
+++ /views/mods/mod_productvariants/admin_edit.phtml	(revision 7096)
@@ -30,5 +30,6 @@
 				<?php if ($this->hasMod('wpsg_mod_stock')) { ?>
         		<th class="col_stock"><?php echo __('Lagerbestand', 'wpsg'); $colspan ++; ?></th>
-        		<?php } ?>
+		        <th class="col_stock col_min_stock"><?php echo __('Minimallagerbestand', 'wpsg'); $colspan ++; ?></th>
+		        <?php } ?>
 
 				<?php if ($this->hasMod('wpsg_mod_weight')) { ?>
@@ -47,5 +48,5 @@
         		
       		</tr>
-    	</thead>    	
+    	</thead>
     	<?php $i = 0; foreach ($this->view['arVariation'] as $vari) { $i ++; ?>
     	<tbody id="vari_<?php echo $vari['id']; ?>">
@@ -119,5 +120,13 @@
 						});
 
-						jQuery('#productvariation_weight_<?php echo $vari['id']; ?>').wpsg_editable('<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_productvariants&subaction=admin_inlineEdit&noheader=1', {
+					    jQuery('#productvariation_min_stock_<?php echo $vari['id']; ?>').wpsg_editable('<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_productvariants&subaction=admin_inlineEdit&noheader=1', {
+						    submitdata: {
+							    field: 'vari_min_stock',
+							    product_id: jQuery('#wpsg_mod_productvariants_product_id').val(),
+							    field_id: '<?php echo $vari['id']; ?>'
+						    }
+					    });
+
+					    jQuery('#productvariation_weight_<?php echo $vari['id']; ?>').wpsg_editable('<?php echo WPSG_URL_WP; ?>wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_productvariants&subaction=admin_inlineEdit&noheader=1', {
 							submitdata: { 
 					    		field: 'vari_weight',
@@ -147,7 +156,8 @@
     			<td class="col_artnr"><span class="wpsg_editable" id="productvariation_anr_<?php echo $vari['id']; ?>"><?php echo wpsg_hspc($vari['anr']); ?></span></td>    			
     			<td class="col_price"><span class="wpsg_editable" id="productvariation_price_<?php echo $vari['id']; ?>"><?php echo wpsg_hspc(wpsg_ff($vari['price'], $this->get_option('wpsg_currency'))); ?></span></td>
- 
+
 				<?php if ($this->hasMod('wpsg_mod_stock')) { ?>
     			<td class="col_stock"><span class="wpsg_editable" id="productvariation_stock_<?php echo $vari['id']; ?>"><?php echo wpsg_hspc($vari['stock']); ?></span></td>
+    			<td class="col_stock"><span class="wpsg_editable" id="productvariation_min_stock_<?php echo $vari['id']; ?>"><?php echo wpsg_hspc($vari['min_stock']); ?></span></td>
         		<?php } ?>
 
Index: /views/mods/mod_stock/stockmail.phtml
===================================================================
--- /views/mods/mod_stock/stockmail.phtml	(revision 7095)
+++ /views/mods/mod_stock/stockmail.phtml	(revision 7096)
@@ -9,15 +9,30 @@
 ?>
 
-<?php echo __('Hallo Administrator,', 'wpsg'); ?>
-
-<?php echo wpsg_translate(__('Ein Produkt hat das Erreichen des minimalen Lagerbestand am #1# um #2# Uhr gemeldet', 'wpsg'), date('d.m.Y'), date('H:i')); ?>
+<p><?php echo __('Hallo ', 'wpsg').$GLOBALS['stockemail_prodvariant']['admin_name'].','; ?></p>
 
 <?php
-echo ('');
-foreach ((array)$this->basket->arProdukte as $p)
-	$id = $p['id'];
-	echo ('');
-	echo __('Produkt').' : '.$p['id'].'  '.$p['name'];
+	if(isset($GLOBALS['stockemail_prodvariant']) && wpsg_isSizedArray($GLOBALS['stockemail_prodvariant']))
+	{
+
+		echo wpsg_translate(__('Eine Produktvariation hat das Erreichen des minimalen Lagerbestands am #1# um #2# Uhr gemeldet.', 'wpsg'), date('d.m.Y'), date('H:i'));
+		echo ('');
+		echo __("Produkt").': '.$GLOBALS['stockemail_prodvariant']['produkt']['id'].' '.$GLOBALS['stockemail_prodvariant']['produkt']['name'];
+		echo ('');
+		echo __("Produktvariation").': '.$GLOBALS['stockemail_prodvariant']['variant']['id'].' '.$GLOBALS['stockemail_prodvariant']['variant']['name'];
+
+	}
+	else
+	{
+
+		echo wpsg_translate(__('Ein Produkt hat das Erreichen des minimalen Lagerbestand am #1# um #2# Uhr gemeldet.', 'wpsg'), date('d.m.Y'), date('H:i'));
+		echo ('');
+			foreach ((array)$this->basket->arProdukte as $p)
+				$id = $p['id'];
+				echo ('');
+				echo __('Produkt').': '.$p['id'].'  '.$p['name'];
+
+	}
 ?>
+
 <?php echo __('Mit freundlichen GrÃŒÃen', 'wpsg'); ?>
 
Index: /views/mods/mod_stock/stockmail_html.phtml
===================================================================
--- /views/mods/mod_stock/stockmail_html.phtml	(revision 7095)
+++ /views/mods/mod_stock/stockmail_html.phtml	(revision 7096)
@@ -7,16 +7,32 @@
 	$this->htmlMail = true;
 
+	include(WPSG_PATH_VIEW . 'mailtemplates/html/logo.phtml');
+
 ?>
 
-<p><?php echo __('Hallo Administrator,', 'wpsg'); ?></p>
-
-<p><?php echo wpsg_translate(__('Ein Produkt hat das Erreichen des minimalen Lagerbestand am #1# um #2# Uhr gemeldet', 'wpsg'), date('d.m.Y'), date('H:i')); ?></p>
+<p><?php echo __('Hallo ', 'wpsg').$GLOBALS['stockemail_prodvariant']['admin_name'].','; ?></p>
 
 <?php
-echo ('<br />');
-foreach ((array)$this->basket->arProdukte as $p)
-	$id = $p['id'];
-	echo ('<br />');
-	echo __('Produkt').' : '.$p['id'].'  '.$p['name'];
+	if(isset($GLOBALS['stockemail_prodvariant']) && wpsg_isSizedArray($GLOBALS['stockemail_prodvariant']))
+	{
+
+		echo wpsg_translate(__('Eine Produktvariation hat das Erreichen des minimalen Lagerbestands am #1# um #2# Uhr gemeldet.', 'wpsg'), date('d.m.Y'), date('H:i'));
+		echo ('<br />');
+		echo __("Produkt").': '.$GLOBALS['stockemail_prodvariant']['produkt']['id'].' '.$GLOBALS['stockemail_prodvariant']['produkt']['name'];
+		echo ('<br />');
+		echo __("Produktvariation").': '.$GLOBALS['stockemail_prodvariant']['variant']['id'].' '.$GLOBALS['stockemail_prodvariant']['variant']['name'];
+
+	}
+	else
+	{
+
+		echo wpsg_translate(__('Ein Produkt hat das Erreichen des minimalen Lagerbestand am #1# um #2# Uhr gemeldet.', 'wpsg'), date('d.m.Y'), date('H:i'));
+		echo ('<br />');
+		foreach ((array)$this->basket->arProdukte as $p)
+			$id = $p['id'];
+			echo ('<br />');
+			echo __('Produkt').': '.$p['id'].'  '.$p['name'];
+
+	}
 ?>
 
Index: /views/mods/mod_voucherproduct/gutschein_mail_html.phtml
===================================================================
--- /views/mods/mod_voucherproduct/gutschein_mail_html.phtml	(revision 7095)
+++ /views/mods/mod_voucherproduct/gutschein_mail_html.phtml	(revision 7096)
@@ -4,4 +4,6 @@
 	 * Template fÃŒr die Mail, der die gekauften Gutscheine versendet (HTML)
 	 */
+
+	include(WPSG_PATH_VIEW . 'mailtemplates/html/logo.phtml');
 
 ?>
