From 948aeb2b1d4462202da2625f5634ae5d763b187a Mon Sep 17 00:00:00 2001 From: O K Date: Wed, 21 Jan 2026 15:11:29 +0200 Subject: [PATCH] improve externalLog --- .../modules/zh_uspslabels/zh_uspslabels.php | 3 + usps_api_bridge.php | 57 ++++++++++--------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/override/modules/zh_uspslabels/zh_uspslabels.php b/override/modules/zh_uspslabels/zh_uspslabels.php index f8b51f8..a0d4dbf 100644 --- a/override/modules/zh_uspslabels/zh_uspslabels.php +++ b/override/modules/zh_uspslabels/zh_uspslabels.php @@ -32,6 +32,9 @@ class Zh_UspsLabelsOverride extends Zh_UspsLabels // If Bridge returns a valid numeric rate, use it. // If it returns FALSE (api error, no token, etc), fall back to old logic. if ($newRate !== false && $newRate !== null) { + if ($this->getHelper()->getModuleHelper()->getConfig('ADD_EASYPOST_FEE') && $newRate > 0) { + $newRate += 0.01; + } return $newRate; } $bridge->externalLog(['calculateRate Failed' => ['params' => $params, 'shipping_cost' => $shipping_cost, 'products' => $products, 'this' => $this]]); diff --git a/usps_api_bridge.php b/usps_api_bridge.php index 054bf04..a5f194f 100644 --- a/usps_api_bridge.php +++ b/usps_api_bridge.php @@ -203,8 +203,11 @@ class Usps_Api_Bridge extends Module 'postcode' => Tools::getValue('postcode'), 'id_country' => Tools::getValue('id_country'), ]]); + $destZip = $context->cookie->postcode; + $destCountryIso = Country::getIsoById((int)$context->cookie->id_country); - if (Tools::getIsset('postcode')) { + + /* if (Tools::getIsset('postcode')) { $destZip = Tools::getValue('postcode'); } elseif (isset($context->cookie->postcode)) { $destZip = $context->cookie->postcode; @@ -214,34 +217,35 @@ class Usps_Api_Bridge extends Module $destCountryIso = Country::getIsoById((int)Tools::getValue('id_country')); } elseif (isset($context->cookie->id_country)) { $destCountryIso = Country::getIsoById((int)$context->cookie->id_country); - } - } - if (!empty($params->id_address_delivery)) { - $address = new Address($params->id_address_delivery); - if (Validate::isLoadedObject($address)) { - if (!empty($address->postcode)) { - $destZip = $address->postcode; - } - if (!empty($address->id_country)) { - $destCountryIso = Country::getIsoById($address->id_country); + } */ + } else { + if (!empty($params->id_address_delivery)) { + $address = new Address($params->id_address_delivery); + if (Validate::isLoadedObject($address)) { + if (!empty($address->postcode)) { + $destZip = $address->postcode; + } + if (!empty($address->id_country)) { + $destCountryIso = Country::getIsoById($address->id_country); + } } } - } - if (empty($destZip) && isset($context->cookie->postcode)) { - $destZip = $context->cookie->postcode; - } - if (empty($destCountryIso) && isset($context->cookie->id_country)) { - $destCountryIso = Country::getIsoById((int)$context->cookie->id_country); - } else if (empty($destCountryIso) && isset($params->id_country)) { - $destCountryIso = Country::getIsoById((int)$params->id_country); - } + if (empty($destZip) && isset($context->cookie->postcode)) { + $destZip = $context->cookie->postcode; + } + if (empty($destCountryIso) && isset($context->cookie->id_country)) { + $destCountryIso = Country::getIsoById((int)$context->cookie->id_country); + } else if (empty($destCountryIso) && isset($params->id_country)) { + $destCountryIso = Country::getIsoById((int)$params->id_country); + } - if (empty($destCountryIso)) { - $this->externalLog([ - 'destCountryIso' => 'set to default', - ]); - $destCountryIso = 'US'; + if (empty($destCountryIso)) { + $this->externalLog([ + 'destCountryIso' => 'set to default', + ]); + $destCountryIso = 'US'; + } } if (empty($destZip)) { @@ -255,7 +259,7 @@ class Usps_Api_Bridge extends Module $originZip = $this->getOriginZip($originalModule); // $originZip = substr(preg_replace('/[^0-9]/', '', $originZip), 0, 5); // $destZip = substr(preg_replace('/[^0-9]/', '', $destZip), 0, 5); - $isInternational = ($destCountryIso !== 'US'); + $isInternational = $destCountryIso !== 'US'; // Map Code $newApiClass = $this->mapServiceCodeToApiClass($methodCode, $isInternational); @@ -263,6 +267,7 @@ class Usps_Api_Bridge extends Module $this->externalLog([ 'mapServiceCodeToApiClass()' => 'failed', 'methodCode' => $methodCode, + 'carrierId' => $carrierId, 'isInternational' => $isInternational, ]); return false;