Skip to content

Commit d01dab8

Browse files
committed
Merge remote-tracking branch 'gl_magento2ce/AC-7900' into AC-7900_DHL
Unable to create Shipping Label for Dutiable shipments in DHL shipping method
2 parents 51f38b4 + 71c943b commit d01dab8

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ protected function getCountryParams($countryCode)
13981398
*/
13991399
protected function _doShipmentRequest(\Magento\Framework\DataObject $request)
14001400
{
1401+
14011402
$this->_prepareShipmentRequest($request);
14021403
$this->_mapRequestToShipment($request);
14031404
$this->setRequest($request);
@@ -1658,8 +1659,11 @@ protected function _doRequest()
16581659
$baseCurrencyCode = $this->_storeManager->getWebsite($rawRequest->getWebsiteId())->getBaseCurrencyCode();
16591660
$nodeDutiable->addChild('DeclaredCurrency', $baseCurrencyCode);
16601661
$nodeDutiable->addChild('TermsOfTrade', 'DAP');
1661-
}
16621662

1663+
/** Export Declaration */
1664+
$this->addExportDeclaration($xml, $rawRequest);
1665+
1666+
}
16631667
/**
16641668
* Reference
16651669
* This element identifies the reference information. It is an optional field in the
@@ -2183,4 +2187,65 @@ private function getGatewayURL(): string
21832187
return (string)$this->getConfigData('gateway_url');
21842188
}
21852189
}
2190+
2191+
/**
2192+
* Generating Export Declaration Details
2193+
*
2194+
* @param \Magento\Shipping\Model\Simplexml\Element $xml
2195+
* @param RateRequest $rawRequest
2196+
* @return void
2197+
*/
2198+
private function addExportDeclaration($xml, $rawRequest)
2199+
{
2200+
$nodeExportDeclaration = $xml->addChild('ExportDeclaration', '', '');
2201+
$nodeExportDeclaration->addChild(
2202+
'InvoiceNumber',
2203+
$rawRequest->getOrderShipment()->getOrder()->hasInvoices() ?
2204+
$this->getInvoiceNumbers($rawRequest) :
2205+
$rawRequest->getOrderShipment()->getOrder()->getIncrementId()
2206+
);
2207+
$nodeExportDeclaration->addChild('InvoiceDate', date(
2208+
"Y-m-d",
2209+
strtotime($rawRequest->getOrderShipment()->getOrder()->getCreatedAt())
2210+
));
2211+
$exportItems = $rawRequest->getPackages();
2212+
foreach ($exportItems as $exportItem) {
2213+
$itemWeightUnit = $exportItem['params']['weight_units'] ? substr(
2214+
$exportItem['params']['weight_units'],
2215+
0,
2216+
1
2217+
) : 'L';
2218+
foreach ($exportItem['items'] as $itemNo => $itemData) {
2219+
$nodeExportItem = $nodeExportDeclaration->addChild('ExportLineItem', '', '');
2220+
$nodeExportItem->addChild('LineNumber', $itemNo);
2221+
$nodeExportItem->addChild('Quantity', $itemData['qty']);
2222+
$nodeExportItem->addChild('QuantityUnit', 'PCS');
2223+
$nodeExportItem->addChild('Description', $itemData['name']);
2224+
$nodeExportItem->addChild('Value', $itemData['price']);
2225+
$nodeItemWeight = $nodeExportItem->addChild('Weight', '', '');
2226+
$nodeItemWeight->addChild('Weight', $itemData['weight']);
2227+
$nodeItemWeight->addChild('WeightUnit', $itemWeightUnit);
2228+
$nodeItemGrossWeight = $nodeExportItem->addChild('GrossWeight');
2229+
$nodeItemGrossWeight->addChild('Weight', $itemData['weight']);
2230+
$nodeItemGrossWeight->addChild('WeightUnit', $itemWeightUnit);
2231+
$nodeExportItem->addChild('ManufactureCountryCode', $rawRequest->getShipperAddressCountryCode());
2232+
}
2233+
}
2234+
}
2235+
2236+
/**
2237+
* Fetching Shipment Order Invoice No
2238+
*
2239+
* @param RateRequest $rawRequest
2240+
* @return string
2241+
*/
2242+
private function getInvoiceNumbers($rawRequest)
2243+
{
2244+
$invoiceNumbers = [];
2245+
$order = $rawRequest->getOrderShipment()->getOrder();
2246+
foreach ($order->getInvoiceCollection() as $invoice) {
2247+
$invoiceNumbers[] = $invoice->getIncrementId();
2248+
}
2249+
return implode(',', $invoiceNumbers);
2250+
}
21862251
}

0 commit comments

Comments
 (0)