Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed UPS Rest API bugs #3976

Merged
merged 11 commits into from
May 12, 2024
61 changes: 31 additions & 30 deletions app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,13 @@ public function setRequest(Mage_Shipping_Model_Rate_Request $request)
}

$r->setDestCountry(Mage::getModel('directory/country')->load($destCountry)->getIso2Code());

$r->setDestRegionCode($request->getDestRegionCode());

if ($request->getDestPostcode()) {
$r->setDestPostal($request->getDestPostcode());
}

$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());

$weight = $this->_getCorrectWeight($weight);

$r->setWeight($weight);
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
$r->setFreeMethodWeight($request->getFreeMethodWeight());
Expand All @@ -270,11 +266,15 @@ public function setRequest(Mage_Shipping_Model_Rate_Request $request)
$unit = $this->getConfigData('unit_of_measure');
}
$r->setUnitMeasure($unit);

if ($r->getUnitMeasure() == 'LBS') {
$r->setUnitDimensions('IN');
$r->setUnitDimensionsDescription('Inches');
} else {
$r->setUnitDimensions('CM');
$r->setUnitDimensionsDescription('Centimeters');
}
$r->setIsReturn($request->getIsReturn());

$r->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());

$this->_rawRequest = $r;

return $this;
Expand Down Expand Up @@ -755,8 +755,8 @@ protected function _getXmlQuotes()

$xmlRequest .= (
$params['49_residential'] === '01'
? "<ResidentialAddressIndicator>{$params['49_residential']}</ResidentialAddressIndicator>"
: ''
? "<ResidentialAddressIndicator>{$params['49_residential']}</ResidentialAddressIndicator>"
: ''
);

$xmlRequest .= <<< XMLRequest
Expand Down Expand Up @@ -1150,11 +1150,15 @@ protected function _getRestTracking($trackings)
$version = "v1";
$query = http_build_query([
'locale' => 'en_US',
'returnSignature' => 'false'
'returnSignature' => 'false',
'returnMilestones' => 'false',
'returnPOD' => 'false'
]);
$headers = [
"Authorization: Bearer $accessToken",
'Content-Type: application/json'
'Content-Type: application/json',
'transId: track' . uniqid(),
'transactionSrc: OpenMage'
];

$ch = curl_init();
Expand Down Expand Up @@ -1201,7 +1205,7 @@ protected function _parseRestTrackingResponse($trackingValue, $jsonResponse)
if ($jsonResponse) {
$responseData = json_decode($jsonResponse, true);

if ($responseData['trackResponse']['shipment']) {
if (isset($responseData['trackResponse']['shipment'])) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
$activityTags = $responseData['trackResponse']['shipment'][0]['package'][0]['activity'] ?? [];
if ($activityTags) {
fballiano marked this conversation as resolved.
Show resolved Hide resolved
$index = 1;
Expand Down Expand Up @@ -1255,8 +1259,8 @@ protected function _parseRestTrackingResponse($trackingValue, $jsonResponse)
}
$resultArr['progressdetail'] = $packageProgress;
}
} else {
$errorTitle = $responseData['errors']['message'];
} elseif (isset($responseData['response']['errors'][0]['message'])) {
$errorTitle = $responseData['response']['errors'][0]['message'];
}
}

Expand Down Expand Up @@ -1490,9 +1494,9 @@ protected function _formShipmentRequest(Varien_Object $request)
$referenceData = $request->getReferenceData() . $request->getPackageId();
} else {
$referenceData = 'Order #'
. $request->getOrderShipment()->getOrder()->getIncrementId()
. ' P'
. $request->getPackageId();
. $request->getOrderShipment()->getOrder()->getIncrementId()
. ' P'
. $request->getPackageId();
}
$referencePart = $packagePart->addChild('ReferenceNumber');
$referencePart->addChild('Code', '02');
Expand Down Expand Up @@ -1537,9 +1541,9 @@ protected function _formShipmentRequest(Varien_Object $request)

$labelPart = $xmlRequest->addChild('LabelSpecification');
$labelPart->addChild('LabelPrintMethod')
->addChild('Code', 'GIF');
->addChild('Code', 'GIF');
$labelPart->addChild('LabelImageFormat')
->addChild('Code', 'GIF');
->addChild('Code', 'GIF');

$this->setXMLAccessRequest();
$xmlRequest = $this->_xmlAccessRequest . $xmlRequest->asXML();
Expand Down Expand Up @@ -2045,12 +2049,9 @@ public function getContainerTypes(Varien_Object $params = null)
$countryShipper = $params->getCountryShipper();
$countryRecipient = $params->getCountryRecipient();

