/** * Updates the session with all data relevant to the current order * * - Counts the items in the Cart, sums up the amounts * - Calculates all taxes and fees * Sets fields in the global $_SESSION['shop'] array, namely * 'grand_total_price', 'vat_price', 'vat_products_txt', * 'vat_grand_txt', and 'vat_procentual'. */ static function update_session() { global $_ARRAYLANG; if (empty($_SESSION['shop']['payment_price'])) { $_SESSION['shop']['payment_price'] = 0; } if (empty($_SESSION['shop']['shipment_price'])) { $_SESSION['shop']['shipment_price'] = 0; } Vat::is_home_country(empty($_SESSION['shop']['countryId2']) || $_SESSION['shop']['countryId2'] == \Cx\Core\Setting\Controller\Setting::getValue('country_id', 'Shop')); // VAT enabled? if (Vat::isEnabled()) { // VAT included? if (Vat::isIncluded()) { // home country equals shop country; VAT is included already if (Vat::is_home_country()) { $_SESSION['shop']['vat_price'] = Currency::formatPrice(Cart::get_vat_amount() + Vat::calculateOtherTax($_SESSION['shop']['payment_price'] + $_SESSION['shop']['shipment_price'])); $_SESSION['shop']['grand_total_price'] = Currency::formatPrice(Cart::get_price() + $_SESSION['shop']['payment_price'] + $_SESSION['shop']['shipment_price']); $_SESSION['shop']['vat_products_txt'] = $_ARRAYLANG['TXT_TAX_INCLUDED']; $_SESSION['shop']['vat_grand_txt'] = $_ARRAYLANG['TXT_TAX_INCLUDED']; } else { // Foreign country; subtract VAT from grand total price. $_SESSION['shop']['vat_price'] = Cart::get_vat_amount(); $_SESSION['shop']['grand_total_price'] = Currency::formatPrice(Cart::get_price() + $_SESSION['shop']['payment_price'] + $_SESSION['shop']['shipment_price'] - $_SESSION['shop']['vat_price']); $_SESSION['shop']['vat_products_txt'] = $_ARRAYLANG['TXT_TAX_INCLUDED']; $_SESSION['shop']['vat_grand_txt'] = $_ARRAYLANG['TXT_TAX_EXCLUDED']; } } else { // VAT is excluded // When the VAT is excluded, but enabled for foreign countries, // it must be added nonetheless! // Otherwise, you would expect it to be disabled for that case. // if (Vat::is_home_country()) { // home country equals shop country; add VAT. // the VAT on the products has already been calculated and set in the cart. // now we add the default VAT to the shipping and payment cost. $_SESSION['shop']['vat_price'] = Currency::formatPrice(Cart::get_vat_amount() + Vat::calculateOtherTax($_SESSION['shop']['payment_price'] + $_SESSION['shop']['shipment_price'])); $_SESSION['shop']['grand_total_price'] = Currency::formatPrice(Cart::get_price() + $_SESSION['shop']['payment_price'] + $_SESSION['shop']['shipment_price'] + $_SESSION['shop']['vat_price']); $_SESSION['shop']['vat_products_txt'] = $_ARRAYLANG['TXT_TAX_EXCLUDED']; $_SESSION['shop']['vat_grand_txt'] = $_ARRAYLANG['TXT_TAX_INCLUDED']; // } else { // // foreign country; do not add VAT // $_SESSION['shop']['vat_price'] = '0.00'; // $_SESSION['shop']['grand_total_price'] = Currency::formatPrice( // Cart::get_price() // + $_SESSION['shop']['payment_price'] // + $_SESSION['shop']['shipment_price']); // $_SESSION['shop']['vat_products_txt'] = $_ARRAYLANG['TXT_TAX_EXCLUDED']; // $_SESSION['shop']['vat_grand_txt'] = $_ARRAYLANG['TXT_TAX_EXCLUDED']; // } } } else { // VAT is disabled $_SESSION['shop']['vat_price'] = '0.00'; $_SESSION['shop']['vat_products_txt'] = ''; $_SESSION['shop']['vat_grand_txt'] = ''; $_SESSION['shop']['grand_total_price'] = Currency::formatPrice(Cart::get_price() + $_SESSION['shop']['payment_price'] + $_SESSION['shop']['shipment_price']); } //\DBG::log("Shop::update_session(): VAT: ".$_SESSION['shop']['vat_price']); }