Index: /changelog
===================================================================
--- /changelog	(revision 7603)
+++ /changelog	(revision 7604)
@@ -297,2 +297,3 @@
 - Bugfix: Speichern von Produktattributen RTE mit Links wieder mÃ¶glich / Ticket #699
 - Bugfix: Speichern des Fonts in DownloadPlus wieder mÃ¶glich / Ticket #698
+- Feature: Beim kopieren/speichern von Produkten kann der Bestand innerhalb einer Produktgruppe automatisch ermittelt werden (Optional)
Index: /model/wpsg_model.class.php
===================================================================
--- /model/wpsg_model.class.php	(revision 7603)
+++ /model/wpsg_model.class.php	(revision 7604)
@@ -76,4 +76,5 @@
 			
 		} // public function __get($name)
+		 
 		
 		/**
@@ -101,6 +102,5 @@
 				$arReturn = [];
 				
-				foreach ($id as $_id)
-				{
+				foreach ($id as $_id) {
 					
 					$arReturn[$_id] = self::getInstance($_id);
Index: /model/wpsg_product.class.php
===================================================================
--- /model/wpsg_product.class.php	(revision 7603)
+++ /model/wpsg_product.class.php	(revision 7604)
@@ -157,7 +157,9 @@
 
 		} // public function getMeta($meta_key)
-
-		public function getProductgroup()
-		{
+		
+		/**
+		 * @return wpsg_productgroup
+		 */
+		public function getProductgroup() {
 
 			return wpsg_productgroup::getInstance($this->pgruppe);
Index: /mods/mod_productgroups/wpsg_productgroup.php
===================================================================
--- /mods/mod_productgroups/wpsg_productgroup.php	(revision 7603)
+++ /mods/mod_productgroups/wpsg_productgroup.php	(revision 7604)
@@ -38,5 +38,14 @@
 
 	    }
-
+	
+		/**
+		 * @return string
+		 */
+	    public function getLabel() {
+			
+			return $this->__get('name');
+			
+		} 
+	    
         /* Statische Funktionen */
 
Index: /mods/wpsg_mod_stock.class.php
===================================================================
--- /mods/wpsg_mod_stock.class.php	(revision 7603)
+++ /mods/wpsg_mod_stock.class.php	(revision 7604)
@@ -25,9 +25,9 @@
 		} // public function __construct()
 
