Index: /changelog
===================================================================
--- /changelog	(revision 8106)
+++ /changelog	(revision 8107)
@@ -518,2 +518,3 @@
 #4.3.8
 - Bugfix: Downloadprodukte werden bei Versandkosten Staffelpreisen nicht mehr berÃŒcksichtigt
+- Feature: Optimierung Exportprofile
Index: /mods/wpsg_mod_abo.class.php
===================================================================
--- /mods/wpsg_mod_abo.class.php	(revision 8106)
+++ /mods/wpsg_mod_abo.class.php	(revision 8107)
@@ -1075,5 +1075,5 @@
         }
 
-        public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $product_key, $product_index, $profil_separator) {
+        public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) {
 
             if (!in_array($field_value, ['wpsg_mod_abo_runningtime', 'wpsg_mod_abo_starttime', 'wpsg_mod_abo_price', 'wpsg_mod_abo_duration'])) return;
@@ -1083,4 +1083,8 @@
             $abo_order = $this->isAboOrder($o_id);
             $abo_order_id = 0;
+			
+			$oOrderProduct = wpsg_order_product::getInstance($order_product_id);
+			
+			$product_key = $oOrderProduct->getProductKey();
 
             if ($abo_order === false) return;
Index: /mods/wpsg_mod_basic.class.php
===================================================================
--- /mods/wpsg_mod_basic.class.php	(revision 8106)
+++ /mods/wpsg_mod_basic.class.php	(revision 8107)
@@ -710,5 +710,5 @@
 		 * Gibt einen Wert fÃŒr eine Exportspalte zurÃŒck. Das Modul schreibt das Ergebnis in $return zurÃŒck
 		 */
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator) { }
+		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) { }
 		
 		/**
Index: /mods/wpsg_mod_creditcard.class.php
===================================================================
--- /mods/wpsg_mod_creditcard.class.php	(revision 8106)
+++ /mods/wpsg_mod_creditcard.class.php	(revision 8107)
@@ -265,5 +265,5 @@
 		} // public function wpsg_mod_export_loadFields(&$arFields)
 		
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator) {
+		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) {
 			
 			$arOrder = $this->shop->cache->loadOrder($o_id);
Index: /mods/wpsg_mod_deliverytime.class.php
===================================================================
--- /mods/wpsg_mod_deliverytime.class.php	(revision 8106)
+++ /mods/wpsg_mod_deliverytime.class.php	(revision 8107)
@@ -314,9 +314,7 @@
 		} // public function wpsg_mod_export_loadFields(&$arFields)
 
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator)
-		{
-
-			if ($field_value == 'product_deliverytime')
-			{
+		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) {
+
+			if ($field_value == 'product_deliverytime') {
 
 				$return = $this->getProductDeliveryTime($p_id);
Index: /mods/wpsg_mod_downloadplus.class.php
===================================================================
--- /mods/wpsg_mod_downloadplus.class.php	(revision 8106)
+++ /mods/wpsg_mod_downloadplus.class.php	(revision 8107)
@@ -51,4 +51,7 @@
 				mode INT(1) NOT NULL COMMENT 'Individualisierungsmodus im Produkt eingestellt',
 				template INT(11) NOT NULL COMMENT 'Link zu WPSG_TBL_DP_TEMPLATES, im Produkt eingestellt',
+				INDEX o_id (o_id),
+				INDEX p_key (p_key),
+				INDEX product_index (product_index),
 			    PRIMARY KEY  (id)
 			) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
@@ -82,4 +85,5 @@
 				text VARCHAR(1000) NOT NULL COMMENT 'Freitext',
 				font VARCHAR(255) NOT NULL COMMENT 'Schriftart',
+				INDEX template_id (template_id),
 				INDEX deleted (deleted),
 			    PRIMARY KEY  (id)
@@ -89,5 +93,6 @@
 
 	        $sql = "CREATE TABLE ".WPSG_TBL_VARIANTS_VARI." (
-				template_id int(11) NOT NULL COMMENT 'Template fÃŒr Downloadplus',				
+				template_id int(11) NOT NULL COMMENT 'Template fÃŒr Downloadplus',
+				INDEX template_id (template_id),				
 				KEY variant_id (variant_id),
 			) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;";
@@ -1433,12 +1438,14 @@
 	    } // public function wpsg_mod_export_loadFields(&$arFields)
 
-	    public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator)
-	    {
-
+	    public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) {
+
+			$oOrderProduct = wpsg_order_product::getInstance($order_product_id);
+			
+			$product_index = $oOrderProduct->getProductIndex();
+			
 	        // Individualisierung heraussuchen
 	        $db_indiv = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_PDFINDIV."` WHERE `o_id` = '".wpsg_q($o_id)."' AND `p_key` = '".wpsg_q($p_id)."' AND `product_index` = '".wpsg_q($product_index)."' ORDER BY `id` DESC LIMIT 1 ");
 
-	        switch ($field_value)
-	        {
+	        switch ($field_value) {
 
 	            case 'dnr':
@@ -1448,6 +1455,5 @@
 	            default:
 
-	                if (preg_match('/^text\d+$/', $field_value))
-	                {
+	                if (preg_match('/^text\d+$/', $field_value)) {
 
 	                    $return = '';
Index: /mods/wpsg_mod_export.class.php
===================================================================
--- /mods/wpsg_mod_export.class.php	(revision 8106)
+++ /mods/wpsg_mod_export.class.php	(revision 8107)
@@ -742,6 +742,5 @@
          * @param array $arOrderFilter
          */
