Skip to content

Commit 74c17f7

Browse files
merge magento/2.3.3-develop into magento-tsg/2.3.3-develop-pr73
2 parents 20f9520 + 50144fb commit 74c17f7

File tree

4 files changed

+101
-90
lines changed

4 files changed

+101
-90
lines changed

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

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\App\ProductMetadataInterface;
1212
use Magento\Framework\Async\CallbackDeferred;
13-
use Magento\Framework\Async\ProxyDeferredFactory;
1413
use Magento\Framework\HTTP\AsyncClient\HttpResponseDeferredInterface;
1514
use Magento\Framework\HTTP\AsyncClient\Request;
1615
use Magento\Framework\HTTP\AsyncClientInterface;
@@ -21,6 +20,7 @@
2120
use Magento\Quote\Model\Quote\Address\RateResult\Error;
2221
use Magento\Shipping\Model\Carrier\AbstractCarrier;
2322
use Magento\Shipping\Model\Rate\Result;
23+
use Magento\Shipping\Model\Rate\Result\ProxyDeferredFactory;
2424
use Magento\Framework\Xml\Security;
2525
use Magento\Dhl\Model\Validator\XmlValidator;
2626

@@ -389,16 +389,17 @@ public function collectRates(RateRequest $request)
389389
//Saving $result to use proper result with the callback
390390
$this->_result = $result = $this->_getQuotes();
391391
//After quotes are loaded parsing the response.
392-
return $this->proxyDeferredFactory->createFor(
393-
Result::class,
394-
new CallbackDeferred(
395-
function () use ($request, $result) {
396-
$this->_result = $result;
397-
$this->_updateFreeMethodQuote($request);
398-
399-
return $this->_result;
400-
}
401-
)
392+
return $this->proxyDeferredFactory->create(
393+
[
394+
'deferred' => new CallbackDeferred(
395+
function () use ($request, $result) {
396+
$this->_result = $result;
397+
$this->_updateFreeMethodQuote($request);
398+
399+
return $this->_result;
400+
}
401+
)
402+
]
402403
);
403404
}
404405

@@ -818,16 +819,16 @@ protected function _getAllItems()
818819

819820
if (!empty($decimalItems)) {
820821
foreach ($decimalItems as $decimalItem) {
821-
$fullItems = array_merge(
822-
$fullItems,
823-
array_fill(0, $decimalItem['qty'] * $qty, $decimalItem['weight'])
824-
);
822+
$fullItems[] = array_fill(0, $decimalItem['qty'] * $qty, $decimalItem['weight']);
825823
}
826824
} else {
827-
$fullItems = array_merge($fullItems, array_fill(0, $qty, $this->_getWeight($itemWeight)));
825+
$fullItems[] = array_fill(0, $qty, $this->_getWeight($itemWeight));
828826
}
829827
}
830-
sort($fullItems);
828+
if ($fullItems) {
829+
$fullItems = array_merge(...$fullItems);
830+
sort($fullItems);
831+
}
831832

832833
return $fullItems;
833834
}
@@ -1057,23 +1058,24 @@ protected function _getQuotes()
10571058
}
10581059
}
10591060

1060-
return $this->proxyDeferredFactory->createFor(
1061-
Result::class,
1062-
new CallbackDeferred(
1063-
function () use ($deferredResponses, $responseBodies) {
1064-
//Loading rates not found in cache
1065-
foreach ($deferredResponses as $deferredResponseData) {
1066-
$responseBodies[] = [
1067-
'body' => $deferredResponseData['deferred']->get()->getBody(),
1068-
'date' => $deferredResponseData['date'],
1069-
'request' => $deferredResponseData['request'],
1070-
'from_cache' => false
1071-
];
1072-
}
1061+
return $this->proxyDeferredFactory->create(
1062+
[
1063+
'deferred' => new CallbackDeferred(
1064+
function () use ($deferredResponses, $responseBodies) {
1065+
//Loading rates not found in cache
1066+
foreach ($deferredResponses as $deferredResponseData) {
1067+
$responseBodies[] = [
1068+
'body' => $deferredResponseData['deferred']->get()->getBody(),
1069+
'date' => $deferredResponseData['date'],
1070+
'request' => $deferredResponseData['request'],
1071+
'from_cache' => false
1072+
];
1073+
}
10731074

1074-
return $this->processQuotesResponses($responseBodies);
1075-
}
1076-
)
1075+
return $this->processQuotesResponses($responseBodies);
1076+
}
1077+
)
1078+
]
10771079
);
10781080
}
10791081

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Async\CallbackDeferred;
12-
use Magento\Framework\Async\ProxyDeferredFactory;
1312
use Magento\Framework\DataObject;
1413
use Magento\Framework\Exception\LocalizedException;
1514
use Magento\Framework\HTTP\AsyncClient\HttpResponseDeferredInterface;
@@ -22,6 +21,7 @@
2221
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
2322
use Magento\Shipping\Model\Carrier\CarrierInterface;
2423
use Magento\Shipping\Model\Rate\Result;
24+
use Magento\Shipping\Model\Rate\Result\ProxyDeferredFactory;
2525
use Magento\Shipping\Model\Simplexml\Element;
2626
use Magento\Ups\Helper\Config;
2727
use Magento\Shipping\Model\Shipment\Request as Shipment;
@@ -239,15 +239,16 @@ public function collectRates(RateRequest $request)
239239
//To use the correct result in the callback.
240240
$this->_result = $result = $this->_getQuotes();
241241