-		public function install()
-		{
+		public function install() {
 
 			$this->shop->checkDefault('wpsg_mod_stock_showBackendStock', '1');
-
+			$this->shop->checkDefault('wpsg_mod_stock_updateProductSave', '1');
+			
 			require_once(WPSG_PATH_WP.'/wp-admin/includes/upgrade.php');
 
@@ -64,4 +64,10 @@
 		    $this->shop->update_option('wpsg_mod_stock_minstockproduct', $_REQUEST['wpsg_mod_stock_minstockproduct'], false, false, WPSG_SANITIZE_CHECKBOX);
 		    $this->shop->update_option('wpsg_mod_stock_hideSoldout', $_REQUEST['wpsg_mod_stock_hideSoldout'], false, false, WPSG_SANITIZE_CHECKBOX);
+		    
+		    if ($this->shop->hasMod('wpsg_mod_productgroups')) {
+		    
+		    	$this->shop->update_option('wpsg_mod_stock_updateProductSave', $_REQUEST['wpsg_mod_stock_updateProductSave'], false, false, WPSG_SANITIZE_CHECKBOX);
+		    	
+			}
 
 			if ($this->shop->hasMod('wpsg_mod_productindex')) {
@@ -127,17 +133,34 @@
 
 		} // public function produkt_edit(&$data)
-
-		public function produkt_save(&$produkt_id)
-		{
-
-			$this->db->UpdateQuery(WPSG_TBL_PRODUCTS, array(
-			    "stock" => wpsg_q(wpsg_sinput(WPSG_SANITIZE_TEXTFIELD, $_REQUEST['wpsg_mod_stock_stock'])),
-			    "stock_count" => wpsg_q(wpsg_sinput(WPSG_SANITIZE_CHECKBOX, $_REQUEST['wpsg_mod_stock_stock_count'])),
-			    "minstockproduct_count" => wpsg_q(wpsg_sinput(WPSG_SANITIZE_TEXTFIELD, $_REQUEST['wpsg_mod_minstockproduct'])),
-			    "minstockproduct_mail" => wpsg_q(wpsg_sinput(WPSG_SANITIZE_EMAIL, $_REQUEST['wpsg_mod_stock_minstockproduct_mail']))
-			), "`id` = '".wpsg_q(wpsg_sinput(WPSG_SANITIZE_TEXTFIELD, $produkt_id))."'");
-
+	
+		public function produkt_save_before(&$product_data) {
+			
+			wpsg_checkRequest('stock', [WPSG_SANITIZE_INT, ['allowEmpty' => true]], __('Lagerbestand'),$product_data, $_REQUEST['wpsg_mod_stock_stock']);
+			wpsg_checkRequest('stock_count', [WPSG_SANITIZE_CHECKBOX], __('Lagerbestand zÃ€hlen'), $product_data, $_REQUEST['wpsg_mod_stock_stock_count']);
+			wpsg_checkRequest('minstockproduct_count', [WPSG_SANITIZE_INT], __('Mindestlagerbestand zÃ€hlen'), $product_data, $_REQUEST['wpsg_mod_minstockproduct']);
+			wpsg_checkRequest('minstockproduct_mail', [WPSG_SANITIZE_EMAIL], __('Lagerbestand / Benachrichtigung an'), $product_data, $_REQUEST['wpsg_mod_stock_minstockproduct_mail']);
+			 
+		}
+		
+		public function produkt_save(&$product_id) {
+
+			if ($this->shop->get_option('wpsg_mod_stock_updateProductSave') === '1' && $this->shop->hasMod('wpsg_mod_productgroups')) {
+
+				$this->calculateProductgroupStock($product_id);
+								
+			}
+			
 		} // public function produkt_save(&$produkt_id)
-
+		
+		public function produkt_copy(&$produkt_id, &$copy_id) {
+			
+			if ($this->shop->get_option('wpsg_mod_stock_updateProductSave') === '1' && $this->shop->hasMod('wpsg_mod_productgroups')) {
+				
+				$this->calculateProductgroupStock($copy_id);
+				
+			}
+			
+		}
+		
 		public function produkt_edit_sidebar(&$produkt_data)
 		{
@@ -413,4 +436,42 @@
 		/* Modulfunktionen */
 
+		public function calculateProductgroupStock($product_id) {
+			
+			$oProduct = wpsg_product::getInstance($product_id);
+			$oProductGroup = $oProduct->getProductgroup();
+			
+			if ($oProductGroup->isLoaded()) {
+				
+				$arProductRows = $this->db->fetchAssoc("SELECT P.`id`, P.`stock` FROM `".WPSG_TBL_PRODUCTS."` AS P WHERE P.`pgruppe` = '".wpsg_q($oProductGroup->getId())."' ");
+				
+				$stock = 0;
+				
+				foreach ($arProductRows as $p_row) {
+					
+					$stock += intval($p_row['stock']);
+					
+				}
+				
+				$stock_pre = intval($oProductGroup->__get('stock_value'));
+				
+				$this->db->UpdateQuery(WPSG_TBL_PRODUCTS_GROUP, [
+					'stock_value' => wpsg_q($stock)
+				], " `id` = '".wpsg_q($oProductGroup->getId())."' ");
+				
+				if ($stock_pre !== $stock && is_admin()) {
+					
+					$this->shop->addBackendMessage(wpsg_translate(
+						__('Der Lagerbestand in Produktgruppe #1# wurde von #2# auf #3# automatisch geÃ€ndert.', 'wpsg'),
+						$oProductGroup->getLabel(),
+						$stock_pre,
+						$stock
+					));
+					
+				}
+				
+			}
+			
+		}
+		
 		/**
 		 * Gibt den aktuellen Bestand fÃŒr ein Produkt zurÃŒck
@@ -760,3 +821,2 @@
 	} // class wpsg_mod_stock extends wpsg_mod_basic
 
-?>
Index: /views/mods/mod_stock/settings_edit.phtml
===================================================================
--- /views/mods/mod_stock/settings_edit.phtml	(revision 7603)
+++ /views/mods/mod_stock/settings_edit.phtml	(revision 7604)
@@ -22,3 +22,11 @@
 <?php echo wpsg_drawForm_Checkbox('wpsg_mod_stock_minstockproduct',  __('Minimalbestand im Produkt hinterlegen', 'wpsg'), $this->get_option('wpsg_mod_stock_minstockproduct'), array('help' => 'wpsg_mod_stock_minstockproduct')); ?>
 <?php echo wpsg_drawForm_Checkbox('wpsg_mod_stock_hideSoldout',  __('Ausverkaufte Produkte nicht anzeigen', 'wpsg'), $this->get_option('wpsg_mod_stock_hideSoldout'), array('help' => 'wpsg_mod_stock_hideSoldout')); ?>
+
+<?php if ($this->hasMod('wpsg_mod_productgroups')) { ?>
+	
+	<br />
+	
+	<?php echo wpsg_drawForm_Checkbox('wpsg_mod_stock_updateProductSave', __('Bestand in Produktgruppen automatisch ermitteln.', 'wpsg'), $this->get_option('wpsg_mod_stock_updateProductSave'), ['help' => 'wpsg_mod_stock_updateProductSave']); ?>
+
+<?php } ?>
  
