Compare commits

..

3 Commits

Author SHA1 Message Date
O K
948aeb2b1d improve externalLog 2026-01-21 15:11:29 +02:00
O K
adc581282f update estimator logic 2026-01-21 09:59:16 +02:00
O K
7601859990 extend debug info 2026-01-21 09:55:35 +02:00
2 changed files with 55 additions and 23 deletions

View File

@@ -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]]);

View File

@@ -15,7 +15,7 @@ class Usps_Api_Bridge extends Module
{
$this->name = 'usps_api_bridge';
$this->tab = 'shipping_logistics';
$this->version = '1.0.1';
$this->version = '1.0.2';
$this->author = 'Panariga';
$this->need_instance = 0;
$this->bootstrap = true;
@@ -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,30 +217,41 @@ 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);
} */
} 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($params->id_address_delivery)) {
$address = new Address($params->id_address_delivery);
if (Validate::isLoadedObject($address)) {
$destZip = $address->postcode;
$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)) {
$destCountryIso = 'US';
if (empty($destCountryIso)) {
$this->externalLog([
'destCountryIso' => 'set to default',
]);
$destCountryIso = 'US';
}
}
if (empty($destZip)) {
$this->externalLog([
'destZip' => 'is empty',
]);
return false;
}
@@ -245,15 +259,30 @@ 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);
if (!$newApiClass) return false;
if (!$newApiClass) {
$this->externalLog([
'mapServiceCodeToApiClass()' => 'failed',
'methodCode' => $methodCode,
'carrierId' => $carrierId,
'isInternational' => $isInternational,
]);
return false;
}
// 6. Pack Products
$packedBoxes = $originalModule->getHelper()->getCarrierHelper()->packProducts($products, $params->id);
if (empty($packedBoxes)) return false;
if (empty($packedBoxes)) {
$this->externalLog([
'packProducts()' => 'failed',
'products' => $products,
'params->id' => $params->id,
]);
return false;
}
// 7. Setup Client
$client = new UspsV3Client($token, (bool)\Configuration::get('USPS_BRIDGE_LIVE_MODE'));