242-
return $this->deferredProxyFactory->createFor(
243-
Result::class,
244-
new CallbackDeferred(
245-
function () use ($request, $result) {
246-
$this->_result = $result;
247-
$this->_updateFreeMethodQuote($request);
248-
return $this->getResult();
249-
}
250-
)
242+
return $this->deferredProxyFactory->create(
243+
[
244+
'deferred' => new CallbackDeferred(
245+
function () use ($request, $result) {
246+
$this->_result = $result;
247+
$this->_updateFreeMethodQuote($request);
248+
return $this->getResult();
249+
}
250+
)
251+
]
251252
);
252253
}
253254

@@ -782,19 +783,20 @@ protected function _getXmlQuotes()
782783
new Request($url, Request::METHOD_POST, ['Content-Type' => 'application/xml'], $xmlRequest)
783784
);
784785

785-
return $this->deferredProxyFactory->createFor(
786-
Result::class,
787-
new CallbackDeferred(
788-
function () use ($httpResponse) {
789-
if ($httpResponse->get()->getStatusCode() >= 400) {
790-
$xmlResponse = '';
791-
} else {
792-
$xmlResponse = $httpResponse->get()->getBody();
793-
}
786+
return $this->deferredProxyFactory->create(
787+
[
788+
'deferred' => new CallbackDeferred(
789+
function () use ($httpResponse) {
790+
if ($httpResponse->get()->getStatusCode() >= 400) {
791+
$xmlResponse = '';
792+
} else {
793+
$xmlResponse = $httpResponse->get()->getBody();
794+
}
794795

795-
return $this->_parseXmlResponse($xmlResponse);
796-
}
797-
)
796+
return $this->_parseXmlResponse($xmlResponse);
797+
}
798+
)
799+
]
798800
);
799801
}
800802

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\Async\CallbackDeferred;
11-
use Magento\Framework\Async\ProxyDeferredFactory;
1211
use Magento\Framework\HTTP\AsyncClient\Request;
1312
use Magento\Framework\HTTP\AsyncClientInterface;
1413
use Magento\Framework\Xml\Security;
1514
use Magento\Quote\Model\Quote\Address\RateRequest;
1615
use Magento\Shipping\Helper\Carrier as CarrierHelper;
1716
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
1817
use Magento\Shipping\Model\Rate\Result;
18+
use Magento\Shipping\Model\Rate\Result\ProxyDeferredFactory;
1919
use Magento\Usps\Helper\Data as DataHelper;
2020

