Index: src/GXMainComponents/Application.inc.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/GXMainComponents/Application.inc.php b/src/GXMainComponents/Application.inc.php
--- a/src/GXMainComponents/Application.inc.php	
+++ b/src/GXMainComponents/Application.inc.php	
@@ -1,6 +1,6 @@
 <?php
 /* --------------------------------------------------------------
-   Application.inc.php 2021-05-14
+   Application.inc.php 2021-06-30
    Gambio GmbH
    http://www.gambio.de
    Copyright (c) 2021 Gambio GmbH
@@ -270,7 +270,11 @@
 
         // write customers status in session
         if (isset($_SESSION['customer_id'])) {
-            $customerStatusQuery1  = $db->select('c.customers_status, a.customer_b2b_status')
+            $customerStatusQuery1 = $db->select('c.customers_status, 
+                                                        a.address_book_id, 
+                                                        a.customer_b2b_status, 
+                                                        a.entry_country_id, 
+                                                        a.entry_zone_id')
                 ->from('customers c')
                 ->join('address_book a', 'a.address_book_id = c.customers_default_address_id')
                 ->where('c.customers_id', $_SESSION['customer_id'])
@@ -311,6 +315,62 @@
                 if (!isset($_SESSION['customer_b2b_status'])) {
                     update_customer_b2b_status($customersStatusValue1['customer_b2b_status']);
                 }
+    
+                $customerCountryId = $customersStatusValue1['entry_country_id'];
+                $customerZoneId    = $customersStatusValue1['entry_zone_id'];
+    
+                $selfpickupSelected = isset($_SESSION['shipping']['id'])
+                                      && $_SESSION['shipping']['id'] === 'selfpickup_selfpickup';
+    
+                // For selfpickup the taxation must be calculated based on the country/zone the shop is located in
+                if ($selfpickupSelected) {
+                    $query             = 'SELECT
+                                               g.`value` AS entry_country_id,
+                                               z.`zone_id` AS entry_zone_id
+                                            FROM `gx_configurations` g
+                                            INNER JOIN `zones_to_geo_zones` z ON g.`value` = z.`zone_country_id`
+                                            WHERE `key` = "configuration/SHIPPING_ORIGIN_COUNTRY" LIMIT 1';
+                    $result            = xtc_db_query($query);
+                    $row               = xtc_db_fetch_array($result);
+                    $customerCountryId = $row['entry_country_id'];
+                    $customerZoneId    = $row['entry_zone_id'];
+                } else {
+                    $cartContentType = isset($_SESSION['cart'])
+                                       && method_exists($_SESSION['cart'],
+                                                        'get_content_type') ? $_SESSION['cart']->get_content_type() : null;
+        
+                    // $cartContentType is null in Gambio Admin
+                    if ($cartContentType !== null) {
+                        $addressBookId = null;
+                        $query         = 'SELECT
+                                                ab.`entry_country_id`,
+                                                ab.`entry_zone_id`
+                                            FROM ' . TABLE_ADDRESS_BOOK . ' ab
+                                            LEFT JOIN ' . TABLE_ZONES . ' z ON (ab.`entry_zone_id` = z.`zone_id`)
+                                            WHERE
+                                                ab.`customers_id` = ' . (int)$_SESSION['customer_id'] . ' AND
+                                                ab.`address_book_id` = ';
+                        if ($cartContentType === 'virtual' && !empty($_SESSION['billto'])
+                            && $customersStatusValue1['address_book_id'] !== $_SESSION['billto']) {
+                            $addressBookId = (int)$_SESSION['billto'];
+                            $query         .= $addressBookId;
+                        } elseif ($cartContentType !== 'virtual' && !empty($_SESSION['sendto'])
+                                  && $customersStatusValue1['address_book_id'] !== $_SESSION['sendto']) {
+                            $addressBookId = (int)$_SESSION['sendto'];
+                            $query         .= $addressBookId;
+                        }
+            
+                        if ($addressBookId !== null) {
+                            $result            = xtc_db_query($query);
+                            $row               = xtc_db_fetch_array($result);
+                            $customerCountryId = $row['entry_country_id'];
+                            $customerZoneId    = $row['entry_zone_id'];
+                        }
+                    }
+                }
+    
+                $_SESSION['customer_country_id'] = $customerCountryId;
+                $_SESSION['customer_zone_id']    = $customerZoneId;
             } else // (int)xtc_db_num_rows($customers_status_query_1) !== 1
             {
                 if (!StyleEditServiceFactory::service()->isEditing()) {
@@ -351,6 +411,11 @@
                 ];
 
                 update_customer_b2b_status('0');
+    
+                if (!isset ($_SESSION['customer_country_id'])) {
+                    $_SESSION['customer_country_id'] = STORE_COUNTRY;
+                    $_SESSION['customer_zone_id']    = STORE_ZONE;
+                }
             }
         } else // isset($_SESSION['customer_id']) === false
         {
@@ -385,11 +450,11 @@
             ];
 
             update_customer_b2b_status('0');
-        }
-
-        if (!isset ($_SESSION['customer_country_id'])) {
-            $_SESSION['customer_country_id'] = STORE_COUNTRY;
-            $_SESSION['customer_zone_id']    = STORE_ZONE;
+    
+            if (!isset ($_SESSION['customer_country_id'])) {
+                $_SESSION['customer_country_id'] = STORE_COUNTRY;
+                $_SESSION['customer_zone_id']    = STORE_ZONE;
+            }
         }
     }
     
Index: src/system/classes/tax/CountrySessionWriter.inc.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/system/classes/tax/CountrySessionWriter.inc.php b/src/system/classes/tax/CountrySessionWriter.inc.php
--- a/src/system/classes/tax/CountrySessionWriter.inc.php	
+++ b/src/system/classes/tax/CountrySessionWriter.inc.php	
@@ -1,9 +1,9 @@
 <?php
 /* --------------------------------------------------------------
-   CountrySessionWriter.inc.php 2014-12-15 gm
+   CountrySessionWriter.inc.php 2021-06-30 gm
    Gambio GmbH
    http://www.gambio.de
-   Copyright (c) 2014 Gambio GmbH
+   Copyright (c) 2021 Gambio GmbH
    Released under the GNU General Public License (Version 2)
    [http://www.gnu.org/licenses/gpl-2.0.html]
    --------------------------------------------------------------
@@ -36,7 +36,8 @@
 			if(isset($countriesArray[$p_countryIsoCode]))
 			{
 				$countryId = $this->countries->get_country_id_by_iso_code($p_countryIsoCode);
-				$_SESSION['customer_country_id'] = $countryId;
+				$_SESSION['customer_country_id']   = $countryId;
+				$_SESSION['cart_shipping_country'] = $countryId;
 			}
 		}
 	}
