Index: /changelog
===================================================================
--- /changelog	(revision 7660)
+++ /changelog	(revision 7661)
@@ -327,2 +327,5 @@
 - Feature: Zahlungsart "Kostenfrei" fÃŒr Bestellungen die mit 0,- durchgefÃŒhrt werden / Task  #709
 - Feature: FÃŒllmengen ÃŒberarbeitet (Bezugseinheit und Umrechnung im Produkt unterschiedlich und definierbar) 
+
+#4.2.1
+- Feature: Option "Nach dem entfernen eines Produktes auf die gÃŒnstigste Zahlungsart wechseln" hinzugefÃŒgt
Index: /controller/wpsg_AdminController.class.php
===================================================================
--- /controller/wpsg_AdminController.class.php	(revision 7660)
+++ /controller/wpsg_AdminController.class.php	(revision 7661)
@@ -2128,6 +2128,7 @@
 				$this->update_option('wpsg_autolineending', $_REQUEST['wpsg_autolineending'], false, false, WPSG_SANITIZE_CHECKBOX);
 				$this->update_option('wpsg_dontcopymedia', $_REQUEST['wpsg_dontcopymedia'], false, false, WPSG_SANITIZE_CHECKBOX);
+				$this->update_option('wpsg_switchtolowestshippingafterproductremove', $_REQUEST['wpsg_switchtolowestshippingafterproductremove'], false, false, WPSG_SANITIZE_CHECKBOX);
 				$this->update_option('wpsg_geo_determination', $_REQUEST['wpsg_geo_determination'], false, false, WPSG_SANITIZE_VALUES, [0, 3, 4]);
-
+				
 				$this->addBackendMessage(__('Einstellungen gespeichert.', 'wpsg'));
 
Index: /controller/wpsg_ShopController.class.php
===================================================================
--- /controller/wpsg_ShopController.class.php	(revision 7660)
+++ /controller/wpsg_ShopController.class.php	(revision 7661)
@@ -4658,11 +4658,11 @@
 
 			if (isset($_SESSION['wpsg']['checkout']['shipping'])) {
-					
+								
 				if (!array_key_exists($_SESSION['wpsg']['checkout']['shipping'], $this->arShipping)) {
-					
+						
 					$_SESSION['wpsg']['checkout']['shipping'] = array_keys($this->arShipping)[0];
-					
-				}
-								
+						
+				}
+												
 			}
 			
Index: /lib/wpsg_basket.class.php
===================================================================
--- /lib/wpsg_basket.class.php	(revision 7660)
+++ /lib/wpsg_basket.class.php	(revision 7661)
@@ -213,12 +213,42 @@
 		 * Entfernt ein Produkt aus dem Warenkorb
 		 */
