remove mapServiceCodeToApiClass override
This commit is contained in:
@@ -153,7 +153,7 @@ class Usps_Api_Bridge extends Module
|
|||||||
|
|
||||||
return $helper->generateForm([$fields_form]);
|
return $helper->generateForm([$fields_form]);
|
||||||
}
|
}
|
||||||
public function calculateRate($params, $shipping_cost, $products, $originalModule)
|
public function calculateRate($params, $shipping_cost, $products, $originalModule)
|
||||||
{
|
{
|
||||||
require_once(dirname(__FILE__) . '/classes/UspsV3Client.php');
|
require_once(dirname(__FILE__) . '/classes/UspsV3Client.php');
|
||||||
|
|
||||||
@@ -161,11 +161,11 @@ class Usps_Api_Bridge extends Module
|
|||||||
$token = $this->getAccessToken();
|
$token = $this->getAccessToken();
|
||||||
if (!$token) return false;
|
if (!$token) return false;
|
||||||
|
|
||||||
|
|
||||||
// 2. Identify Service (Use the Module's ID, not the Cart's ID)
|
// 2. Identify Service (Use the Module's ID, not the Cart's ID)
|
||||||
// $originalModule->id_carrier is the carrier currently being calculated in the loop.
|
// $originalModule->id_carrier is the carrier currently being calculated in the loop.
|
||||||
$carrierId = (int)$originalModule->id_carrier;
|
$carrierId = (int)$originalModule->id_carrier;
|
||||||
|
|
||||||
// Fallback for edge cases where module ID might be missing (rare)
|
// Fallback for edge cases where module ID might be missing (rare)
|
||||||
if (!$carrierId && isset($params->id_carrier)) {
|
if (!$carrierId && isset($params->id_carrier)) {
|
||||||
$carrierId = (int)$params->id_carrier;
|
$carrierId = (int)$params->id_carrier;
|
||||||
@@ -191,7 +191,7 @@ class Usps_Api_Bridge extends Module
|
|||||||
$sql = 'SELECT rate FROM `' . _DB_PREFIX_ . 'uspsl_cache_rate`
|
$sql = 'SELECT rate FROM `' . _DB_PREFIX_ . 'uspsl_cache_rate`
|
||||||
WHERE id_cache = ' . (int)$zhCache->id . '
|
WHERE id_cache = ' . (int)$zhCache->id . '
|
||||||
AND id_carrier = ' . (int)$carrierId; // Use the correct ID here too!
|
AND id_carrier = ' . (int)$carrierId; // Use the correct ID here too!
|
||||||
|
|
||||||
$cachedRate = Db::getInstance()->getValue($sql);
|
$cachedRate = Db::getInstance()->getValue($sql);
|
||||||
|
|
||||||
if ($cachedRate !== false && $cachedRate !== null) {
|
if ($cachedRate !== false && $cachedRate !== null) {
|
||||||
@@ -226,16 +226,16 @@ class Usps_Api_Bridge extends Module
|
|||||||
|
|
||||||
// 9. Loop through boxes
|
// 9. Loop through boxes
|
||||||
foreach ($packedBoxes as $packedBox) {
|
foreach ($packedBoxes as $packedBox) {
|
||||||
|
|
||||||
$weightInLbs = $this->convertUnit($packedBox->getWeight(), 'g', 'lbs', 3);
|
$weightInLbs = $this->convertUnit($packedBox->getWeight(), 'g', 'lbs', 3);
|
||||||
if ($weightInLbs < 0.1) $weightInLbs = 0.1;
|
if ($weightInLbs < 0.1) $weightInLbs = 0.1;
|
||||||
|
|
||||||
$box = $packedBox->getBox();
|
$box = $packedBox->getBox();
|
||||||
$length = $this->convertUnit($box->getOuterLength(), 'mm', 'in', 2);
|
$length = $this->convertUnit($box->getOuterLength(), 'mm', 'in', 2);
|
||||||
$width = $this->convertUnit($box->getOuterWidth(), 'mm', 'in', 2);
|
$width = $this->convertUnit($box->getOuterWidth(), 'mm', 'in', 2);
|
||||||
$height = $this->convertUnit($box->getOuterDepth(), 'mm', 'in', 2);
|
$height = $this->convertUnit($box->getOuterDepth(), 'mm', 'in', 2);
|
||||||
|
|
||||||
$category = 'NONSTANDARD';
|
$category = 'NONSTANDARD';
|
||||||
if ($newApiClass === 'USPS_GROUND_ADVANTAGE') {
|
if ($newApiClass === 'USPS_GROUND_ADVANTAGE') {
|
||||||
if ($length <= 22 && $width <= 18 && $height <= 15 && $weightInLbs >= 0.375 && $weightInLbs <= 25) {
|
if ($length <= 22 && $width <= 18 && $height <= 15 && $weightInLbs >= 0.375 && $weightInLbs <= 25) {
|
||||||
$category = 'MACHINABLE';
|
$category = 'MACHINABLE';
|
||||||
@@ -252,7 +252,7 @@ class Usps_Api_Bridge extends Module
|
|||||||
'priceType' => $requestedPriceType,
|
'priceType' => $requestedPriceType,
|
||||||
'mailingDate' => date('Y-m-d', strtotime('+1 day')),
|
'mailingDate' => date('Y-m-d', strtotime('+1 day')),
|
||||||
'processingCategory' => $category,
|
'processingCategory' => $category,
|
||||||
'rateIndicator' => 'SP'
|
'rateIndicator' => 'SP'
|
||||||
];
|
];
|
||||||
|
|
||||||
$flatRateIndicator = $this->mapBoxToRateIndicator($box->getReference());
|
$flatRateIndicator = $this->mapBoxToRateIndicator($box->getReference());
|
||||||
@@ -286,7 +286,7 @@ class Usps_Api_Bridge extends Module
|
|||||||
$newCacheRate->id_cache = $zhCache->id;
|
$newCacheRate->id_cache = $zhCache->id;
|
||||||
$newCacheRate->id_carrier = $carrierId; // Use Correct ID
|
$newCacheRate->id_carrier = $carrierId; // Use Correct ID
|
||||||
$newCacheRate->code = $methodCode;
|
$newCacheRate->code = $methodCode;
|
||||||
$newCacheRate->rate = $totalPrice;
|
$newCacheRate->rate = $totalPrice;
|
||||||
$newCacheRate->save();
|
$newCacheRate->save();
|
||||||
}
|
}
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
@@ -403,7 +403,7 @@ class Usps_Api_Bridge extends Module
|
|||||||
*/
|
*/
|
||||||
private function mapServiceCodeToApiClass($oldCode, $isInternational)
|
private function mapServiceCodeToApiClass($oldCode, $isInternational)
|
||||||
{
|
{
|
||||||
$this->externalLog(['mapServiceCodeToApiClass' => ['oldCode' => $oldCode, 'isInternational' => $isInternational]]);
|
// $this->externalLog(['mapServiceCodeToApiClass' => ['oldCode' => $oldCode, 'isInternational' => $isInternational]]);
|
||||||
// 1. Define the Standard Map
|
// 1. Define the Standard Map
|
||||||
$map = [
|
$map = [
|
||||||
// DOMESTIC
|
// DOMESTIC
|
||||||
@@ -429,7 +429,7 @@ class Usps_Api_Bridge extends Module
|
|||||||
|
|
||||||
// 2. International Override Logic
|
// 2. International Override Logic
|
||||||
// If the destination is International, but the mapped class is Domestic, swap it.
|
// If the destination is International, but the mapped class is Domestic, swap it.
|
||||||
if ($isInternational) {
|
/* if ($isInternational) {
|
||||||
switch ($apiClass) {
|
switch ($apiClass) {
|
||||||
case 'PRIORITY_MAIL':
|
case 'PRIORITY_MAIL':
|
||||||
return 'PRIORITY_MAIL_INTERNATIONAL';
|
return 'PRIORITY_MAIL_INTERNATIONAL';
|
||||||
@@ -444,7 +444,7 @@ class Usps_Api_Bridge extends Module
|
|||||||
case 'LIBRARY_MAIL':
|
case 'LIBRARY_MAIL':
|
||||||
return 'FIRST-CLASS_PACKAGE_INTERNATIONAL_SERVICE';
|
return 'FIRST-CLASS_PACKAGE_INTERNATIONAL_SERVICE';
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
return $apiClass;
|
return $apiClass;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user