-        private function handleExportProductCSV($profil_id, $arProductFilter = array())
-        {
+        private function handleExportProductCSV($profil_id, $arProductFilter = array()) {
 
             $this->loadFields();
@@ -756,11 +755,9 @@
             $arExportData = array();
 
-            if ($profil['csv_fieldnames'] == '1')
-            {
+            if ($profil['csv_fieldnames'] == '1') {
 
                 $row = array();
 
-                foreach ($profil['fields'] as $f)
-                {
+                foreach ($profil['fields'] as $f) {
 
                     $row[] = $f['name'];
@@ -772,11 +769,9 @@
             }
 
-            foreach ($arData as $oProduct)
-            {
+            foreach ($arData as $oProduct) {
 
                 $row = array();
 
-                foreach ($profil['fields'] as $f)
-                {
+                foreach ($profil['fields'] as $f) {
 
                     $row[] = $this->getValue($f, $profil['field_delimiter'], false, $oProduct->id);
@@ -826,13 +821,13 @@
             $profil = $this->loadProfil($profil_id);
 
+			$start = microtime(true);
+			
             $arExportData = array();
 
-            if ($profil['csv_fieldnames'] == '1')
-            {
+            if ($profil['csv_fieldnames'] == '1') {
 
                 $row = array();
 
-                foreach ($profil['fields'] as $f)
-                {
+                foreach ($profil['fields'] as $f) {
 
                     $row[] = $f['name'];
@@ -843,14 +838,12 @@
 
             }
-
+ 
             foreach ($arData as $order_id) {
 
                 $row = array();
 
-                if ($profil['order_online'] == '1')
-                {
-
-                    foreach ($profil['fields'] as $f)
-                    {
+                if ($profil['order_online'] == '1') {
+
+                    foreach ($profil['fields'] as $f) {
 
                         $row[] = $this->getValue($f, $profil['field_delimiter'], $order_id);
@@ -860,7 +853,5 @@
                     $arExportData[] = $row;
 
-                }
-                else
-                {
+                } else {
 
                     $arProdukte = $this->db->fetchAssoc("
@@ -876,13 +867,11 @@
                     ");
 
-                    foreach ($arProdukte as $p)
-                    {
+                    foreach ($arProdukte as $p) {
 
                         $row = array();
 
-                        foreach ($profil['fields'] as $f)
-                        {
-
-                            $row[] = $this->getValue($f, $profil['field_delimiter'], $order_id, $p['p_id'], $p['product_index'], $p['productkey'], $p['order_product_id']);
+                        foreach ($profil['fields'] as $f) {
+
+                            $row[] = $this->getValue($f, $profil['field_delimiter'], $order_id, $p['p_id'], null, $p['order_product_id']);
 
                         }
@@ -893,8 +882,8 @@
 
                 }
-
+				
                 if (\memory_get_usage() > 200000) {
 
-                    $this->arCache = [];
+                   // $this->arCache = [];
 
                 }
@@ -902,4 +891,5 @@
                 $this->shop->callMods('wpsg_mod_export_handleRowOrder', [$order_id, $profil, &$arExportData]);
 
+				/*
                 wpsg_product::clearCache();
                 wpsg_order::clearCache($order_id);
@@ -910,11 +900,16 @@
                 $this->shop->cache->clearProductCache(false);
                 $this->shop->cache->clearKundenCache(false);
-
+				
                 gc_collect_cycles ();
+				*/
 
             } // foreach arData
 
-            foreach ($arExportData as $row)
-            {
+	        $time_elapsed_secs = microtime(true) - $start;				
+			//die("= ".$time_elapsed_secs.'s');
+	         
+	        //die('<pre>'.print_r($arExportData, true).'</pre>');
+	        
+            foreach ($arExportData as $row) {
 
                 fputcsv($filehandler, $row, $profil['field_delimiter'], $profil['field_enclosure'], $profil['field_escape']);
@@ -925,6 +920,5 @@
 
             // In ISO wandeln
-            if ($profil['file_encoding'] == self::ENCODING_ISO88591)
-            {
+            if ($profil['file_encoding'] == self::ENCODING_ISO88591) {
 
                 file_put_contents($tmpfname, utf8_decode(file_get_contents($tmpfname)));
@@ -992,5 +986,5 @@
                 {
 
-                    $row[] = $this->getValue($f, $profil['field_delimiter'], false, false, 1, false, false, $oCustomer->id);
+                    $row[] = $this->getValue($f, $profil['field_delimiter'], null, null, $oCustomer->id);
 
                 }
@@ -1190,5 +1184,5 @@
                             if ($tag_product === false) $tag_product = $doc->createElement($this->clearXML($profil['xml_producttag']));
 
-                            $value = $this->getValue($f, $profil['field_delimiter'], $oOrder->id, $oOrderProduct->getProductId(), $oOrderProduct->getProductIndex(), $oOrderProduct->getProductKey());
+                            $value = $this->getValue($f, $profil['field_delimiter'], $oOrder->id, $oOrderProduct->getProductId(), null, $oOrderProduct->getId());
 
                             if (wpsg_isSizedInt($f['xml_att']))
@@ -1274,5 +1268,5 @@
                 {
 
-                    $value = $this->getValue($f, $profil['field_delimiter'], false, false, 1, false, false, $oCustomer->id);
+                    $value = $this->getValue($f, $profil['field_delimiter'], null, null,  $oCustomer->id);
 
                     if (wpsg_isSizedInt($f['xml_att']))
@@ -1565,6 +1559,5 @@
 
             // Rechnungen
-            if ($this->shop->hasMod('wpsg_mod_rechnungen'))
-            {
+            if ($this->shop->hasMod('wpsg_mod_rechnungen')) {
 
                 $this->fields[11] = array(
@@ -1704,40 +1697,29 @@
         }
 
-        public function getValue($f, $profil_separator, $o_id, $p_id = false, $product_index = 1, $productkey = false, $order_product_id = false, $customer_id = false) {
+        public function getValue($f, $profil_separator, $o_id, $p_id = null, $customer_id = null, $order_product_id = null) {
 
             $field_value = $f['value_key'];
 
-            $cache_key = $o_id.'_'.$p_id.'_'.$product_index.'_'.$productkey.'_'.$order_product_id.'_'.$customer_id;
-
-            // Hier werden die Ergebnisse gespeichert
-            if (array_key_exists($cache_key, $this->arCache)) {
-
-                $order = $this->arCache[$cache_key]['order'];
-                $produkt = $this->arCache[$cache_key]['produkt'];
-                $kunde = $this->arCache[$cache_key]['kunde'];
-
-            } else {
-
-                $order = $this->db->fetchRow("
-					SELECT 
-						O.*
-					FROM
-						`".WPSG_TBL_ORDER."` AS O
-					WHERE
-						O.`id` = '".wpsg_q($o_id)."'
-				");
-
-                // Anzahl an tatsÃ€chlich bestellten Artikeln
-                $order['menge'] = $this->db->fetchOne("SELECT SUM(OP.`menge`) FROM `".WPSG_TBL_ORDERPRODUCT."` AS OP WHERE OP.`o_id` = '".wpsg_q($order['id'])."'");
-
-                $order['oOrder'] = wpsg_order::getInstance($order['id']);
-
-                // Anzahl an Produkten in der Bestellung (MengenunabhÃ€ngig)
-                $order['count'] = $this->db->fetchOne("SELECT COUNT(*) FROM `".WPSG_TBL_ORDERPRODUCT."` WHERE `o_id` = '".wpsg_q($order['id'])."'");
-
-                $order['payment_method'] = $order['oOrder']->getPaymentLabel();
-                $order['shipping_method'] = $order['oOrder']->getShippingLabel();
-
-                $order['custom_data'] = unserialize($order['custom_data']);
+			if (isset($this->arCache['oOrder'][$o_id])) {
+				
+				$order = $this->arCache['order'][$o_id];
+
+				/** @var wpsg_order $oOrder */
+				$oOrder = $this->arCache['oOrder'][$o_id];
+
+				/** @var array $arCalculation */
+				$arCalculation = $this->arCache['arCalculation'][$o_id];
+
+				$customer_id = $oOrder->getCustomer()->getId();
+				
+			} else {
+				
+				/** @var wpsg_order $oOrder */
+	            $oOrder = wpsg_order::getInstance($o_id);
+				
+				$order = [
+					'id' => $oOrder->getId(),
+					'custom_data' => unserialize($oOrder->__get('custom_data'))
+				];
 
                 if ($this->shop->hasMod('wpsg_mod_rechnungen')) {
@@ -1780,142 +1762,79 @@
 
                 }
-
-                if ($customer_id !== false) $order['k_id'] = $customer_id;
-
-                $kunde = $this->db->fetchRow("
-					SELECT
-						K.*							
-					FROM
-						`".WPSG_TBL_KU."` AS K
-					WHERE
-						K.`id` = '".wpsg_q($order['k_id'])."'
-				");
-
-                /* Kundenvariablen */
-                $kunde['kv'] = @unserialize($kunde['custom']);
-
-                if ($p_id == false) {
-
-                    $arProdukte = $this->db->fetchAssoc("
-						SELECT
-							P.*,
-							OP.`mod_vp_varkey`,
-							OP.`menge`,
-							(OP.`price_brutto` - OP.`price_netto`) AS mwst_value,
-							OP.`price` AS price 
-						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($o_id)."'
-					");
-
-                    $produkt = array();
-
-                    foreach ($arProdukte as $p) {
-
-                        foreach ($p as $col_name => $col_value) {
-
-                            $produkt[$col_name][] = $col_value;
-
-                        }
-
-                    }
-
-                    foreach ($produkt as $col_name => $values) {
-
-                        if ($profil_separator == ',') $produkt[$col_name] = implode(";", $values);
-                        else $produkt[$col_name] = implode(",", $values);
-
-                    }
-
-                } else {
-
-                    if (wpsg_isSizedInt($order_product_id)) {
-
-                        $produkt = $this->db->fetchRow("
-							SELECT
-								P.*,
-								OP.`mod_vp_varkey`,
-								OP.`menge`,
-								(OP.`price_brutto` - OP.`price_netto`) AS mwst_value,
-								OP.`price` AS price
-							FROM
-								`".WPSG_TBL_ORDERPRODUCT."` AS OP
-									LEFT JOIN `".WPSG_TBL_PRODUCTS."` AS P ON (P.`id` = OP.`p_id`)
-							WHERE
-								OP.`id` = '".wpsg_q($order_product_id)."'
-						");
-
-                    } else {
-
-                        $produkt = $this->db->fetchRow("
-							SELECT
-								P.*,							
-								OP.`mod_vp_varkey`,
-								OP.`menge`,
-								(OP.`price_brutto` - OP.`price_netto`) AS mwst_value,
-								OP.`price` AS price
-							FROM
-								`".WPSG_TBL_PRODUCTS."` AS P
-									LEFT JOIN `".WPSG_TBL_ORDERPRODUCT."` AS OP ON (P.`id` = OP.`p_id` AND OP.`o_id` = '".wpsg_q($order['id'])."')
-							WHERE
-								P.`id` = '".wpsg_q($p_id)."'
-						");
-
-                    }
-
-                    /* Produktattribute */
-                    if ($this->shop->hasMod('wpsg_mod_produktattribute')) {
-
-                        $produkt['mod_attribute'] = $this->db->fetchAssocField("
-							SELECT
-								`a_id`, `value`
-							FROM
-								`".WPSG_TBL_PRODUCTS_AT."` AS PA
-							WHERE
-								PA.`p_id` = '".wpsg_q($produkt['id'])."'								
-						", "a_id", "value");
-
-                    }
-
-                }
-
-                $this->arCache[$cache_key] = array(
-                    "order" => $order,
-                    "produkt" => $produkt,
-                    "kunde" => $kunde
-                );
-
-            }
-
-            if (wpsg_isSizedInt($order['land'])) {
-
-                $oFrontendCountry = wpsg_country::getInstance($order['land']);
-
-            } else {
-
-                $oFrontendCountry = $this->shop->getDefaultCountry();
-
-            }
-
-            // Objekte laden 
-
-            /** @var wpsg_order $oOrder */
-            $oOrder = wpsg_order::getInstance($order['id']);
-
-            $oCalculation = new \wpsg\wpsg_calculation();
-            $oCalculation->fromDB($oOrder->getId());
-
-            $arCalculation = $oCalculation->getCalculationArray();
-
-            if ($customer_id !== false) $oCustomer = wpsg_customer::getInstance($customer_id);
-            else $oCustomer = $oOrder->getCustomer();
-
-            if ($p_id !== false) {
-
-                $oProduct = wpsg_product::getInstance($p_id);
-
-            }
+								
+				$oCalculation = new \wpsg\wpsg_calculation();
+	            $oCalculation->fromDB($oOrder->getId());
+			
+				/** @var array $arCalculation */
+				$arCalculation = $oCalculation->getCalculationArray();
+			
+				$customer_id = $oOrder->getCustomer()->getId();
+				
+				$this->arCache['oOrder'][$o_id] = $oOrder;
+				$this->arCache['arCalculation'][$o_id] = $arCalculation;
+				$this->arCache['order'][$o_id] = $order;
+							
+			}
+						
+			if ($p_id !== null) {
+				
+				if (isset($this->arCache['product'][$p_id])) {
+					
+					/** @var wpsg_product $oProduct */
+					$oProduct = $this->arCache['oProduct'][$p_id];
+					
+				} else {
+			 
+					/** @var wpsg_product $oProduct */
+					$oProduct = wpsg_product::getInstance($p_id);
+					
+				}
+				
+			}
+			
+			if ($customer_id !== null) {
+				
+				if (isset($this->arCache['customer'][$customer_id])) {
+					
+					/** @var wpsg_customer $oCustomer */
+					$oCustomer = $this->arCache['customer'][$customer_id];
+					
+					$kunde = $this->arCache['kunde'][$customer_id];
+					
+				} else {
+					
+					/** @var wpsg_customer $oCustomer */
+					$oCustomer = wpsg_customer::getInstance($customer_id);
+					
+					$kunde = [
+						'kv' => @unserialize($oCustomer->__get('custom'))
+					];
+
+					$this->arCache['oCustomer'][$customer_id] = $oCustomer;
+					$this->arCache['kunde'][$customer_id] = $kunde;
+					
+				}
+				
+			}
+			 
+			if ($order_product_id !== null) {
+				
+				if (isset($this->arCache['order_product_id'][$order_product_id])) {
+					
+					/** @var wpsg_order_product $oOrderProduct */
+					$oOrderProduct = $this->arCache['order_product_id'][$order_product_id];
+					 					
+				} else {
+					
+					/** @var wpsg_order_product $oCustomer */
+					$oOrderProduct = wpsg_order_product::getInstance($order_product_id);
+					 
+					$this->arCache['order_product_id'][$order_product_id] = $oOrderProduct;
+					
+				}
+				
+			}
+			
+            $oFrontendCountry = $oOrder->getInvoiceCountry();
 
             $getTaxSum = function($tax_code) use (&$arCalculation) {
@@ -1957,22 +1876,24 @@
 	            case 'order_tax_d': $return = $getTaxSum('d')['sum']; break;
 
-                case 'order_id': $return = $order['id']; break;
+                case 'order_id': $return = $oOrder->getId(); break;
                 case 'order_cdate':
 
-                    if (strtotime($order['cdate']) !== false)
-                    {
-                        $return = date('d.m.Y H:i:s', strtotime($order['cdate']));
-                    }
-                    else
-                    {
+                    if (strtotime($oOrder->__get('cdate')) !== false) {
+						
+                        $return = date('d.m.Y H:i:s', strtotime($oOrder->__get('cdate')));
+						
+                    } else {
+						
                         $return = '--';
+						
                     }
 
                     break;
-                case 'order_onr': $return = $order['onr']; break;
-                case 'order_bemerkung': $return = preg_replace('/\r\n|\r|\n/', ' ', $order['comment']); break;
+					
+                case 'order_onr': $return = $oOrder->getNr(); break;
+                case 'order_bemerkung': $return = preg_replace('/\r\n|\r|\n/', ' ', $oOrder->__get('comment')); break;
                 case 'order_price':
 
-                    $return = $order['price_gesamt_brutto'];
+                    $return = $oOrder->getAmount(WPSG_BRUTTO);
 
                     break;
@@ -1980,12 +1901,12 @@
                 case 'order_price_netto':
 
-                    $return = $order['price_gesamt_netto'];
+                    $return = $oOrder->getAmount(WPSG_NETTO);
 
                     break;
 
-                case 'order_shipping': $return = number_format($order['price_shipping'], 2, ',', '.'); break;
-                case 'order_payment': $return = number_format($order['price_payment'], 2, ',', '.'); break;
-                case 'order_useragent':	$return = $order['useragent']; break;
-                case 'order_ip': $return = $order['ip']; break;
+                case 'order_shipping': $return = number_format($oOrder->__get('price_shipping'), 2, ',', '.'); break;
+                case 'order_payment': $return = number_format($oOrder->__get('price_payment'), 2, ',', '.'); break;
+                case 'order_useragent':	$return = $oOrder->__get('useragent'); break;
+                case 'order_ip': $return = $oOrder->__get('ip'); break;
 
                 case 'order_invoice_title': $return = $oOrder->getInvoiceTitle(); break;
@@ -2015,23 +1936,21 @@
                 case 'order_land_krzl': $return = $oOrder->getShippingCountryKuerzel(); break;
 
-                case 'order_payment_method': $return = $order['payment_method']; break;
-                case 'order_shipping_method': $return = $order['shipping_method']; break;
-                case 'order_count': $return = $order['count']; break;
-                case 'order_firma': $return = $order['shipping_firma']; break;
-                case 'order_status': $return = $this->shop->arStatus[$order['status']]; break;
-                case 'order_bname': $return = $order['mod_autodebit_name']; break;
-                case 'order_bblz': $return = $order['mod_autodebit_blz']; break;
-                case 'order_binhaber': $return = $order['mod_autodebit_inhaber']; break;
-                case 'order_menge': $return = $order['menge']; break;
-                case 'order_bnr': $return = $order['mod_autodebit_knr']; break;
-                case 'order_iban': $return = $order['mod_autodebit_iban']; break;
-                case 'order_bic': $return = $order['mod_autodebit_bic']; break;
-                case 'order_weight': $return = $order['weight']; break;
+                case 'order_payment_method': $return = $oOrder->getPaymentLabel(); break;
+                case 'order_shipping_method': $return = $oOrder->getShippingLabel(); break;
+                case 'order_count': $return = $oOrder->getProductCount(); break;
+                case 'order_firma': $return = $oOrder->getInvoiceCompany(); break;
+                case 'order_status': $return = $oOrder->getStateLabel(); break;
+                case 'order_bnr': $return = $oOrder->__get('mod_autodebit_knr'); break;
+                case 'order_iban': $return = $oOrder->__get('mod_autodebit_iban'); break;
+                case 'order_bic': $return = $oOrder->__get('mod_autodebit_bic'); break;
+                case 'order_weight': $return = $oOrder->__get('weeight'); break;
                 case 'order_gutschein':
 
-                    if (wpsg_isSizedInt($order['gs_id'])) {
+					$gs_id = $oOrder->__get('gs_id');
+					
+                    if (wpsg_isSizedInt($gs_id)) {
 
                         // AbwÃ€rtskompatibilitÃ€t fÃŒr alte Bestellungen						
-                        $return = $this->db->fetchOne("SELECT `code` FROM `".WPSG_TBL_GUTSCHEIN."` WHERE `id` = '".wpsg_q($order['gs_id'])."'");
+                        $return = $this->db->fetchOne("SELECT `code` FROM `".WPSG_TBL_GUTSCHEIN."` WHERE `id` = '".wpsg_q($oOrder->__get('gs_id'))."'");
 
                     } else {
@@ -2043,5 +1962,5 @@
 								`".WPSG_TBL_ORDER_VOUCHER."`
 							WHERE
-								`order_id` = '".wpsg_q($order['id'])."'
+								`order_id` = '".wpsg_q($oOrder->getId())."'
 							GROUP BY
 								`order_id`
@@ -2054,130 +1973,92 @@
                 case 'rechnung_nr': $return = $order['rnr']; break;
                 case 'rechnungskorrektur_nr':
-                case 'gutschrift_nr':
-                    $return = $order['gnr']; break;
+                case 'gutschrift_nr': $return = $order['gnr']; break;
                 case 'rdatum':
 
-                    if (strtotime($order['rdatum']) !== false)
-                    {
+                    if (strtotime($order['rdatum']) !== false) {
+						
                         $return = date('d.m.Y H:i:s', strtotime($order['rdatum']));
-                    }
+						
+                    } else {
+						
+                        $return = '--';
+						
+                    }
+
+                    break;
+
+                case 'produkt_id': $return = $oProduct->getId(); break;
+                case 'produkt_index': $return = $oOrderProduct->getProductIndex(); break;
+                case 'produkt_name': $return = $oProduct->getProductName(); break;
+                case 'product_url': $return = $oProduct->getProductURL(); break;
+                case 'product_picture_url':
+
+                    $nAttachmentID = $this->shop->imagehandler->getAttachmentID($oOrderProduct->getProductKey());
+                    $return = '';
+
+                    if (wpsg_isSizedInt($nAttachmentID)) $return = \wp_get_attachment_url($nAttachmentID);
+
+                    break;
+               
+                case 'produkt_typ': $return = $oProduct->__get('typ'); break;
+                case 'produkt_preis': // Brutto Preis im Produkt
+
+                    if ($this->shop->getBackendTaxview() == WPSG_BRUTTO)
+                        $return = number_format($oProduct->__get('preis'), 2, ',', '.');
                     else
-                    {
-                        $return = '--';
-                    }
+                        $return = number_format($oProduct->__get('preis') + $oProduct->__get('mwst_value'), 2, ',', '.');
 
                     break;
 
-                case 'produkt_id': $return = $produkt['id']; break;
-                case 'produkt_index': $return = $product_index; break;
-                case 'produkt_name': $return = $produkt['name']; break;
-                case 'product_url': $return = $this->shop->getProduktLink($produkt); break;
-                case 'product_picture_url':
-
-                    $nAttachmentID = $this->shop->imagehandler->getAttachmentID($produkt['id']);
-                    $return = '';
-
-                    if (wpsg_isSizedInt($nAttachmentID)) $return = \wp_get_attachment_url($nAttachmentID);
+                case 'produkt_preis_brutto':
+
+                    $return = $oProduct->getPrice(false, WPSG_BRUTTO);
 
                     break;
-                /*case 'product_shippingprice':
-                     
-                    $arCountry = wpsg_country::find([]);
-                    
-                    foreach ($arCountry as $oCountry) {
-                        
-                        $cost = 0;
+
+                case 'produkt_preis_netto': // Netto Preis im Produkt
+
+                    $return = $oProduct->getPrice(false, WPSG_NETTO);
+
+                    break;
+
+                case 'product_preis_order': // Brutto Preis aus bestelltem Produkt
+
+                    $return = number_format($oOrderProduct->getPriceSum(WPSG_BRUTTO), 2, ',', '.');
+                    break;
+
+                case 'product_preis_order_netto':
+
+                    $return = number_format($oOrderProduct->getPriceSum(WPSG_NETTO), 2, ',', '.');
+                    break;
+
+                case 'produkt_mwst': $return = $oOrderProduct->getTaxKey(); break;
+                case 'produkt_mwst_satz': $return = wpsg_ff($oFrontendCountry->getTax($oProduct->__get('mwst_key'))); break;
+                case 'produkt_mwst_value': $return = wpsg_ff($oProduct->getPrice(false, WPSG_BRUTTO) - $oProduct->getPrice(false, WPSG_NETTO)); break;
  
-                        $this->shop->basket = new wpsg_basket();
-                        $this->shop->basket->arProdukte = [
-                            [
-                                'id' => $oProduct->id,
-                                'menge' => 1
-                            ]
-                        ];
-                        $this->shop->baskert->arCheckout['land'] = $oCountry->id;
-
-                        $arShipping = [];
-                        
-                        $this->shop->callMods('addShipping', [&$arShipping, true]);
-                        
-                        foreach ($arShipping as $shipping_key => $shipping) {
-                            
-                            $arBasket = $this->shop->basket->toArray();
-                            
-                            $this->shop->callMods('calcShipping', [&$arBasket, $shipping_key]);
- 
-                            wpsg_debug($oCountry->getShorttext()." : ".$shipping_key.":".$arBasket['sum']['preis_shipping_brutto']);
-
-                        }
-                        
-                    }
-                    
-                    
-                    die("K");
-                    
-                    break;*/
-                case 'produkt_typ': $return = $produkt['typ']; break;
-                case 'produkt_preis': // Brutto Preis im Produkt
-
-                    if ($this->shop->getBackendTaxview() == WPSG_BRUTTO)
-                        $return = number_format($produkt['preis'], 2, ',', '.');
-                    else
-                        $return = number_format($produkt['preis'] + $produkt['mwst_value'], 2, ',', '.');
+                case 'produkt_order_mwst_value': $return = wpsg_ff($oOrderProduct->getTaxAmount()); break;
+
+                case 'produkt_feinheit': $return = $oProduct->__get('feinheit'); break;
+                case 'produkt_fmenge': $return = $oProduct->__get('fmenge'); break;
+                case 'produkt_beschreibung': $return = $oProduct->__get('beschreibung'); break;
+                case 'produkt_longdescription': $return = $oProduct->__get('longdescription'); break;
+                case 'produkt_moreinfos': $return = $oProduct->__get('moreinfos'); break;
+                case 'produkt_moreinfos2': $return = $oProduct->__get('moreinfos2'); break;
+                case 'produkt_weight': $return = $oProduct->__get('weight'); break;
+                case 'produkt_stock': $return = $oProduct->__get('stock'); break;
+                case 'product_stock_state':
+
+					$product_stock = $oProduct->__get('stock');
+					
+                    $return = ((wpsg_isSizedInt($product_stock))?__('auf Lager', 'wpsg'):__('nicht auf Lager', 'wpsg'));
 
                     break;
-
-                case 'produkt_preis_brutto':
-
-                    $return = $oProduct->getPrice(false, WPSG_BRUTTO);
-
-                    break;
-
-                case 'produkt_preis_netto': // Netto Preis im Produkt
-
-                    $return = $oProduct->getPrice(false, WPSG_NETTO);
-
-                    break;
-
-                case 'product_preis_order': // Brutto Preis aus bestelltem Produkt
-
-                    $return = number_format($produkt['price'], 2, ',', '.');
-                    break;
-
-                case 'product_preis_order_netto':
-
-                    $return = number_format($produkt['price'] - $produkt['mwst_value'], 2, ',', '.');
-                    break;
-
-                case 'produkt_mwst': $return = $produkt['mwst_key']; break;
-                case 'produkt_mwst_satz': $return = wpsg_ff($oFrontendCountry->getTax($produkt['mwst_key'])); break;
-                case 'produkt_mwst_value': $return = wpsg_ff($oProduct->getPrice(false, WPSG_BRUTTO) - $oProduct->getPrice(false, WPSG_NETTO)); break;
-
-                // case 'produkt_picture_link': $return = $produktbild['url']; break; 
-
-                // case 'produkt_shippingprice': $return = $produkt['shippingprice']; break;
-
-                case 'produkt_order_mwst_value': $return = wpsg_ff($produkt['mwst_value'] * $produkt['menge']); break;
-
-                case 'produkt_feinheit': $return = $produkt['feinheit']; break;
-                case 'produkt_fmenge': $return = $produkt['fmenge']; break;
-                case 'produkt_beschreibung': $return = $produkt['beschreibung']; break;
-                case 'produkt_longdescription': $return = $produkt['longdescription']; break;
-                case 'produkt_moreinfos': $return = $produkt['moreinfos']; break;
-                case 'produkt_moreinfos2': $return = $produkt['moreinfos2']; break;
-                case 'produkt_weight': $return = $produkt['weight']; break;
-                case 'produkt_stock': $return = $produkt['stock']; break;
-                case 'product_stock_state':
-
-                    $return = ((wpsg_isSizedInt($produkt['stock']))?__('auf Lager', 'wpsg'):__('nicht auf Lager', 'wpsg'));
-
-                    break;
-                case 'produkt_anr': $return = $produkt['anr']; break;
-                case 'produkt_menge': $return = $produkt['menge']; break;
-                case 'produkt_ean': $return = $produkt['ean']; break;
-                case 'produkt_gtin': $return = $produkt['gtin']; break;
-
-                case 'kunde_id': $return = @$kunde['id']; break;
-                case 'kunde_nr': $return = $kunde['knr']; break;
+                case 'produkt_anr': $return = $oProduct->__get('anr'); break;
+                case 'produkt_menge': $return = $oProduct->__get('menge'); break;
+                case 'produkt_ean': $return = $oProduct->__get('ean'); break;
+                case 'produkt_gtin': $return = $oProduct->__get('gtin'); break;
+
+                case 'kunde_id': $return = $oCustomer->getId(); break;
+                case 'kunde_nr': $return = $oCustomer->getNr(); break;
 
                 case 'kunde_title': $return = $oCustomer->getTitle(); break;
@@ -2195,15 +2076,16 @@
                 case 'kunde_fax': $return = $oCustomer->getFax(); break;
 
-                case 'kunde_email': $return = @$kunde['email']; break;
-                case 'kunde_ustid': $return = @$kunde['ustidnr']; break;
+                case 'kunde_email': $return = $oCustomer->getEMail(); break;
+                case 'kunde_ustid': $return = $oCustomer->__get('ustidnr'); break;
                 case 'kunde_geb':
 
-                    if (strtotime($kunde['geb']) !== false)
-                    {
-                        $return = date('d.m.Y H:i:s', strtotime($kunde['geb']));
-                    }
-                    else
-                    {
+                    if (strtotime($oCustomer->__get('geb')) !== false) {
+						
+                        $return = date('d.m.Y H:i:s', strtotime($oCustomer->__get('geb')));
+						
+                    } else {
+						
                         $return = '--';
+						
                     }
 
@@ -2212,6 +2094,5 @@
                 default:
 
-                    if (preg_match('/ov_\d+/', $field_value))
-                    {
+                    if (preg_match('/ov_\d+/', $field_value)) {
 
                         // Bestellvariable
@@ -2219,45 +2100,26 @@
                         $return = $order['bvars'][$ordervarid];
 
-                    }
-                    else if (preg_match('/pv_\d+/', $field_value))
-                    {
+                    } else if (preg_match('/pv_\d+/', $field_value)) {
 
                         $produktvarid = substr($field_value, 3);
 
                         // Produktvariable (index kann auch 0 sein)
-                        if (isset($order['pvars'][$product_index]))
-                        {
-
-                            $return = $order['pvars'][$product_index][$produktvarid];
+                        if (isset($order['pvars'][$oOrderProduct->getProductIndex()])) {
+
+                            $return = $order['pvars'][$oOrderProduct->getProductIndex()][$produktvarid];
+
+                        } else {
+
+                            $return = $order['pvars'][$oOrderProduct->getProductKey()][$produktvarid];
 
                         }
-                        else
-                        {
-
-                            // AbwÃ€rtskompatibilitÃ€t < 3.5.1 
-                            if ($produkt['mod_vp_varkey'] != '')
-                            {
-                                $produkt_key = $produkt['mod_vp_varkey'];
-                            }
-                            else
-                            {
-                                $produkt_key = $produkt['id'];
-                            }
-
-                            $return = $order['pvars'][$produkt_key][$produktvarid];
-
-                        }
-
-                    }
-                    else if (preg_match('/pa_\d+/', $field_value))
-                    {
+
+                    } else if (preg_match('/pa_\d+/', $field_value)) {
 
                         // Produktattribute
                         $paid = substr($field_value, 3);
-                        $return = $produkt['mod_attribute'][$paid];
-
-                    }
-                    else if (preg_match('/kv_\d+/', $field_value))
-                    {
+                        $return = $this->callMod('wpsg_mod_produktattribute', 'getAttributeValue', [$oProduct->getId(), $paid]);
+
+                    } else if (preg_match('/kv_\d+/', $field_value)) {
 
                         // Kundenvariable
@@ -2265,13 +2127,11 @@
                         $return = $kunde['kv'][$kvid];
 
-                    }
-                    else
-                    {
+                    } else {
 
                         $return = false;
-                        $this->shop->callMods('wpsg_mod_export_getValue', array(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator));
-
-                        if ($return === false)
-                        {
+						
+                        $this->shop->callMods('wpsg_mod_export_getValue', array(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator));
+
+                        if ($return === false) {
 
                             $return = __('Nicht definiert ('.$field_value.') !', 'wpsg');
@@ -2287,9 +2147,7 @@
             if (wpsg_isSizedInt($f['trim'])) $return = preg_replace('/\040/', '', $return);
 
-            if (isset($f['format']) && $f['format'] > 0 && $return != '--')
-            {
-
-                switch ($f['format'])
-                {
+            if (isset($f['format']) && $f['format'] > 0 && $return != '--') {
+
+                switch ($f['format']) {
 
                     case 100: $return = number_format(floatval(wpsg_tf($return)), 2, '.', ''); break;
@@ -2311,6 +2169,5 @@
             return $return;
 
-        } // public function getValue($field_value, $o_id, $p_id = false)
-
-    } // wpsg_mod_export extends wpsg_mod_basic
-
+        }  
+
+    } 
Index: /mods/wpsg_mod_productgroups.class.php
===================================================================
--- /mods/wpsg_mod_productgroups.class.php	(revision 8106)
+++ /mods/wpsg_mod_productgroups.class.php	(revision 8107)
@@ -502,9 +502,7 @@
 		} // public function wpsg_mod_export_loadFields(&$arFields)
 
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator)
-		{
-
-			if (wpsg_isSizedInt($o_id) && !wpsg_isSizedInt($p_id))
-			{
+		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) {
+
+			if (wpsg_isSizedInt($o_id) && !wpsg_isSizedInt($p_id)) {
 
 				$product_db = $this->db->fetchRow("
@@ -522,19 +520,16 @@
 				");
 
-			}
-			else if (wpsg_isSizedInt($p_id))
-			{
+			} else if (wpsg_isSizedInt($p_id)) {
 
 				$product_db = $this->shop->cache->loadProduct($p_id);
 				$product_db['pgruppe_name'] = $this->db->fetchOne("SELECT `name` FROM `".WPSG_TBL_PRODUCTS_GROUP."` WHERE `id` = '".wpsg_q($product_db['pgruppe'])."' ");
 
-			}
-			else
-			{
+			} else {
+				
 				return;
-			}
-
-			switch ($field_value)
-			{
+				
+			}
+
+			switch ($field_value) {
 
 				case 'pgruppe_id': $return = $product_db['pgruppe']; break;
Index: /mods/wpsg_mod_productvariants.class.php
===================================================================
--- /mods/wpsg_mod_productvariants.class.php	(revision 8106)
+++ /mods/wpsg_mod_productvariants.class.php	(revision 8107)
@@ -2375,6 +2375,10 @@
         }
 
-        public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $product_key, $product_index, $profil_separator) {
-
+        public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) {
+
+			$oOrderProduct = wpsg_order_product::getInstance($order_product_id);
+			
+			$product_key = $oOrderProduct->getId();
+			
 		    if (preg_match('/^var_\d+$/', $field_value)) {
 		        
Index: /mods/wpsg_mod_stock.class.php
===================================================================
--- /mods/wpsg_mod_stock.class.php	(revision 8106)
+++ /mods/wpsg_mod_stock.class.php	(revision 8107)
@@ -718,6 +718,6 @@
         }
         
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator) {
-
+		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) {
+ 						
 		    // Abbrechen wenn uninteressante Felder
             if (!in_array($field_value, ['mod_stock_stock', 'mod_stock_minstock'])) return;
Index: /mods/wpsg_mod_surfaceproduct.class.php
===================================================================
--- /mods/wpsg_mod_surfaceproduct.class.php	(revision 8106)
+++ /mods/wpsg_mod_surfaceproduct.class.php	(revision 8107)
@@ -160,42 +160,4 @@
 			
 		}
-		
-		/*
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id ) 
-		{
-			
-			$arOrder = $this->shop->cache->loadOrder($o_id);
-			$value = "";
-			
-			if ($field_value == 'mod_surfaceproduct_mode_running')
-			{
-				$value = $arOrder['mod_surfaceproduct_mode_running'];
-			}
-			if ($field_value == 'mod_surfaceproduct_running_order')
-			{
-				$value = $arOrder['mod_surfaceproduct_running_order'];
-			}
-			if ($field_value == 'mod_surfaceproduct_mode_length')
-			{
-				$value = $arOrder['mod_surfaceproduct_mode_length'];
-			}
-			if ($field_value == 'mod_surfaceproduct_mode_both')
-			{
-				$value = $arOrder['mod_surfaceproduct_mode_both'];
-			}
-			
-			if ($value == "")
-			{
-				$return = $value;
-			}
-			else
-			{
-				
-				$key = $this->shop->get_option("wpsg_mod_surfaceproduct");
-				$return = $value; 
-				
-			}
-		}	
-		*/
-	}
-?>
+		 
+	} 
Index: /mods/wpsg_mod_voucherproduct.class.php
===================================================================
--- /mods/wpsg_mod_voucherproduct.class.php	(revision 8106)
+++ /mods/wpsg_mod_voucherproduct.class.php	(revision 8107)
@@ -635,6 +635,5 @@
 		} // public function order_view_sidebar(&$order_id)
 		
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator) 
-		{ 
+		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) { 
 			 
 			if (!in_array($field_value, array('wpsg_mod_voucher_code', 'wpsg_mod_voucher_validfrom', 'wpsg_mod_voucher_validto')) || !wpsg_isSizedInt($o_id) || !wpsg_isSizedInt($p_id));
@@ -656,6 +655,5 @@
 			$arValidTo = array();
 			
-			foreach ($arVoucher as $v)
-			{
+			foreach ($arVoucher as $v) {
 				
 				$arCode[] = $v['code'];
@@ -667,6 +665,5 @@
 			if ($profil_separator === ',') $separator = ';'; else $separator = ',';
 						
-			switch ($field_value)
-			{
+			switch ($field_value) {
 				
 				case 'wpsg_mod_voucher_code': $return = implode($separator, $arCode); break;
Index: /system/intern/mods/wpsg_mod_varianten.class.php
===================================================================
--- /system/intern/mods/wpsg_mod_varianten.class.php	(revision 8106)
+++ /system/intern/mods/wpsg_mod_varianten.class.php	(revision 8107)
@@ -890,9 +890,11 @@
 		} // public function wpsg_mod_export_loadFields(&$arFields) 
 		
-		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $productkey, $product_index, $profil_separator) 
-		{ 
-
-			if ($this->isVariantsProductKey($productkey))
-			{
+		public function wpsg_mod_export_getValue(&$return, $field_value, $o_id, $p_id, $order_product_id, $profil_separator) { 
+
+			$oOrderProduct = wpsg_order_product::getInstance($order_product_id);
+			
+			$productkey = $oOrderProduct->getProductKey();
+			
+			if ($this->isVariantsProductKey($productkey)) {
 
 				$var_info = $this->getVariantenInfoArray($productkey);
@@ -901,7 +903,5 @@
 				$var_vanr = $var_info['akey'];
 				
-			}
-			else
-			{
+			} else {
 				
 				// Damit das nicht definiert nicht im Export erscheint, fÃŒr Produkte die keine Variante sind 
@@ -912,6 +912,5 @@
 			}
 			
-			switch ($field_value)
-			{
+			switch ($field_value) {
 			
 				case 'product_vname': $return = $var_vname; break;
