Skip to content

Fix wrong format error DHL shipping label #31021

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

Merged
merged 16 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<argument name="address" value="US_Address_TX"/>
</actionGroup>

<!-- Select Free Shipping -->
<actionGroup ref="StorefrontSetShippingMethodActionGroup" stepKey="setShippingMethodFreeShipping">
<argument name="shippingMethodName" value="Free Shipping"/>
</actionGroup>

<!-- Assert Free Shipping checkbox -->
<seeCheckboxIsChecked selector="{{CheckoutShippingMethodsSection.shippingMethodFreeShipping}}" stepKey="freeShippingMethodCheckboxIsChecked"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="selectViewAndEditCart"/>

<!--Assert Shopping Cart Summary-->
<actionGroup ref="AssertStorefrontShoppingCartSummaryWithShippingActionGroup" stepKey="AssertCartSummary" >
<actionGroup ref="StorefrontCheckCartActionGroup" stepKey="AssertCartSummary" >
<argument name="subtotal" value="$100.00"/>
<argument name="shipping" value="10.00"/>
<argument name="total" value="110.00"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="selectViewAndEditCart"/>

<!--Assert Shopping Cart Summary-->
<actionGroup ref="AssertStorefrontShoppingCartSummaryWithShippingActionGroup" stepKey="AssertCartSummary" >
<actionGroup ref="StorefrontCheckCartActionGroup" stepKey="AssertCartSummary" >
<argument name="subtotal" value="$50.00"/>
<argument name="shipping" value="5.00"/>
<argument name="total" value="55.00"/>
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Dhl/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
foreach ($package['items'] as $item) {
$content[] = $item['name'];
}
$nodePiece->addChild('PieceContents', substr(implode(',', $content), 0, 34));
$nodePiece->addChild('PieceContents', $this->string->substr(implode(',', $content), 0, 34));
}

$nodeShipmentDetails->addChild('Weight', sprintf('%.3f', $rawRequest->getPackageWeight()));
Expand All @@ -1776,7 +1776,7 @@ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
$nodeShipmentDetails->addChild('DoorTo', 'DD');
$nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1));
$contentType = isset($package['params']['container']) ? $package['params']['container'] : '';
$packageType = $contentType === self::DHL_CONTENT_TYPE_NON_DOC ? 'CP' : '';
$packageType = $contentType === self::DHL_CONTENT_TYPE_NON_DOC ? 'CP' : 'EE';
$nodeShipmentDetails->addChild('PackageType', $packageType);
if ($this->isDutiable($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId())) {
$nodeShipmentDetails->addChild('IsDutiable', 'Y');
Expand Down
45 changes: 35 additions & 10 deletions dev/tests/integration/testsuite/Magento/Dhl/Model/CarrierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@
use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Quote\Model\Quote\Address\RateResult\Error;
use Magento\Shipping\Model\Shipment\Request;
use Magento\Shipping\Model\Simplexml\Element as ShippingElement;
use Magento\Shipping\Model\Tracking\Result\Status;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\HTTP\AsyncClientInterfaceMock;
use Magento\Shipping\Model\Simplexml\Element as ShippingElement;
use PHPUnit\Framework\TestCase;

/**
* Test for DHL integration.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CarrierTest extends \PHPUnit\Framework\TestCase
class CarrierTest extends TestCase
{
private const PRODUCT_NAME_SPECIAL_CHARS = 'Φυστίκι Ψημένο με Αλάτι Συσκευασία';

/**
* @var Carrier
*/
Expand Down Expand Up @@ -254,10 +257,16 @@ private function assertTrackingResult($expectedTrackingData, $trackingResults):
* @param string $origCountryId
* @param string $expectedRegionCode
* @param string $destCountryId
* @param bool|null $isProductNameContainsSpecialChars
* @return void
* @dataProvider requestToShipmentDataProvider
*/
public function testRequestToShip(string $origCountryId, string $expectedRegionCode, string $destCountryId): void
{
public function testRequestToShip(
string $origCountryId,
string $expectedRegionCode,
string $destCountryId,
bool $isProductNameContainsSpecialChars = false
): void {
$this->config->setValue(
'shipping/origin/country_id',
$origCountryId,
Expand All @@ -274,6 +283,8 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
)
]
);
$productName = $isProductNameContainsSpecialChars ? self::PRODUCT_NAME_SPECIAL_CHARS : 'item_name';

//phpcs:enable Magento2.Functions.DiscouragedFunction
$request = new Request(
[
Expand All @@ -291,7 +302,7 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
],
'items' => [
'item1' => [
'name' => 'item_name',
'name' => $productName,
],
],
],
Expand Down Expand Up @@ -329,10 +340,15 @@ public function testRequestToShip(string $origCountryId, string $expectedRegionC
$requestElement->Request->ServiceHeader->MessageReference = 'MAGE_SHIP_28TO32_Char_CHECKED';
$requestElement->Request->ServiceHeader->MessageTime = 'currentTime';
$requestElement->ShipmentDetails->Date = 'currentTime';
$this->assertXmlStringEqualsXmlString(
$this->getExpectedLabelRequestXml($origCountryId, $destCountryId, $expectedRegionCode),
$requestElement->asXML()

$expectedLabelRequest = $this->getExpectedLabelRequestXml(
$origCountryId,
$destCountryId,
$expectedRegionCode,
$isProductNameContainsSpecialChars
);

$this->assertXmlStringEqualsXmlString($expectedLabelRequest, $requestElement->asXML());
}

/**
Expand All @@ -351,7 +367,10 @@ public function requestToShipmentDataProvider(): array
],
[
'DE', 'EU', 'DE'
]
],
[
'GB', 'EU', 'US', true
],
];
}

Expand All @@ -361,12 +380,14 @@ public function requestToShipmentDataProvider(): array
* @param string $origCountryId
* @param string $destCountryId
* @param string $regionCode
* @param bool $isProductNameContainsSpecialChars
* @return string
*/
private function getExpectedLabelRequestXml(
string $origCountryId,
string $destCountryId,
string $regionCode
string $regionCode,
bool $isProductNameContainsSpecialChars
): string {
$countryNames = [
'US' => 'United States Of America',
Expand All @@ -387,6 +408,10 @@ private function getExpectedLabelRequestXml(
$expectedRequestElement->Shipper->CountryName = $countryNames[$origCountryId];
$expectedRequestElement->RegionCode = $regionCode;

if ($isProductNameContainsSpecialChars) {
$expectedRequestElement->ShipmentDetails->Pieces->Piece->PieceContents = self::PRODUCT_NAME_SPECIAL_CHARS;
}

return $expectedRequestElement->asXML();
}

Expand Down