Skip to content

Commit a1776ac

Browse files
committed
MAGETWO-91622: Error on RMA shipping label creation for FedEx Smart Post
- Fixed incorrect payment type for FedEx Smart Post Return request - Added possibility to parse multiple tracking codes for one Return request
1 parent 67db61e commit a1776ac

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
namespace Magento\Fedex\Model;
88

99
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\DataObject;
1011
use Magento\Framework\Module\Dir;
1112
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\Framework\Webapi\Soap\ClientFactory;
1214
use Magento\Framework\Xml\Security;
1315
use Magento\Quote\Model\Quote\Address\RateRequest;
1416
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
@@ -17,7 +19,6 @@
1719
/**
1820
* Fedex shipping implementation
1921
*
20-
* @author Magento Core Team <core@magentocommerce.com>
2122
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2223
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2324
*/
@@ -143,6 +144,11 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
143144
*/
144145
private $serializer;
145146

147+
/**
148+
* @var ClientFactory
149+
*/
150+
private $soapClientFactory;
151+
146152
/**
147153
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
148154
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
@@ -164,7 +170,7 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
164170
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
165171
* @param array $data
166172
* @param Json|null $serializer
167-
*
173+
* @param ClientFactory|null $soapClientFactory
168174
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
169175
*/
170176
public function __construct(
@@ -187,7 +193,8 @@ public function __construct(
187193
\Magento\Framework\Module\Dir\Reader $configReader,
188194
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
189195
array $data = [],
190-
Json $serializer = null
196+
Json $serializer = null,
197+
ClientFactory $soapClientFactory = null
191198
) {
192199
$this->_storeManager = $storeManager;
193200
$this->_productCollectionFactory = $productCollectionFactory;
@@ -214,6 +221,7 @@ public function __construct(
214221
$this->_rateServiceWsdl = $wsdlBasePath . 'RateService_v10.wsdl';
215222
$this->_trackServiceWsdl = $wsdlBasePath . 'TrackService_v' . self::$trackServiceVersion . '.wsdl';
216223
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
224+
$this->soapClientFactory = $soapClientFactory ?: ObjectManager::getInstance()->get(ClientFactory::class);
217225
}
218226

219227
/**
@@ -225,7 +233,7 @@ public function __construct(
225233
*/
226234
protected function _createSoapClient($wsdl, $trace = false)
227235
{
228-
$client = new \SoapClient($wsdl, ['trace' => $trace]);
236+
$client = $this->soapClientFactory->create($wsdl, ['trace' => $trace]);
229237
$client->__setLocation(
230238
$this->getConfigFlag(
231239
'sandbox_mode'
@@ -1263,7 +1271,7 @@ protected function _formShipmentRequest(\Magento\Framework\DataObject $request)
12631271
$countriesOfManufacture[] = $product->getCountryOfManufacture();
12641272
}
12651273

1266-
$paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER';
1274+
$paymentType = $this->getPaymentType($request);
12671275
$optionType = $request->getShippingMethod() == self::RATE_REQUEST_SMARTPOST
12681276
? 'SERVICE_DEFAULT' : $packageParams->getDeliveryConfirmation();
12691277
$requestClient = [
@@ -1749,4 +1757,18 @@ private function parseDate($timestamp)
17491757

17501758
return false;
17511759
}
1760+
1761+
/**
1762+
* Defines payment type by request.
1763+
* Two values are available: RECIPIENT or SENDER.
1764+
*
1765+
* @param DataObject $request
1766+
* @return string
1767+
*/
1768+
private function getPaymentType(DataObject $request): string
1769+
{
1770+
return $request->getIsReturn() && $request->getShippingMethod() !== self::RATE_REQUEST_SMARTPOST
1771+
? 'RECIPIENT'
1772+
: 'SENDER';
1773+
}
17521774
}

dev/tests/integration/testsuite/Magento/Sales/_files/address_data.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
return [
88
'region' => 'CA',
9+
'region_id' => '12',
910
'postcode' => '11111',
1011
'lastname' => 'lastname',
1112
'firstname' => 'firstname',

0 commit comments

Comments
 (0)