try to fix missing zip error
This commit is contained in:
@@ -161,9 +161,7 @@ public function calculateRate($params, $shipping_cost, $products, $originalModul
|
||||
$token = $this->getAccessToken();
|
||||
if (!$token) return false;
|
||||
|
||||
// 2. Identify Service (Module Loop context)
|
||||
$carrierId = (int)$originalModule->id_carrier;
|
||||
// Fallback
|
||||
if (!$carrierId && isset($params->id_carrier)) {
|
||||
$carrierId = (int)$params->id_carrier;
|
||||
}
|
||||
@@ -171,7 +169,6 @@ public function calculateRate($params, $shipping_cost, $products, $originalModul
|
||||
// 3. Get Method Code
|
||||
$sql = 'SELECT code FROM `' . _DB_PREFIX_ . 'uspsl_method` WHERE id_carrier = ' . (int)$carrierId;
|
||||
$methodCode = \Db::getInstance()->getValue($sql);
|
||||
|
||||
if (!$methodCode) return false;
|
||||
|
||||
// --- 4. CHECK LEGACY DB CACHE ---
|
||||
@@ -180,14 +177,11 @@ public function calculateRate($params, $shipping_cost, $products, $originalModul
|
||||
|
||||
if ($canCache) {
|
||||
$zhCache = \UspsPsLabels\Cache::cacheCart($params->id);
|
||||
|
||||
if (\Validate::isLoadedObject($zhCache)) {
|
||||
$sql = 'SELECT rate FROM `' . _DB_PREFIX_ . 'uspsl_cache_rate`
|
||||
WHERE id_cache = ' . (int)$zhCache->id . '
|
||||
AND id_carrier = ' . (int)$carrierId;
|
||||
|
||||
$cachedRate = \Db::getInstance()->getValue($sql);
|
||||
|
||||
if ($cachedRate !== false && $cachedRate !== null) {
|
||||
return (float)$cachedRate + $shipping_cost;
|
||||
}
|
||||
@@ -196,32 +190,39 @@ public function calculateRate($params, $shipping_cost, $products, $originalModul
|
||||
// -------------------------------
|
||||
|
||||
// 5. Determine International Status & Address Data (Cookie/Object Hybrid)
|
||||
$destAddress = new \Address($params->id_address_delivery);
|
||||
$destZip = '';
|
||||
$destCountryIso = 'US';
|
||||
$destCountryIso = '';
|
||||
|
||||
if (\Validate::isLoadedObject($destAddress)) {
|
||||
// Real Address exists
|
||||
$destZip = $destAddress->postcode;
|
||||
$destCountryIso = \Country::getIsoById($destAddress->id_country);
|
||||
} else {
|
||||
// Fallback for Estimator (Cookies)
|
||||
$context = \Context::getContext();
|
||||
|
||||
if (isset($context->cookie->id_country) && $context->cookie->id_country) {
|
||||
$destCountryIso = \Country::getIsoById($context->cookie->id_country);
|
||||
} elseif (isset($params->id_country) && $params->id_country) {
|
||||
$destCountryIso = \Country::getIsoById($params->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 (isset($context->cookie->postcode) && $context->cookie->postcode) {
|
||||
if (empty($destZip) && Tools::getIsset('postcode')) {
|
||||
$destZip = Tools::getValue('postcode');
|
||||
}
|
||||
if (empty($destCountryIso) && Tools::getIsset('id_country')) {
|
||||
$destCountryIso = Country::getIsoById((int)Tools::getValue('id_country'));
|
||||
}
|
||||
$context = Context::getContext();
|
||||
if (empty($destZip) && isset($context->cookie->postcode)) {
|
||||
$destZip = $context->cookie->postcode;
|
||||
}
|
||||
|
||||
// If absolutely no data, we can't calculate
|
||||
if (empty($destZip) && empty($destCountryIso)) {
|
||||
return false;
|
||||
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($destZip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Clean Data
|
||||
@@ -281,7 +282,6 @@ public function calculateRate($params, $shipping_cost, $products, $originalModul
|
||||
$payload['rateIndicator'] = $flatRateIndicator;
|
||||
}
|
||||
|
||||
// FIX: Pass destCountryIso directly, do not rely on Address object inside this helper
|
||||
$response = $this->sendApiRequest($client, $payload, $isInternational, $destCountryIso, $destZip);
|
||||
|
||||
if (isset($response['error']) && $payload['priceType'] === 'COMMERCIAL') {
|
||||
|
||||
Reference in New Issue
Block a user