Skip to content

Commit aff1ce0

Browse files
committed
MC-23093: The initial option value for DHL is incorrect
1 parent 6da226d commit aff1ce0

File tree

3 files changed

+103
-33
lines changed

3 files changed

+103
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected function _getDimension($dimension, $configWeightUnit = false)
940940
);
941941
}
942942

943-
return sprintf('%.3f', $dimension);
943+
return round($dimension, 3);
944944
}
945945

946946
/**

app/code/Magento/Dhl/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
3333
<divide_order_weight>1</divide_order_weight>
3434
<unit_of_measure>K</unit_of_measure>
35-
<size>R</size>
35+
<size>0</size>
3636
<handling_type>F</handling_type>
3737
<handling_action>O</handling_action>
3838
<shipment_days>Mon,Tue,Wed,Thu,Fri</shipment_days>

dev/tests/integration/testsuite/Magento/Dhl/Model/CarrierTest.php

Lines changed: 101 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Quote\Model\Quote\Address\RateRequest;
1616
use Magento\Shipping\Model\Shipment\Request;
1717
use Magento\Shipping\Model\Tracking\Result\Status;
18+
use Magento\Store\Model\ScopeInterface;
1819
use Magento\TestFramework\Helper\Bootstrap;
1920
use Magento\TestFramework\HTTP\AsyncClientInterfaceMock;
2021
use Magento\Shipping\Model\Simplexml\Element as ShippingElement;
@@ -411,7 +412,106 @@ private function getExpectedLabelRequestXml(
411412
*/
412413
public function testCollectRates()
413414
{
414-
$requestData = [
415+
$requestData = $this->getRequestData();
416+
//phpcs:disable Magento2.Functions.DiscouragedFunction
417+
$response = new Response(
418+
200,
419+
[],
420+
file_get_contents(__DIR__ . '/../_files/dhl_quote_response.xml')
421+
);
422+
//phpcs:enable Magento2.Functions.DiscouragedFunction
423+
$this->httpClient->nextResponses(array_fill(0, Carrier::UNAVAILABLE_DATE_LOOK_FORWARD + 1, $response));
424+
/** @var RateRequest $request */
425+
$request = Bootstrap::getObjectManager()->create(RateRequest::class, $requestData);
426+
$expectedRates = [
427+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 45.85, 'method' => 'E', 'price' => 45.85],
428+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'Q', 'price' => 35.26],
429+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 37.38, 'method' => 'Y', 'price' => 37.38],
430+
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'P', 'price' => 35.26]
431+
];
432+
433+
$actualRates = $this->dhlCarrier->collectRates($request)->getAllRates();
434+
435+
self::assertEquals(count($expectedRates), count($actualRates));
436+
foreach ($actualRates as $i => $actualRate) {
437+
$actualRate = $actualRate->getData();
438+
unset($actualRate['method_title']);
439+
self::assertEquals($expectedRates[$i], $actualRate);
440+
}
441+
$requestXml = $this->httpClient->getLastRequest()->getBody();
442+
self::assertContains('<Weight>18.223</Weight>', $requestXml);
443+
self::assertContains('<Height>0.63</Height>', $requestXml);
444+
self::assertContains('<Width>0.63</Width>', $requestXml);
445+
self::assertContains('<Depth>0.63</Depth>', $requestXml);
446+
}
447+
448+
/**
449+
* Tests that quotes request doesn't contain dimensions when it shouldn't.
450+
*
451+
* @param string|null $size
452+
* @param string|null $height
453+
* @param string|null $width
454+
* @param string|null $depth
455+
* @magentoConfigFixture default_store carriers/dhl/active 1
456+
* @dataProvider collectRatesWithoutDimensionsDataProvider
457+
*/
458+
public function testCollectRatesWithoutDimensions(?string $size, ?string $height, ?string $width, ?string $depth)
459+
{
460+
$requestData = $this->getRequestData();
461+
$this->setDhlConfig(['size' => $size, 'height' => $height, 'width' => $width, 'depth' => $depth]);
462+
463+
/** @var RateRequest $request */
464+
$request = Bootstrap::getObjectManager()->create(RateRequest::class, $requestData);
465+
$this->dhlCarrier = Bootstrap::getObjectManager()->create(Carrier::class);
466+
$this->dhlCarrier->collectRates($request)->getAllRates();
467+
468+
$requestXml = $this->httpClient->getLastRequest()->getBody();
469+
$this->assertNotContains('<Width>', $requestXml);
470+
$this->assertNotContains('<Height>', $requestXml);
471+
$this->assertNotContains('<Depth>', $requestXml);
472+
}
473+
474+
/**
475+
* @return array
476+
*/
477+
public function collectRatesWithoutDimensionsDataProvider()
478+
{
479+
return [
480+
['size' => '0', 'height' => '1.1', 'width' => '0.6', 'depth' => '0.7'],
481+
['size' => '1', 'height' => '', 'width' => '', 'depth' => ''],
482+
['size' => null, 'height' => '1.1', 'width' => '0.6', 'depth' => '0.7'],
483+
['size' => '1', 'height' => '1', 'width' => '', 'depth' => ''],
484+
['size' => null, 'height' => null, 'width' => null, 'depth' => null],
485+
];
486+
}
487+
488+
/**
489+
* Sets DHL config value.
490+
*
491+
* @param array $params
492+
* @return void
493+
*/
494+
private function setDhlConfig(array $params)
495+
{
496+
foreach ($params as $name => $val) {
497+
if ($val !== null) {
498+
$this->config->setValue(
499+
'carriers/dhl/' . $name,
500+
$val,
501+
ScopeInterface::SCOPE_STORE
502+
);
503+
}
504+
}
505+
}
506+
507+
/**
508+
* Returns request data.
509+
*
510+
* @return array
511+
*/
512+
private function getRequestData(): array
513+
{
514+
return [
415515
'data' => [
416516
'dest_country_id' => 'DE',
417517
'dest_region_id' => '82',
@@ -454,35 +554,5 @@ public function testCollectRates()
454554
'all_items' => [],
455555
]
456556
];
457-
//phpcs:disable Magento2.Functions.DiscouragedFunction
458-
$response = new Response(
459-
200,
460-
[],
461-
file_get_contents(__DIR__ . '/../_files/dhl_quote_response.xml')
462-
);
463-
//phpcs:enable Magento2.Functions.DiscouragedFunction
464-
$this->httpClient->nextResponses(array_fill(0, Carrier::UNAVAILABLE_DATE_LOOK_FORWARD + 1, $response));
465-
/** @var RateRequest $request */
466-
$request = Bootstrap::getObjectManager()->create(RateRequest::class, $requestData);
467-
$expectedRates = [
468-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 45.85, 'method' => 'E', 'price' => 45.85],
469-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'Q', 'price' => 35.26],
470-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 37.38, 'method' => 'Y', 'price' => 37.38],
471-
['carrier' => 'dhl', 'carrier_title' => 'DHL Title', 'cost' => 35.26, 'method' => 'P', 'price' => 35.26]
472-
];
473-
474-
$actualRates = $this->dhlCarrier->collectRates($request)->getAllRates();
475-
476-
self::assertEquals(count($expectedRates), count($actualRates));
477-
foreach ($actualRates as $i => $actualRate) {
478-
$actualRate = $actualRate->getData();
479-
unset($actualRate['method_title']);
480-
self::assertEquals($expectedRates[$i], $actualRate);
481-
}
482-
$requestXml = $this->httpClient->getLastRequest()->getBody();
483-
self::assertContains('<Weight>18.223</Weight>', $requestXml);
484-
self::assertContains('<Height>0.630</Height>', $requestXml);
485-
self::assertContains('<Width>0.630</Width>', $requestXml);
486-
self::assertContains('<Depth>0.630</Depth>', $requestXml);
487557
}
488558
}

0 commit comments

Comments
 (0)