if (($countryShipper == self::USA_COUNTRY_ID
&& $countryRecipient == self::CANADA_COUNTRY_ID)
|| ($countryShipper == self::CANADA_COUNTRY_ID
&& $countryRecipient == self::USA_COUNTRY_ID)
|| ($countryShipper == self::MEXICO_COUNTRY_ID
&& $countryRecipient == self::USA_COUNTRY_ID)
if (($countryShipper == self::USA_COUNTRY_ID && $countryRecipient == self::CANADA_COUNTRY_ID)
|| ($countryShipper == self::CANADA_COUNTRY_ID && $countryRecipient == self::USA_COUNTRY_ID)
|| ($countryShipper == self::MEXICO_COUNTRY_ID && $countryRecipient == self::USA_COUNTRY_ID)
&& $method == '11' // UPS Standard
) {
$containerTypes = [];
Expand All @@ -2072,14 +2073,14 @@ public function getContainerTypes(Varien_Object $params = null)
'2a' => Mage::helper('usa')->__('Small Express Box'),
'2b' => Mage::helper('usa')->__('Medium Express Box'),
'2c' => Mage::helper('usa')->__('Large Express Box'),
];
];
}
return ['00' => Mage::helper('usa')->__('Customer Packaging')] + $containerTypes;
} elseif ($countryShipper == self::USA_COUNTRY_ID && $countryRecipient == self::PUERTORICO_COUNTRY_ID
&& (
$method == '03' // UPS Ground
|| $method == '02' // UPS Second Day Air
|| $method == '01' // UPS Next Day Air
|| $method == '02' // UPS Second Day Air
|| $method == '01' // UPS Next Day Air
)
) {
// Container types should be the same as for domestic
Expand Down Expand Up @@ -2290,8 +2291,8 @@ protected function _getRestQuotes()
],
"Dimensions" => [
"UnitOfMeasurement" => [
"Code" => "IN",
"Description" => "Inches"
"Code" => $rowRequest->getUnitDimensions(),
"Description" => $rowRequest->getUnitDimensionsDescription()
],
"Length" => "5",
"Width" => "5",
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Usa/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@
<dest_type>RES</dest_type>
<free_method>GND</free_method>
<gateway_xml_url>https://onlinetools.ups.com/ups.app/xml/Rate</gateway_xml_url>
<gateway_rest_url>https://wwwcie.ups.com/api/rating/</gateway_rest_url>
<gateway_rest_url>https://onlinetools.ups.com/api/rating/</gateway_rest_url>
<tracking_xml_url>https://onlinetools.ups.com/ups.app/xml/Track</tracking_xml_url>
<tracking_rest_url>https://wwwcie.ups.com/api/track/</tracking_rest_url>
<tracking_rest_url>https://onlinetools.ups.com/api/track/</tracking_rest_url>
<shipconfirm_xml_url>https://onlinetools.ups.com/ups.app/xml/ShipConfirm</shipconfirm_xml_url>
<shipconfirm_rest_url>https://wwwcie.ups.com/api/shipments/v2403/ship</shipconfirm_rest_url>
<shipconfirm_rest_url>https://onlinetools.ups.com/api/shipments/v2403/ship</shipconfirm_rest_url>
<shipaccept_xml_url>https://onlinetools.ups.com/ups.app/xml/ShipAccept</shipaccept_xml_url>
<verify_peer>0</verify_peer>
<handling>0</handling>
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Usa/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@
</origin_shipment>
<client_id translate="label comment">
<label>Client ID</label>
<comment><![CDATA[To obtain your Client ID/Secret you have to:<br />- Register to <a href='https://developer.ups.com' target=_blank>https://developer.ups.com</a><br />- Go to My Apps -> Add Apps and fill all data<br />- Add Rating/Authorization/Shipping/TimeInTransit products to the app]]></comment>
<comment><![CDATA[To obtain your Client ID/Secret you have to:<br />- Register to <a href='https://developer.ups.com' target=_blank>https://developer.ups.com</a><br />- Go to My Apps -> Add Apps and fill all data<br />- Add Rating, Authorization, Shipping, TimeInTransit, Tracking products to the app]]></comment>
<frontend_type>obscure</frontend_type>
<backend_model>adminhtml/system_config_backend_encrypted</backend_model>
<sort_order>35</sort_order>
Expand Down
Loading