Skip to content

Commit dc5874d

Browse files
committed
#AC-9290::UPS shipping - 'Origin of the Shipment' set to 'Mexico', UPS shipping methods are not displayed - fixes and code review changes
1 parent 43a280e commit dc5874d

19 files changed

+1708
-1870
lines changed

app/code/Magento/Ups/Helper/Config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,17 @@ protected function getCodes()
121121
],
122122
// Shipments Originating in Mexico
123123
'Shipments Originating in Mexico' => [
124+
'01' => __('UPS Next Day Air'),
125+
'02' => __('UPS Second Day Air'),
126+
'03' => __('UPS Ground'),
124127
'07' => __('UPS Express'),
125128
'08' => __('UPS Expedited'),
129+
'11' => __('UPS Standard'),
130+
'12' => __('UPS Three-Day Select'),
131+
'13' => __('UPS Next Day Air Saver'),
132+
'14' => __('UPS Next Day Air Early A.M.'),
126133
'54' => __('UPS Express Plus'),
134+
'59' => __('UPS Second Day Air A.M.'),
127135
'65' => __('UPS Saver'),
128136
],
129137
// Shipments Originating in Other Countries

app/code/Magento/Ups/Model/Carrier.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class Carrier extends AbstractCarrierOnline implements CarrierInterface
157157
protected $_debugReplacePrivateDataKeys = [
158158
'UserId',
159159
'Password',
160-
'AccessLicenseNumber',
161160
];
162161

163162
/**
@@ -582,10 +581,9 @@ protected function _getQuotes()
582581
}
583582
$serviceDescription = $serviceCode ? $this->getShipmentByCode($serviceCode) : '';
584583

584+
$shipperNumber = '';
585585
if ($this->getConfigFlag('negotiated_active') && ($shipperNumber = $this->getConfigData('shipper_number'))) {
586586
$shipperNumber = $this->getConfigData('shipper_number');
587-
} else {
588-
$shipperNumber = '';
589587
}
590588

591589
if ($rowRequest->getIsReturn()) {
@@ -600,10 +598,9 @@ protected function _getQuotes()
600598
$shipperStateProvince = $params['origRegionCode'];
601599
}
602600

601+
$residentialAddressIndicator = '';
603602
if ($params['49_residential'] === '01') {
604603
$residentialAddressIndicator = $params['49_residential'];
605-
} else {
606-
$residentialAddressIndicator = '';
607604
}
608605

609606
$rateParams = [
@@ -1051,17 +1048,6 @@ protected function _parseRestTrackingResponse($trackingValue, $jsonResponse)
10511048
$responseData = json_decode($jsonResponse, true);
10521049

10531050
if ($responseData['trackResponse']['shipment']) {
1054-
/**
1055-
$resultArr['service'] =
1056-
$responseData['trackResponse']['shipment']['package']['service']['description'];
1057-
$resultArr['shippeddate'] =
1058-
$responseData['trackResponse']['shipment']['package']['accessPointInformation']['pickupByDate'];
1059-
$weight = $responseData['trackResponse']['shipment']['package']['weight']['weight'];
1060-
$unit = $responseData['trackResponse']['shipment']['package']['weight']['unitOfMeasurement'];
1061-
1062-
$resultArr['weight'] = "{$weight} {$unit}";
1063-
*/
1064-
10651051
$activityTags = $responseData['trackResponse']['shipment'][0]['package'][0]['activity'] ?? [];
10661052
if ($activityTags) {
10671053
$index = 1;
@@ -1142,8 +1128,6 @@ private function processActivityTagInfo(
11421128
//YYYY-MM-DD
11431129
$resultArr['deliverytime'] = implode(':', $timeArr);
11441130
//HH:MM:SS
1145-
//$resultArr['deliverylocation'] = (string)$activityTag['location']['address'];
1146-
//$resultArr['signedby'] = (string)$activityTag->ActivityLocation->SignedForByName;
11471131
if ($addressArr) {
11481132
$resultArr['deliveryto'] = implode(', ', $addressArr);
11491133
}
@@ -1254,16 +1238,12 @@ protected function _formShipmentRequest(DataObject $request)
12541238
]
12551239
];
12561240

1257-
/** need to check this part
12581241
if ($request->getIsReturn()) {
1259-
$returnPart = $shipmentPart->addChild('ReturnService');
1260-
// UPS Print Return Label
1261-
$returnPart->addChild('Code', '9');
1242+
$returnPart = &$shipParams['ShipmentRequest']['Shipment'];
1243+
$returnPart['ReturnService']['Code'] = '9';
12621244
}
1263-
*/
12641245

