Example #1
0
 /**
  * Generation Shipment Details Node according to origin region
  *
  * @param \Magento\Shipping\Model\Simplexml\Element $xml
  * @param RateRequest $rawRequest
  * @param string $originRegion
  * @return void
  */
 protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
 {
     $nodeShipmentDetails = $xml->addChild('ShipmentDetails', '', '');
     $nodeShipmentDetails->addChild('NumberOfPieces', count($rawRequest->getPackages()));
     if ($originRegion) {
         $nodeShipmentDetails->addChild('CurrencyCode', $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode());
     }
     $nodePieces = $nodeShipmentDetails->addChild('Pieces', '', '');
     /*
      * Package type
      * EE (DHL Express Envelope), OD (Other DHL Packaging), CP (Custom Packaging)
      * DC (Document), DM (Domestic), ED (Express Document), FR (Freight)
      * BD (Jumbo Document), BP (Jumbo Parcel), JD (Jumbo Junior Document)
      * JP (Jumbo Junior Parcel), PA (Parcel), DF (DHL Flyer)
      */
     $i = 0;
     foreach ($rawRequest->getPackages() as $package) {
         $nodePiece = $nodePieces->addChild('Piece', '', '');
         $packageType = 'EE';
         if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
             $packageType = 'CP';
         }
         $nodePiece->addChild('PieceID', ++$i);
         $nodePiece->addChild('PackageType', $packageType);
         $nodePiece->addChild('Weight', round($package['params']['weight'], 1));
         $params = $package['params'];
         if ($params['width'] && $params['length'] && $params['height']) {
             if (!$originRegion) {
                 $nodePiece->addChild('Width', round($params['width']));
                 $nodePiece->addChild('Height', round($params['height']));
                 $nodePiece->addChild('Depth', round($params['length']));
             } else {
                 $nodePiece->addChild('Depth', round($params['length']));
                 $nodePiece->addChild('Width', round($params['width']));
                 $nodePiece->addChild('Height', round($params['height']));
             }
         }
         $content = array();
         foreach ($package['items'] as $item) {
             $content[] = $item['name'];
         }
         $nodePiece->addChild('PieceContents', substr(implode(',', $content), 0, 34));
     }
     if (!$originRegion) {
         $nodeShipmentDetails->addChild('Weight', round($rawRequest->getPackageWeight(), 1));
         $nodeShipmentDetails->addChild('WeightUnit', substr($this->_getWeightUnit(), 0, 1));
         $nodeShipmentDetails->addChild('GlobalProductCode', $rawRequest->getShippingMethod());
         $nodeShipmentDetails->addChild('LocalProductCode', $rawRequest->getShippingMethod());
         $nodeShipmentDetails->addChild('Date', $this->_coreDate->date('Y-m-d'));
         $nodeShipmentDetails->addChild('Contents', 'DHL Parcel');
         /**
          * The DoorTo Element defines the type of delivery service that applies to the shipment.
          * The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to
          * Door non-compliant)
          */
         $nodeShipmentDetails->addChild('DoorTo', 'DD');
         $nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1));
         if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
             $packageType = 'CP';
         }
         $nodeShipmentDetails->addChild('PackageType', $packageType);
         if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC) {
             $nodeShipmentDetails->addChild('IsDutiable', 'Y');
         }
         $nodeShipmentDetails->addChild('CurrencyCode', $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode());
     } else {
         if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
             $packageType = 'CP';
         }
         $nodeShipmentDetails->addChild('PackageType', $packageType);
         $nodeShipmentDetails->addChild('Weight', $rawRequest->getPackageWeight());
         $nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1));
         $nodeShipmentDetails->addChild('WeightUnit', substr($this->_getWeightUnit(), 0, 1));
         $nodeShipmentDetails->addChild('GlobalProductCode', $rawRequest->getShippingMethod());
         $nodeShipmentDetails->addChild('LocalProductCode', $rawRequest->getShippingMethod());
         /**
          * The DoorTo Element defines the type of delivery service that applies to the shipment.
          * The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to
          * Door non-compliant)
          */
         $nodeShipmentDetails->addChild('DoorTo', 'DD');
         $nodeShipmentDetails->addChild('Date', $this->_coreDate->date('Y-m-d'));
         $nodeShipmentDetails->addChild('Contents', 'DHL Parcel TEST');
     }
 }