// Load tax config if available, otherwise define fallback class if (file_exists(_PS_CONFIG_DIR_ . 'tax_eu_config.php')) { require_once(_PS_CONFIG_DIR_ . 'tax_eu_config.php'); } else { // Fallback class if config file doesn't exist class TaxEUConfig { public static function getVATRate($country_iso) { return 0.0; } public static function isEUCountry($country_iso) { return false; } } } class Cart extends CartCore { /** * Override getOrderTotal to fix tax calculation for EU customers with BaseLinker integration */ public function getOrderTotal( $withTaxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = false, bool $keepOrderPrices = false ) { // Fix context issue - ensure cart is set in context if (!Context::getContext()->cart || Context::getContext()->cart->id != $this->id) { Context::getContext()->cart = $this; } // Fix for BaseLinker VAT EU 0% export issue if ($withTaxes && $this->isEUCustomer()) { $this->ensureCorrectTaxCalculation(); } try { return parent::getOrderTotal($withTaxes, $type, $products, $id_carrier, $use_cache, $keepOrderPrices); } catch (Exception $e) { // Log error and return 0 to prevent fatal errors PrestaShopLogger::addLog( 'Cart Override: Error calculating order total for cart ID ' . $this->id . ': ' . $e->getMessage(), 3, null, 'Cart', $this->id ); return 0; } } /** * Check if customer is from EU */ private function isEUCustomer() { if (!$this->id_address_delivery) { return false; } $address = new Address($this->id_address_delivery); if (!$address->id_country) { return false; } $country = new Country($address->id_country); return TaxEUConfig::isEUCountry($country->iso_code); } /** * Ensure correct tax calculation for EU customers */ private function ensureCorrectTaxCalculation() { // Force tax calculation method for EU customers $this->setTaxCalculationMethod(); // Apply correct VAT rates for EU countries $address = new Address($this->id_address_delivery); $country = new Country($address->id_country); $vat_rate = TaxEUConfig::getVATRate($country->iso_code); if ($vat_rate > 0) { Context::getContext()->cookie->__set('customer_vat_rate', $vat_rate); } } /** * Override getAverageProductsTaxRate to ensure correct tax calculation */ public function getAverageProductsTaxRate(&$cartAmountTaxExcluded = null, &$cartAmountTaxIncluded = null) { // Fix context issue if (!Context::getContext()->cart || Context::getContext()->cart->id != $this->id) { Context::getContext()->cart = $this; } // If we have a stored VAT rate for EU customer, use it if ($this->isEUCustomer() && isset(Context::getContext()->cookie->customer_vat_rate)) { $vat_rate = (float)Context::getContext()->cookie->customer_vat_rate; try { $cartAmountTaxExcluded = $this->getOrderTotal(false, Cart::ONLY_PRODUCTS); $cartAmountTaxIncluded = $cartAmountTaxExcluded * (1 + ($vat_rate / 100)); return $vat_rate / 100; } catch (Exception $e) { // Log error and fall back to parent method PrestaShopLogger::addLog( 'Cart Override: Error in getAverageProductsTaxRate for cart ID ' . $this->id . ': ' . $e->getMessage(), 3, null, 'Cart', $this->id ); return parent::getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded); } } return parent::getAverageProductsTaxRate($cartAmountTaxExcluded, $cartAmountTaxIncluded); } }
Fatal error: Uncaught Error: Class 'Cart' not found in /home/tsgduwfxmk/domains/tsgduwfxmk.cfolks.pl/public_html/classes/controller/FrontController.php:467 Stack trace: #0 /home/tsgduwfxmk/domains/tsgduwfxmk.cfolks.pl/public_html/controllers/front/listing/CategoryController.php(81): FrontControllerCore->init() #1 /home/tsgduwfxmk/domains/tsgduwfxmk.cfolks.pl/public_html/classes/controller/Controller.php(300): CategoryControllerCore->init() #2 /home/tsgduwfxmk/domains/tsgduwfxmk.cfolks.pl/public_html/classes/Dispatcher.php(510): ControllerCore->run() #3 /home/tsgduwfxmk/domains/tsgduwfxmk.cfolks.pl/public_html/index.php(28): DispatcherCore->dispatch() #4 {main} thrown in /home/tsgduwfxmk/domains/tsgduwfxmk.cfolks.pl/public_html/classes/controller/FrontController.php on line 467