7
7
namespace Magento \Dhl \Model ;
8
8
9
9
use Magento \Catalog \Model \Product \Type ;
10
+ use Magento \Framework \App \ProductMetadataInterface ;
10
11
use Magento \Framework \Module \Dir ;
11
12
use Magento \Sales \Exception \DocumentValidationException ;
12
13
use Magento \Sales \Model \Order \Shipment ;
@@ -213,6 +214,11 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin
213
214
*/
214
215
private $ xmlValidator ;
215
216
217
+ /**
218
+ * @var ProductMetadataInterface
219
+ */
220
+ private $ productMetadata ;
221
+
216
222
/**
217
223
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
218
224
* @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory
@@ -239,7 +245,8 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin
239
245
* @param \Magento\Framework\Stdlib\DateTime $dateTime
240
246
* @param \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory
241
247
* @param array $data
242
- * @param \Magento\Dhl\Model\Validator\XmlValidator $xmlValidator
248
+ * @param \Magento\Dhl\Model\Validator\XmlValidator|null $xmlValidator
249
+ * @param ProductMetadataInterface|null $productMetadata
243
250
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
244
251
*/
245
252
public function __construct (
@@ -268,7 +275,8 @@ public function __construct(
268
275
\Magento \Framework \Stdlib \DateTime $ dateTime ,
269
276
\Magento \Framework \HTTP \ZendClientFactory $ httpClientFactory ,
270
277
array $ data = [],
271
- \Magento \Dhl \Model \Validator \XmlValidator $ xmlValidator = null
278
+ \Magento \Dhl \Model \Validator \XmlValidator $ xmlValidator = null ,
279
+ ProductMetadataInterface $ productMetadata = null
272
280
) {
273
281
$ this ->readFactory = $ readFactory ;
274
282
$ this ->_carrierHelper = $ carrierHelper ;
@@ -302,6 +310,8 @@ public function __construct(
302
310
}
303
311
$ this ->xmlValidator = $ xmlValidator
304
312
?: \Magento \Framework \App \ObjectManager::getInstance ()->get (XmlValidator::class);
313
+ $ this ->productMetadata = $ productMetadata
314
+ ?: \Magento \Framework \App \ObjectManager::getInstance ()->get (ProductMetadataInterface::class);
305
315
}
306
316
307
317
/**
@@ -1393,44 +1403,41 @@ protected function _doRequest()
1393
1403
{
1394
1404
$ rawRequest = $ this ->_request ;
1395
1405
1396
- $ originRegion = $ this ->getCountryParams (
1397
- $ this ->_scopeConfig ->getValue (
1398
- Shipment::XML_PATH_STORE_COUNTRY_ID ,
1399
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
1400
- $ this ->getStore ()
1401
- )
1402
- )->getRegion ();
1403
-
1404
- if (!$ originRegion ) {
1405
- throw new \Magento \Framework \Exception \LocalizedException (__ ('Wrong Region ' ));
1406
- }
1407
-
1408
- if ($ originRegion == 'AM ' ) {
1409
- $ originRegion = '' ;
1410
- }
1411
-
1412
1406
$ xmlStr = '<?xml version="1.0" encoding="UTF-8"?> ' .
1413
- '<req:ShipmentValidateRequest ' .
1414
- $ originRegion .
1407
+ '<req:ShipmentRequest ' .
1415
1408
' xmlns:req="http://www.dhl.com" ' .
1416
1409
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' .
1417
- ' xsi:schemaLocation="http://www.dhl.com ship-val-req ' .
1418
- ($ originRegion ? '_ ' .
1419
- $ originRegion : '' ) .
1420
- '.xsd" /> ' ;
1410
+ ' xsi:schemaLocation="http://www.dhl.com ship-val-global-req-6.2.xsd" ' .
1411
+ ' schemaVersion="6.2" /> ' ;
1421
1412
$ xml = $ this ->_xmlElFactory ->create (['data ' => $ xmlStr ]);
1422
1413
1423
1414
$ nodeRequest = $ xml ->addChild ('Request ' , '' , '' );
1424
1415
$ nodeServiceHeader = $ nodeRequest ->addChild ('ServiceHeader ' );
1416
+ $ nodeServiceHeader ->addChild ('MessageTime ' , $ this ->buildMessageTimestamp ());
1417
+ // MessageReference must be 28 to 32 chars.
1418
+ $ nodeServiceHeader ->addChild (
1419
+ 'MessageReference ' ,
1420
+ $ this ->buildMessageReference (self ::SERVICE_PREFIX_SHIPVAL )
1421
+ );
1425
1422
$ nodeServiceHeader ->addChild ('SiteID ' , (string )$ this ->getConfigData ('id ' ));
1426
1423
$ nodeServiceHeader ->addChild ('Password ' , (string )$ this ->getConfigData ('password ' ));
1427
1424
1428
- if (!$ originRegion ) {
1429
- $ xml ->addChild ('RequestedPickupTime ' , 'N ' , '' );
1430
- }
1431
- if ($ originRegion !== 'AP ' ) {
1432
- $ xml ->addChild ('NewShipper ' , 'N ' , '' );
1425
+ $ nodeMetaData = $ nodeRequest ->addChild ('MetaData ' );
1426
+ $ nodeMetaData ->addChild ('SoftwareName ' , $ this ->productMetadata ->getName ());
1427
+ $ nodeMetaData ->addChild ('SoftwareVersion ' , $ this ->productMetadata ->getVersion ());
1428
+
1429
+ $ originRegion = $ this ->getCountryParams (
1430
+ $ this ->_scopeConfig ->getValue (
1431
+ Shipment::XML_PATH_STORE_COUNTRY_ID ,
1432
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
1433
+ $ this ->getStore ()
1434
+ )
1435
+ )->getRegion ();
1436
+ if ($ originRegion ) {
1437
+ $ xml ->addChild ('RegionCode ' , $ originRegion , '' );
1433
1438
}
1439
+ $ xml ->addChild ('RequestedPickupTime ' , 'N ' , '' );
1440
+ $ xml ->addChild ('NewShipper ' , 'N ' , '' );
1434
1441
$ xml ->addChild ('LanguageCode ' , 'EN ' , '' );
1435
1442
$ xml ->addChild ('PiecesEnabled ' , 'Y ' , '' );
1436
1443
@@ -1472,8 +1479,9 @@ protected function _doRequest()
1472
1479
}
1473
1480
1474
1481
$ nodeConsignee ->addChild ('City ' , $ rawRequest ->getRecipientAddressCity ());
1475
- if ($ originRegion !== 'AP ' ) {
1476
- $ nodeConsignee ->addChild ('Division ' , $ rawRequest ->getRecipientAddressStateOrProvinceCode ());
1482
+ $ recipientAddressStateOrProvinceCode = $ rawRequest ->getRecipientAddressStateOrProvinceCode ();
1483
+ if ($ recipientAddressStateOrProvinceCode ) {
1484
+ $ nodeConsignee ->addChild ('Division ' , $ recipientAddressStateOrProvinceCode );
1477
1485
}
1478
1486
$ nodeConsignee ->addChild ('PostalCode ' , $ rawRequest ->getRecipientAddressPostalCode ());
1479
1487
$ nodeConsignee ->addChild ('CountryCode ' , $ rawRequest ->getRecipientAddressCountryCode ());
@@ -1517,15 +1525,13 @@ protected function _doRequest()
1517
1525
$ nodeReference ->addChild ('ReferenceType ' , 'St ' );
1518
1526
1519
1527
/** Shipment Details */
1520
- $ this ->_shipmentDetails ($ xml , $ rawRequest, $ originRegion );
1528
+ $ this ->_shipmentDetails ($ xml , $ rawRequest );
1521
1529
1522
1530
/** Shipper */
1523
1531
$ nodeShipper = $ xml ->addChild ('Shipper ' , '' , '' );
1524
1532
$ nodeShipper ->addChild ('ShipperID ' , (string )$ this ->getConfigData ('account ' ));
1525
1533
$ nodeShipper ->addChild ('CompanyName ' , $ rawRequest ->getShipperContactCompanyName ());
1526
- if ($ originRegion !== 'AP ' ) {
1527
- $ nodeShipper ->addChild ('RegisteredAccount ' , (string )$ this ->getConfigData ('account ' ));
1528
- }
1534
+ $ nodeShipper ->addChild ('RegisteredAccount ' , (string )$ this ->getConfigData ('account ' ));
1529
1535
1530
1536
$ address = $ rawRequest ->getShipperAddressStreet1 () . ' ' . $ rawRequest ->getShipperAddressStreet2 ();
1531
1537
$ address = $ this ->string ->split ($ address , 35 , false , true );
@@ -1538,8 +1544,9 @@ protected function _doRequest()
1538
1544
}
1539
1545
1540
1546
$ nodeShipper ->addChild ('City ' , $ rawRequest ->getShipperAddressCity ());
1541
- if ($ originRegion !== 'AP ' ) {
1542
- $ nodeShipper ->addChild ('Division ' , $ rawRequest ->getShipperAddressStateOrProvinceCode ());
1547
+ $ shipperAddressStateOrProvinceCode = $ rawRequest ->getShipperAddressStateOrProvinceCode ();
1548
+ if ($ shipperAddressStateOrProvinceCode ) {
1549
+ $ nodeShipper ->addChild ('Division ' , $ shipperAddressStateOrProvinceCode );
1543
1550
}
1544
1551
$ nodeShipper ->addChild ('PostalCode ' , $ rawRequest ->getShipperAddressPostalCode ());
1545
1552
$ nodeShipper ->addChild ('CountryCode ' , $ rawRequest ->getShipperAddressCountryCode ());
@@ -1597,13 +1604,6 @@ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
1597
1604
$ nodeShipmentDetails = $ xml ->addChild ('ShipmentDetails ' , '' , '' );
1598
1605
$ nodeShipmentDetails ->addChild ('NumberOfPieces ' , count ($ rawRequest ->getPackages ()));
1599
1606
1600
- if ($ originRegion ) {
1601
- $ nodeShipmentDetails ->addChild (
1602
- 'CurrencyCode ' ,
1603
- $ this ->_storeManager ->getWebsite ($ this ->_request ->getWebsiteId ())->getBaseCurrencyCode ()
1604
- );
1605
- }
1606
-
1607
1607
$ nodePieces = $ nodeShipmentDetails ->addChild ('Pieces ' , '' , '' );
1608
1608
1609
1609
/*
@@ -1622,18 +1622,12 @@ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
1622
1622
}
1623
1623
$ nodePiece ->addChild ('PieceID ' , ++$ i );
1624
1624
$ nodePiece ->addChild ('PackageType ' , $ packageType );
1625
- $ nodePiece ->addChild ('Weight ' , sprintf ('%.1f ' , $ package ['params ' ]['weight ' ]));
1625
+ $ nodePiece ->addChild ('Weight ' , sprintf ('%.3f ' , $ package ['params ' ]['weight ' ]));
1626
1626
$ params = $ package ['params ' ];
1627
1627
if ($ params ['width ' ] && $ params ['length ' ] && $ params ['height ' ]) {
1628
- if (!$ originRegion ) {
1629
- $ nodePiece ->addChild ('Width ' , round ($ params ['width ' ]));
1630
- $ nodePiece ->addChild ('Height ' , round ($ params ['height ' ]));
1631
- $ nodePiece ->addChild ('Depth ' , round ($ params ['length ' ]));
1632
- } else {
1633
- $ nodePiece ->addChild ('Depth ' , round ($ params ['length ' ]));
1634
- $ nodePiece ->addChild ('Width ' , round ($ params ['width ' ]));
1635
- $ nodePiece ->addChild ('Height ' , round ($ params ['height ' ]));
1636
- }
1628
+ $ nodePiece ->addChild ('Width ' , round ($ params ['width ' ]));
1629
+ $ nodePiece ->addChild ('Height ' , round ($ params ['height ' ]));
1630
+ $ nodePiece ->addChild ('Depth ' , round ($ params ['length ' ]));
1637
1631
}
1638
1632
$ content = [];
1639
1633
foreach ($ package ['items ' ] as $ item ) {
@@ -1642,51 +1636,33 @@ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
1642
1636
$ nodePiece ->addChild ('PieceContents ' , substr (implode (', ' , $ content ), 0 , 34 ));
1643
1637
}
1644
1638
1645
- if (!$ originRegion ) {
1646
- $ nodeShipmentDetails ->addChild ('Weight ' , sprintf ('%.1f ' , $ rawRequest ->getPackageWeight ()));
1647
- $ nodeShipmentDetails ->addChild ('WeightUnit ' , substr ($ this ->_getWeightUnit (), 0 , 1 ));
1648
- $ nodeShipmentDetails ->addChild ('GlobalProductCode ' , $ rawRequest ->getShippingMethod ());
1649
- $ nodeShipmentDetails ->addChild ('LocalProductCode ' , $ rawRequest ->getShippingMethod ());
1650
- $ nodeShipmentDetails ->addChild ('Date ' , $ this ->_coreDate ->date ('Y-m-d ' ));
1651
- $ nodeShipmentDetails ->addChild ('Contents ' , 'DHL Parcel ' );
1652
- /**
1653
- * The DoorTo Element defines the type of delivery service that applies to the shipment.
1654
- * The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to
1655
- * Door non-compliant)
1656
- */
1657
- $ nodeShipmentDetails ->addChild ('DoorTo ' , 'DD ' );
1658
- $ nodeShipmentDetails ->addChild ('DimensionUnit ' , substr ($ this ->_getDimensionUnit (), 0 , 1 ));
1659
- if ($ package ['params ' ]['container ' ] == self ::DHL_CONTENT_TYPE_NON_DOC ) {
1660
- $ packageType = 'CP ' ;
1661
- }
1662
- $ nodeShipmentDetails ->addChild ('PackageType ' , $ packageType );
1663
- if ($ this ->isDutiable ($ rawRequest ->getOrigCountryId (), $ rawRequest ->getDestCountryId ())) {
1664
- $ nodeShipmentDetails ->addChild ('IsDutiable ' , 'Y ' );
1665
- }
1666
- $ nodeShipmentDetails ->addChild (
1667
- 'CurrencyCode ' ,
1668
- $ this ->_storeManager ->getWebsite ($ this ->_request ->getWebsiteId ())->getBaseCurrencyCode ()
1669
- );
1670
- } else {
1671
- if ($ package ['params ' ]['container ' ] == self ::DHL_CONTENT_TYPE_NON_DOC ) {
1672
- $ packageType = 'CP ' ;
1673
- }
1674
- $ nodeShipmentDetails ->addChild ('PackageType ' , $ packageType );
1675
- $ nodeShipmentDetails ->addChild ('Weight ' , sprintf ('%.3f ' , $ rawRequest ->getPackageWeight ()));
1676
- $ nodeShipmentDetails ->addChild ('DimensionUnit ' , substr ($ this ->_getDimensionUnit (), 0 , 1 ));
1677
- $ nodeShipmentDetails ->addChild ('WeightUnit ' , substr ($ this ->_getWeightUnit (), 0 , 1 ));
1678
- $ nodeShipmentDetails ->addChild ('GlobalProductCode ' , $ rawRequest ->getShippingMethod ());
1679
- $ nodeShipmentDetails ->addChild ('LocalProductCode ' , $ rawRequest ->getShippingMethod ());
1680
-
1681
- /**
1682
- * The DoorTo Element defines the type of delivery service that applies to the shipment.
1683
- * The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to
1684
- * Door non-compliant)
1685
- */
1686
- $ nodeShipmentDetails ->addChild ('DoorTo ' , 'DD ' );
1687
- $ nodeShipmentDetails ->addChild ('Date ' , $ this ->_coreDate ->date ('Y-m-d ' ));
1688
- $ nodeShipmentDetails ->addChild ('Contents ' , 'DHL Parcel TEST ' );
1639
+ $ nodeShipmentDetails ->addChild ('Weight ' , sprintf ('%.3f ' , $ rawRequest ->getPackageWeight ()));
1640
+ $ nodeShipmentDetails ->addChild ('WeightUnit ' , substr ($ this ->_getWeightUnit (), 0 , 1 ));
1641
+ $ nodeShipmentDetails ->addChild ('GlobalProductCode ' , $ rawRequest ->getShippingMethod ());
1642
+ $ nodeShipmentDetails ->addChild ('LocalProductCode ' , $ rawRequest ->getShippingMethod ());
1643
+ $ nodeShipmentDetails ->addChild (
1644
+ 'Date ' ,
1645
+ $ this ->_coreDate ->date ('Y-m-d ' , strtotime ('now + 1day ' ))
1646
+ );
1647
+ $ nodeShipmentDetails ->addChild ('Contents ' , 'DHL Parcel ' );
1648
+ /**
1649
+ * The DoorTo Element defines the type of delivery service that applies to the shipment.
1650
+ * The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to
1651
+ * Door non-compliant)
1652
+ */
1653
+ $ nodeShipmentDetails ->addChild ('DoorTo ' , 'DD ' );
1654
+ $ nodeShipmentDetails ->addChild ('DimensionUnit ' , substr ($ this ->_getDimensionUnit (), 0 , 1 ));
1655
+ if ($ package ['params ' ]['container ' ] == self ::DHL_CONTENT_TYPE_NON_DOC ) {
1656
+ $ packageType = 'CP ' ;
1689
1657
}
1658
+ $ nodeShipmentDetails ->addChild ('PackageType ' , $ packageType );
1659
+ if ($ this ->isDutiable ($ rawRequest ->getOrigCountryId (), $ rawRequest ->getDestCountryId ())) {
1660
+ $ nodeShipmentDetails ->addChild ('IsDutiable ' , 'Y ' );
1661
+ }
1662
+ $ nodeShipmentDetails ->addChild (
1663
+ 'CurrencyCode ' ,
1664
+ $ this ->_storeManager ->getWebsite ($ this ->_request ->getWebsiteId ())->getBaseCurrencyCode ()
1665
+ );
1690
1666
}
1691
1667
1692
1668
/**
0 commit comments