2121
/**
@@ -239,16 +239,17 @@ public function collectRates(RateRequest $request)
239239
//Saving current result to use the right one in the callback.
240240
$this->_result = $result = $this->_getQuotes();
241241

242-
return $this->proxyDeferredFactory->createFor(
243-
Result::class,
244-
new CallbackDeferred(
245-
function () use ($request, $result) {
246-
$this->_result = $result;
247-
$this->_updateFreeMethodQuote($request);
242+
return $this->proxyDeferredFactory->create(
243+
[
244+
'deferred' => new CallbackDeferred(
245+
function () use ($request, $result) {
246+
$this->_result = $result;
247+
$this->_updateFreeMethodQuote($request);
248248

249-
return $this->getResult();
250-
}
251-
)
249+
return $this->getResult();
250+
}
251+
)
252+
]
252253
);
253254
}
254255

@@ -555,18 +556,19 @@ protected function _getXmlQuotes()
555556
)
556557
);
557558

558-
return $this->proxyDeferredFactory->createFor(
559-
Result::class,
560-
new CallbackDeferred(
561-
function () use ($deferredResponse, $request, $debugData) {
562-
$responseBody = $deferredResponse->get()->getBody();
563-
$debugData['result'] = $responseBody;
564-
$this->_setCachedQuotes($request, $responseBody);
565-
$this->_debug($debugData);
566-
567-
return $this->_parseXmlResponse($responseBody);
568-
}
569-
)
559+
return $this->proxyDeferredFactory->create(
560+
[
561+
'deferred' => new CallbackDeferred(
562+
function () use ($deferredResponse, $request, $debugData) {
563+
$responseBody = $deferredResponse->get()->getBody();
564+
$debugData['result'] = $responseBody;
565+
$this->_setCachedQuotes($request, $responseBody);
566+
$this->_debug($debugData);
567+
568+
return $this->_parseXmlResponse($responseBody);
569+
}
570+
)
571+
]
570572
);
571573
}
572574

dev/tests/integration/testsuite/Magento/Framework/Async/ProxyDeferredFactoryTest.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class ProxyDeferredFactoryTest extends TestCase
1919
{
2020
/**
21-
* @var ProxyDeferredFactory
21+
* @var \TestDeferred\TestClass\ProxyDeferredFactory
2222
*/
2323
private $factory;
2424

@@ -43,6 +43,7 @@ protected function setUp()
4343
//phpcs:ignore
4444
include_once __DIR__ .'/_files/test_class.php';
4545
\TestDeferred\TestClass::$created = 0;
46+
$this->factory = Bootstrap::getObjectManager()->get(\TestDeferred\TestClass\ProxyDeferredFactory::class);
4647
}
4748

4849
/*
@@ -57,9 +58,10 @@ public function testCreate(): void
5758
return new \TestDeferred\TestClass($value);
5859
};
5960
/** @var \TestDeferred\TestClass $proxy */
60-
$proxy = $this->factory->createFor(
61-
\TestDeferred\TestClass::class,
62-
$this->callbackDeferredFactory->create(['callback' => $callback])
61+
$proxy = $this->factory->create(
62+
[
63+
'deferred' => $this->callbackDeferredFactory->create(['callback' => $callback])
64+
]
6365
);
6466
$this->assertInstanceOf(\TestDeferred\TestClass::class, $proxy);
6567
$this->assertEmpty(\TestDeferred\TestClass::$created);
@@ -80,9 +82,10 @@ public function testSerialize(): void
8082
return new \TestDeferred\TestClass($value);
8183
};
8284
/** @var \TestDeferred\TestClass $proxy */
83-
$proxy = $this->factory->createFor(
84-
\TestDeferred\TestClass::class,
85-
$this->callbackDeferredFactory->create(['callback' => $callback])
85+
$proxy = $this->factory->create(
86+
[
87+
'deferred' => $this->callbackDeferredFactory->create(['callback' => $callback])
88+
]
8689
);
8790
//phpcs:disable
8891
/** @var \TestDeferred\TestClass $unserialized */
@@ -106,9 +109,10 @@ public function testClone(): void
106109
return new \TestDeferred\TestClass($value);
107110
};
108111
/** @var \TestDeferred\TestClass $proxy */
109-
$proxy = $this->factory->createFor(
110-
\TestDeferred\TestClass::class,
111-
$this->callbackDeferredFactory->create(['callback' => $callback])
112+
$proxy = $this->factory->create(
113+
[
114+
'deferred' => $this->callbackDeferredFactory->create(['callback' => $callback])
115+
]
112116
);
113117
$this->assertEquals(0, \TestDeferred\TestClass::$created);
114118
$this->assertEquals(0, $called);
@@ -137,9 +141,10 @@ public function getValue()
137141
};
138142
};
139143
/** @var \TestDeferred\TestClass $proxy */
140-
$proxy = $this->factory->createFor(
141-
\TestDeferred\TestClass::class,
142-
$this->callbackDeferredFactory->create(['callback' => $callback])
144+
$proxy = $this->factory->create(
145+
[
146+
'deferred' => $this->callbackDeferredFactory->create(['callback' => $callback])
147+
]
143148
);
144149
$this->assertInstanceOf(\TestDeferred\TestClass::class, $proxy);
145150
$this->assertEmpty(\TestDeferred\TestClass::$created);

0 commit comments

Comments
 (0)