-		public function removeProduktFromSession($produkt_index)
-		{
+		public function removeProduktFromSession($produkt_index) {
 			
 			unset($_SESSION['wpsg']['basket'][$produkt_index]);
 			
-			$this->shop->callMods('basket_removeProduktFromSession', [$produkt_index]);
-			
+			$this->shop->callMods('basket_removeProduktFromSession', [$produkt_index]);			
 			$this->shop->cache->clearShopBasketArray();
+			$this->shop->basket->initFromSession(true);
+			
+			if ($this->shop->get_option('wpsg_switchtolowestshippingafterproductremove') === '1' && isset($_SESSION['wpsg']['checkout']['shipping'])) {
+				
+				$oCalculation = \wpsg\wpsg_calculation::getSessionCalculation(true);
+				$oCalculation->getCalculationArray();
+				
+				$min_key = null; $min_value = null;
+				
+				$this->shop->arShipping = $this->shop->arShippingAll;
+				$this->shop->checkShippingAvailable();
+				
+				foreach ($this->shop->arShipping as $k => $v) {
+					
+					$price_shipping = $oCalculation->calculateCostKey($v['price']);
+					
+					if ($min_key === null || $price_shipping < $min_value) {
+						
+						$min_key = $k;
+						$min_value = $price_shipping;
+						
+					}
+					
+				}
+				
+				if ($min_key !== null) {
+					
+					$_SESSION['wpsg']['checkout']['shipping'] = $min_key;
+										
+				}
+								
+			}
 			
 			return true;
@@ -1784,5 +1814,4 @@
 		} // public function toArray()
 		
-		
 		/**
 		 * Verteilt den Wert $value auf die MwSt SÃ€tze in $arBasket
@@ -1840,6 +1869,4 @@
 			
 		} // public function addMwSt(&$arBasket, $value)
-		
-		
 		
 		/**
@@ -1992,3 +2019,2 @@
 	} // class wpsg_basket
 
-?>
Index: /lib/wpsg_calculation.class.php
===================================================================
--- /lib/wpsg_calculation.class.php	(revision 7660)
+++ /lib/wpsg_calculation.class.php	(revision 7661)
@@ -443,5 +443,6 @@
                 								
 						if (strpos($set, '|') !== false) {
-									
+							
+							/*
 							list($typ, $set) = explode('-', $set);
 							
@@ -464,5 +465,8 @@
 							
 							$kosten = wpsg_tf($kosten);
-				
+							*/
+				
+							$kosten = $this->calculateCostKey($set);
+							
 							if ($this->shop->getBackendTaxview() === WPSG_NETTO) {
 								
@@ -1252,4 +1256,38 @@
             
         }
+	
+		/**
+		 * Berechnet einen KostenschlÃŒssel
+		 * benÃ¶tigt eine geladene Kalkulation
+		 * @param $set
+		 * @return float|string
+		 * @throws \Exception
+		 */
+        public function calculateCostKey($set) {
+	
+			list($typ, $set) = explode('-', $set);
+	
+			$arKosten = explode('|', $set);
+			$arKosten = array_reverse($arKosten);
+	
+			if ($typ === 'w') $value = (($this->shop->getBackendTaxview() === WPSG_NETTO)?$this->arCalculation['sum']['productsum_netto']:$this->arCalculation['sum']['productsum_brutto']);
+			else if ($typ === 's') $value = $this->arCalculation['sum']['amount']; // Menge
+			else if ($typ === 'g') $value = $this->dWeight; // Gewicht
+			else throw new \Exception(wpsg_translate(__('Typ (#1#) fÃŒr KostenschlÃŒssel nicht definiert.', 'wpsg'), $typ));
+	
+			foreach ($arKosten as $k) {
+		
+				$arP = explode(":", $k);
+		
+				if (sizeof($arP) == 1) $kosten = $arP[0];
+				else if (wpsg_tf($arP[0]) <= $value) $kosten = $arP[1];
+		
+			}
+	
+			$kosten = wpsg_tf($kosten);
+        	
+        	return $kosten;
+			
+		}
         
         /* Private */
@@ -1489,9 +1527,9 @@
 		 * return \wpsg\wpsg_calculation
 		 */
-		public static function getSessionCalculation() {
+		public static function getSessionCalculation($no_cache = false) {
 			
 			$cache_key = __FUNCTION__.implode('|', \func_get_args());
 			
-			if (!isset(self::$functionscache[$cache_key])) {
+			if (!isset(self::$functionscache[$cache_key]) || $no_cache) {
 			
 				$oCalculation = new wpsg_calculation();
Index: /mods/wpsg_mod_versandarten.class.php
===================================================================
--- /mods/wpsg_mod_versandarten.class.php	(revision 7660)
+++ /mods/wpsg_mod_versandarten.class.php	(revision 7661)
@@ -642,3 +642,2 @@
 	} // class wpsg_mod_versandarten extends wpsg_mod_basic
 
-?>
Index: /views/admin/extended.phtml
===================================================================
--- /views/admin/extended.phtml	(revision 7660)
+++ /views/admin/extended.phtml	(revision 7661)
@@ -49,5 +49,6 @@
 				<?php echo wpsg_drawForm_Checkbox('wpsg_nocache', __('Cachen von dynamischen Shopseiten verhindern', 'wpsg'), $this->get_option('wpsg_nocache'), array('help' => 'wpsg_nocache')); ?>
 				<?php echo wpsg_drawForm_Checkbox('wpsg_autolineending', __('MAC KompatibilitÃ€t bei Dateiimporten', 'wpsg'), $this->get_option('wpsg_autolineending'), array('help' => 'wpsg_autolineending')); ?>
-				<?php echo wpsg_drawForm_Checkbox('wpsg_dontcopymedia', __('Produktbilder nicht kopieren', 'wpsg'), $this->get_option('wpsg_dontcopymedia'), ['help' => 'wpsg_dontcopymedia']); ?>
+				<?php echo wpsg_drawForm_Checkbox('wpsg_dontcopymedia', __('Produktbilder nicht kopieren', 'wpsg'), $this->get_option('wpsg_dontcopymedia'), ['help' => 'wpsg_dontcopymedia']); ?>				
+				<?php echo wpsg_drawForm_Checkbox('wpsg_switchtolowestshippingafterproductremove', __('Nach dem entfernen eines Produktes auf die gÃŒnstigste Zahlungsart wechseln', 'wpsg'), $this->get_option('wpsg_switchtolowestshippingafterproductremove'), ['help' => 'wpsg_switchtolowestshippingafterproductremove']); ?>
 				<?php echo wpsg_drawForm_Select('wpsg_geo_determination', __('Abfrage des Kundenstandortes (EU-Leistungsortregel)', 'wpsg'), $this->view['arGeoMode'], $this->get_option('wpsg_geo_determination'), array('help' => 'wpsg_geo_determination')); ?>
 							