12651246
/** Shipment Details */
1266-
12671247
if ($request->getIsReturn()) {
12681248
$shipperData = &$shipParams['ShipmentRequest']['Shipment']['Shipper'];
12691249

app/code/Magento/Ups/Model/UpsAuth.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
2+
/************************************************************************
3+
*
4+
* ADOBE CONFIDENTIAL
5+
* ___________________
6+
*
7+
* Copyright 2023 Adobe
8+
* All Rights Reserved.
9+
*
10+
* NOTICE: All information contained herein is, and remains
11+
* the property of Adobe and its suppliers, if any. The intellectual
12+
* and technical concepts contained herein are proprietary to Adobe
13+
* and its suppliers and are protected by all applicable intellectual
14+
* property laws, including trade secret and copyright laws.
15+
* Dissemination of this information or reproduction of this material
16+
* is strictly forbidden unless prior written permission is obtained
17+
* from Adobe.
18+
* ************************************************************************
519
*/
20+
621
declare(strict_types=1);
722

823
namespace Magento\Ups\Model;
@@ -15,11 +30,12 @@
1530
use Magento\Framework\HTTP\AsyncClientInterface;
1631
use Magento\Quote\Model\Quote\Address\RateRequest;
1732
use Magento\Quote\Model\Quote\Address\RateResult\Error;
33+
use Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory;
1834
use Magento\Shipping\Model\Carrier\AbstractCarrier;
1935

2036
class UpsAuth extends AbstractCarrier
2137
{
22-
public const TEST_AUTH_URL = 'https://wwwcie.ups.com/security/v1/oauth/token';
38+
public const UPS_AUTH_URL = 'https://wwwcie.ups.com/security/v1/oauth/token';
2339
public const CACHE_KEY_PREFIX = 'ups_api_token_';
2440

2541
/**
@@ -33,19 +49,19 @@ class UpsAuth extends AbstractCarrier
3349
private $cache;
3450

3551
/**
36-
* @var \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory
52+
* @var ErrorFactory
3753
*/
3854
public $_rateErrorFactory;
3955

4056
/**
4157
* @param AsyncClientInterface|null $asyncHttpClient
4258
* @param Cache $cacheManager
43-
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
59+
* @param ErrorFactory $rateErrorFactory
4460
*/
4561
public function __construct(
4662
AsyncClientInterface $asyncHttpClient = null,
4763
Cache $cacheManager,
48-
\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
64+
ErrorFactory $rateErrorFactory
4965
) {
5066
$this->asyncHttpClient = $asyncHttpClient ?? ObjectManager::getInstance()->get(AsyncClientInterface::class);
5167
$this->cache = $cacheManager;
@@ -63,7 +79,6 @@ public function __construct(
6379
*/
6480
public function getAccessToken($clientId, $clientSecret)
6581
{
66-
6782
$cacheKey = self::CACHE_KEY_PREFIX;
6883
$result = $this->cache->load($cacheKey);
6984
if (!$result) {
@@ -77,7 +92,7 @@ public function getAccessToken($clientId, $clientSecret)
7792
]);
7893
try {
7994
$asyncResponse = $this->asyncHttpClient->request(new Request(
80-
self::TEST_AUTH_URL,
95+
self::UPS_AUTH_URL,
8196
Request::METHOD_POST,
8297
$headers,
8398
$authPayload

app/code/Magento/Ups/Test/Unit/Model/CarrierTest.php

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -270,80 +270,6 @@ public function testCollectRatesErrorMessage(): void
270270
$this->assertSame($this->error, $this->model->collectRates($request));
271271
}
272272

273-
/**
274-
* @param string $data
275-
* @param array $maskFields
276-
* @param string $expected
277-
*
278-
* @return void
279-
* @dataProvider logDataProvider
280-
*/
281-
public function testFilterDebugData($data, array $maskFields, $expected): void
282-
{
283-
$refClass = new \ReflectionClass(Carrier::class);
284-
$property = $refClass->getProperty('_debugReplacePrivateDataKeys');
285-
$property->setAccessible(true);
286-
$property->setValue($this->model, $maskFields);
287-
288-
$refMethod = $refClass->getMethod('filterDebugData');
289-
$refMethod->setAccessible(true);
290-
$result = $refMethod->invoke($this->model, $data);
291-
$expectedXml = new \SimpleXMLElement($expected);
292-
$resultXml = new \SimpleXMLElement($result);
293-
$this->assertEquals($expectedXml->asXML(), $resultXml->asXML());
294-
}
295-
296-
/**
297-
* Get list of variations.
298-
*
299-
* @return array
300-
*/
301-
public function logDataProvider(): array
302-
{
303-
return [
304-
[
305-
'<?xml version="1.0" encoding="UTF-8"?>
306-
<RateRequest>
307-
<UserId>42121</UserId>
308-
<Password>TestPassword</Password>
309-
<Package ID="0">
310-
<Service>ALL</Service>
311-
</Package>
312-
</RateRequest>',
313-
['UserId', 'Password'],
314-
'<?xml version="1.0" encoding="UTF-8"?>
315-
<RateRequest>
316-
<UserId>****</UserId>
317-
<Password>****</Password>
318-
<Package ID="0">
319-
<Service>ALL</Service>
320-
</Package>
321-
</RateRequest>'
322-
],
323-
[
324-
'<?xml version="1.0" encoding="UTF-8"?>
325-
<RateRequest>
326-
<Auth>
327-
<UserId>1231</UserId>
328-
</Auth>
329-
<Package ID="0">
330-
<Service>ALL</Service>
331-
</Package>
332-
</RateRequest>',
333-
['UserId'],
334-
'<?xml version="1.0" encoding="UTF-8"?>
335-
<RateRequest>
336-
<Auth>
337-
<UserId>****</UserId>
338-
</Auth>
339-
<Package ID="0">
340-
<Service>ALL</Service>
341-
</Package>
342-
</RateRequest>'
343-
]
344-
];
345-
}
346-
347273
/**
348274
* @param array $requestData
349275
* @param array $rawRequestData

0 commit comments

Comments
 (0)