Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Carrier Class Reference
Inheritance diagram for Carrier:
AbstractDhl CarrierInterface AbstractCarrierOnline AbstractCarrier DataObject AbstractCarrierInterface

Public Member Functions

 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, Security $xmlSecurity, \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, \Magento\Shipping\Helper\Carrier $carrierHelper, \Magento\Framework\Stdlib\DateTime\DateTime $coreDate, \Magento\Framework\Module\Dir\Reader $configReader, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Math\Division $mathDivision, \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory, array $data=[], \Magento\Dhl\Model\Validator\XmlValidator $xmlValidator=null)
 
 collectRates (RateRequest $request)
 
 getResult ()
 
 setRequest (\Magento\Framework\DataObject $request)
 
 getAllowedMethods ()
 
 getCode ($type, $code='')
 
 getDhlProducts ($doc)
 
 getDhlProductTitle ($code)
 
 proccessAdditionalValidation (\Magento\Framework\DataObject $request)
 
 processAdditionalValidation (\Magento\Framework\DataObject $request)
 
 getContainerTypes (\Magento\Framework\DataObject $params=null)
 
 getTracking ($trackings)
 
 requestToShipment ($request)
 
- Public Member Functions inherited from AbstractCarrierOnline
 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, Security $xmlSecurity, \Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory, \Magento\Shipping\Model\Rate\ResultFactory $rateFactory, \Magento\Quote\Model\Quote\Address\RateResult\MethodFactory $rateMethodFactory, \Magento\Shipping\Model\Tracking\ResultFactory $trackFactory, \Magento\Shipping\Model\Tracking\Result\ErrorFactory $trackErrorFactory, \Magento\Shipping\Model\Tracking\Result\StatusFactory $trackStatusFactory, \Magento\Directory\Model\RegionFactory $regionFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Directory\Helper\Data $directoryData, \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry, array $data=[])
 
 setActiveFlag ($code='active')
 
 getCarrierCode ()
 
 getTrackingInfo ($tracking)
 
 isTrackingAvailable ()
 
 isCityRequired ()
 
 isZipCodeRequired ($countryId=null)
 
 isShippingLabelsAvailable ()
 
 getAllItems (RateRequest $request)
 
 proccessAdditionalValidation (\Magento\Framework\DataObject $request)
 
 requestToShipment ($request)
 
 returnOfShipment ($request)
 
 rollBack ($data)
 
 isGirthAllowed ($countyDest=null, $carrierMethodCode=null)
 
 setRawRequest ($request)
 
 getMethodPrice ($cost, $method='')
 
 parseXml ($xmlContent, $customSimplexml='SimpleXMLElement')
 
 canCollectRates ()
 
- Public Member Functions inherited from AbstractCarrier
 __construct (\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory, \Psr\Log\LoggerInterface $logger, array $data=[])
 
 getConfigData ($field)
 
 getConfigFlag ($field)
 
 requestToShipment ($request)
 
 returnOfShipment ($request)
 
 getContainerTypes (\Magento\Framework\DataObject $params=null)
 
 getCustomizableContainerTypes ()
 
 getDeliveryConfirmationTypes (\Magento\Framework\DataObject $params=null)
 
 processAdditionalValidation (\Magento\Framework\DataObject $request)
 
 proccessAdditionalValidation (\Magento\Framework\DataObject $request)
 
 isActive ()
 
 isFixed ()
 
 isTrackingAvailable ()
 
 isShippingLabelsAvailable ()
 
 getSortOrder ()
 
 getFinalPriceWithHandlingFee ($cost)
 
 getTotalNumOfBoxes ($weight)
 
 isStateProvinceRequired ()
 
 isCityRequired ()
 
 isZipCodeRequired ($countryId=null)
 
 getDebugFlag ()
 
 debugData ($debugData)
 
 getCarrierCode ()
 
 getContentTypes (\Magento\Framework\DataObject $params)
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from AbstractCarrierInterface
 checkAvailableShipCountries (\Magento\Framework\DataObject $request)
 
- Public Member Functions inherited from CarrierInterface
 isTrackingAvailable ()
 

Data Fields

const DHL_CONTENT_TYPE_DOC = 'D'
 
const DHL_CONTENT_TYPE_NON_DOC = 'N'
 
const DIMENSION_MIN_CM = 3
 
const DIMENSION_MIN_IN = 1
 
const XML_PATH_EU_COUNTRIES_LIST = 'general/country/eu_countries'
 
const CODE = 'dhl'
 
- Data Fields inherited from AbstractDhl
const CONDITION_CODE_SERVICE_DATE_UNAVAILABLE = 1003
 
const UNAVAILABLE_DATE_LOOK_FORWARD = 5
 
const REQUEST_DATE_FORMAT = 'Y-m-d'
 
- Data Fields inherited from AbstractCarrierOnline
const USA_COUNTRY_ID = 'US'
 
const PUERTORICO_COUNTRY_ID = 'PR'
 
const GUAM_COUNTRY_ID = 'GU'
 
const GUAM_REGION_CODE = 'GU'
 
- Data Fields inherited from AbstractCarrier
const DEBUG_KEYS_MASK = '****'
 
const USA_COUNTRY_ID = 'US'
 
const CANADA_COUNTRY_ID = 'CA'
 
const MEXICO_COUNTRY_ID = 'MX'
 
const HANDLING_TYPE_PERCENT = 'P'
 
const HANDLING_TYPE_FIXED = 'F'
 
const HANDLING_ACTION_PERPACKAGE = 'P'
 
const HANDLING_ACTION_PERORDER = 'O'
 

Protected Member Functions

 _getDefaultValue ($origValue, $pathToValue)
 
 _setFreeMethodRequest ($freeMethod)
 
 _addParams (\Magento\Framework\DataObject $requestObject)
 
 _getWeight ($weight, $maxWeight=false, $configWeightUnit=false)
 
 _getAllItems ()
 
 _makePieces (\Magento\Shipping\Model\Simplexml\Element $nodeBkgDetails)
 
 _getDimension ($dimension, $configWeightUnit=false)
 
 _addDimension ($nodePiece)
 
 _getQuotes ()
 
 _getQuotesFromServer ($request)
 
 _buildQuotesRequestXml ()
 
 _setQuotesRequestXmlDate (\SimpleXMLElement $requestXml, $date)
 
 _parseResponse ($response)
 
 _addRate (\SimpleXMLElement $shipmentDetails)
 
 _getDimensionUnit ()
 
 _getWeightUnit ()
 
 getCountryParams ($countryCode)
 
 _doShipmentRequest (\Magento\Framework\DataObject $request)
 
 _mapRequestToShipment (\Magento\Framework\DataObject $request)
 
 _getMinDimension ($dimensionUnit)
 
 _shipmentDetails ($xml, $rawRequest, $originRegion='')
 
 _parseXmlTrackingResponse ($trackings, $response)
 
 _getPerpackagePrice ($cost, $handlingType, $handlingFee)
 
 _checkDomesticStatus ($origCountryCode, $destCountryCode)
 
 _prepareShippingLabelContent (\SimpleXMLElement $xml)
 
 isDutiable ($origCountryId, $destCountryId)
 
- Protected Member Functions inherited from AbstractDhl
 _getShipDate ()
 
 _determineShippingDay ($shippingDays, $date)
 
- Protected Member Functions inherited from AbstractCarrierOnline
 _getQuotesCacheKey ($requestParams)
 
 _getCachedQuotes ($requestParams)
 
 _setCachedQuotes ($requestParams, $response)
 
 _prepareServiceName ($name)
 
 _prepareShipmentRequest (\Magento\Framework\DataObject $request)
 
 _doShipmentRequest (\Magento\Framework\DataObject $request)
 
 _isUSCountry ($countyId)
 
 debugErrors ($errors)
 
 getErrorMessage ()
 
- Protected Member Functions inherited from AbstractCarrier
 _getAllowedContainers (\Magento\Framework\DataObject $params=null)
 
 _updateFreeMethodQuote ($request)
 
 _getPerpackagePrice ($cost, $handlingType, $handlingFee)
 
 _getPerorderPrice ($cost, $handlingType, $handlingFee)
 
 _debug ($debugData)
 
 filterDebugData ($data)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_customizableContainerTypes = [self::DHL_CONTENT_TYPE_NON_DOC]
 
 $_request
 
 $_result
 
 $_countryParams
 
 $_errors = []
 
 $_rates = []
 
 $_code = self::CODE
 
 $_freeMethod = 'free_method_nondoc'
 
 $_maxWeight = 70
 
 $_isShippingLabelFlag = false
 
 $_requestVariables
 
 $_isDomestic = false
 
 $string
 
 $_carrierHelper
 
 $_coreDate
 
 $_storeManager
 
 $_configReader
 
 $mathDivision
 
 $readFactory
 
 $_dateTime
 
 $_httpClientFactory
 
 $_debugReplacePrivateDataKeys
 
- Protected Attributes inherited from AbstractCarrierOnline
 $_activeFlag = 'active'
 
 $_directoryData = null
 
 $_xmlElFactory
 
 $_rateFactory
 
 $_rateMethodFactory
 
 $_trackFactory
 
 $_trackErrorFactory
 
 $_trackStatusFactory
 
 $_regionFactory
 
 $_countryFactory
 
 $_currencyFactory
 
 $stockRegistry
 
 $_rawRequest = null
 
 $xmlSecurity
 
- Protected Attributes inherited from AbstractCarrier
 $_code
 
 $_rates
 
 $_numBoxes = 1
 
 $_freeMethod = 'free_method'
 
 $_isFixed = false
 
 $_customizableContainerTypes = []
 
 $_debugReplacePrivateDataKeys = []
 
 $_scopeConfig
 
 $_rateErrorFactory
 
 $_logger
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from AbstractCarrierOnline
static $_quotesCache = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

DHL International (API v1.4) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 26 of file Carrier.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory  $rateErrorFactory,
\Psr\Log\LoggerInterface  $logger,
Security  $xmlSecurity,
\Magento\Shipping\Model\Simplexml\ElementFactory  $xmlElFactory,
\Magento\Shipping\Model\Rate\ResultFactory  $rateFactory,
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory  $rateMethodFactory,
\Magento\Shipping\Model\Tracking\ResultFactory  $trackFactory,
\Magento\Shipping\Model\Tracking\Result\ErrorFactory  $trackErrorFactory,
\Magento\Shipping\Model\Tracking\Result\StatusFactory  $trackStatusFactory,
\Magento\Directory\Model\RegionFactory  $regionFactory,
\Magento\Directory\Model\CountryFactory  $countryFactory,
\Magento\Directory\Model\CurrencyFactory  $currencyFactory,
\Magento\Directory\Helper\Data  $directoryData,
\Magento\CatalogInventory\Api\StockRegistryInterface  $stockRegistry,
\Magento\Shipping\Helper\Carrier  $carrierHelper,
\Magento\Framework\Stdlib\DateTime\DateTime  $coreDate,
\Magento\Framework\Module\Dir\Reader  $configReader,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Stdlib\StringUtils  $string,
\Magento\Framework\Math\Division  $mathDivision,
\Magento\Framework\Filesystem\Directory\ReadFactory  $readFactory,
\Magento\Framework\Stdlib\DateTime  $dateTime,
\Magento\Framework\HTTP\ZendClientFactory  $httpClientFactory,
array  $data = [],
\Magento\Dhl\Model\Validator\XmlValidator  $xmlValidator = null 
)
Parameters
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory$rateErrorFactory
\Psr\Log\LoggerInterface$logger
Security$xmlSecurity
\Magento\Shipping\Model\Simplexml\ElementFactory$xmlElFactory
\Magento\Shipping\Model\Rate\ResultFactory$rateFactory
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory$rateMethodFactory
\Magento\Shipping\Model\Tracking\ResultFactory$trackFactory
\Magento\Shipping\Model\Tracking\Result\ErrorFactory$trackErrorFactory
\Magento\Shipping\Model\Tracking\Result\StatusFactory$trackStatusFactory
\Magento\Directory\Model\RegionFactory$regionFactory
\Magento\Directory\Model\CountryFactory$countryFactory
\Magento\Directory\Model\CurrencyFactory$currencyFactory
\Magento\Directory\Helper\Data$directoryData
\Magento\CatalogInventory\Api\StockRegistryInterface$stockRegistry
\Magento\Shipping\Helper\Carrier$carrierHelper
\Magento\Framework\Stdlib\DateTime\DateTime$coreDate
\Magento\Framework\Module\Dir\Reader$configReader
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Stdlib\StringUtils$string
\Magento\Framework\Math\Division$mathDivision
\Magento\Framework\Filesystem\Directory\ReadFactory$readFactory
\Magento\Framework\Stdlib\DateTime$dateTime
\Magento\Framework\HTTP\ZendClientFactory$httpClientFactory
array$data
\Magento\Dhl\Model\Validator\XmlValidator$xmlValidator@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 238 of file Carrier.php.

265  {
266  $this->readFactory = $readFactory;
267  $this->_carrierHelper = $carrierHelper;
268  $this->_coreDate = $coreDate;
269  $this->_storeManager = $storeManager;
270  $this->_configReader = $configReader;
271  $this->string = $string;
272  $this->mathDivision = $mathDivision;
273  $this->_dateTime = $dateTime;
274  $this->_httpClientFactory = $httpClientFactory;
275  parent::__construct(
276  $scopeConfig,
277  $rateErrorFactory,
278  $logger,
279  $xmlSecurity,
280  $xmlElFactory,
281  $rateFactory,
282  $rateMethodFactory,
283  $trackFactory,
284  $trackErrorFactory,
285  $trackStatusFactory,
286  $regionFactory,
287  $countryFactory,
288  $currencyFactory,
289  $directoryData,
291  $data
292  );
293  if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_DOC) {
294  $this->_freeMethod = 'free_method_doc';
295  }
296  $this->xmlValidator = $xmlValidator
297  ?: \Magento\Framework\App\ObjectManager::getInstance()->get(XmlValidator::class);
298  }
$storeManager
$logger
$dateTime

Member Function Documentation

◆ _addDimension()

_addDimension (   $nodePiece)
protected

Add dimension to piece

Parameters
\Magento\Shipping\Model\Simplexml\Element$nodePiece
Returns
void

Definition at line 901 of file Carrier.php.

902  {
903  $sizeChecker = (string)$this->getConfigData('size');
904 
905  $height = $this->_getDimension((float)$this->getConfigData('height'));
906  $depth = $this->_getDimension((float)$this->getConfigData('depth'));
907  $width = $this->_getDimension((float)$this->getConfigData('width'));
908 
909  if ($sizeChecker && $height && $depth && $width) {
910  $nodePiece->addChild('Height', $height);
911  $nodePiece->addChild('Depth', $depth);
912  $nodePiece->addChild('Width', $width);
913  }
914  }
_getDimension($dimension, $configWeightUnit=false)
Definition: Carrier.php:865

◆ _addParams()

_addParams ( \Magento\Framework\DataObject  $requestObject)
protected

Fills request object with Dhl config parameters

Parameters
\Magento\Framework\DataObject$requestObject
Returns
\Magento\Framework\DataObject

Definition at line 387 of file Carrier.php.

388  {
389  foreach ($this->_requestVariables as $code => $objectCode) {
390  if ($this->_request->getDhlId()) {
391  $value = $this->_request->getData($objectCode['code']);
392  } else {
393  $value = $this->getConfigData($code);
394  }
395  $requestObject->setData($objectCode['setCode'], $value);
396  }
397 
398  return $requestObject;
399  }
$value
Definition: gender.phtml:16
$code
Definition: info.phtml:12

◆ _addRate()

_addRate ( \SimpleXMLElement  $shipmentDetails)
protected

Add rate to DHL rates array

Parameters
\SimpleXMLElement$shipmentDetails
Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 1118 of file Carrier.php.

1119  {
1120  if (isset($shipmentDetails->ProductShortName)
1121  && isset($shipmentDetails->ShippingCharge)
1122  && isset($shipmentDetails->GlobalProductCode)
1123  && isset($shipmentDetails->CurrencyCode)
1124  && array_key_exists((string)$shipmentDetails->GlobalProductCode, $this->getAllowedMethods())
1125  ) {
1126  // DHL product code, e.g. '3', 'A', 'Q', etc.
1127  $dhlProduct = (string)$shipmentDetails->GlobalProductCode;
1128  $totalEstimate = (float)(string)$shipmentDetails->ShippingCharge;
1129  $currencyCode = (string)$shipmentDetails->CurrencyCode;
1130  $baseCurrencyCode = $this->_storeManager->getWebsite($this->_request->getWebsiteId())
1131  ->getBaseCurrencyCode();
1132  $dhlProductDescription = $this->getDhlProductTitle($dhlProduct);
1133 
1134  if ($currencyCode != $baseCurrencyCode) {
1135  /* @var $currency \Magento\Directory\Model\Currency */
1136  $currency = $this->_currencyFactory->create();
1137  $rates = $currency->getCurrencyRates($currencyCode, [$baseCurrencyCode]);
1138  if (!empty($rates) && isset($rates[$baseCurrencyCode])) {
1139  // Convert to store display currency using store exchange rate
1140  $totalEstimate = $totalEstimate * $rates[$baseCurrencyCode];
1141  } else {
1142  $rates = $currency->getCurrencyRates($baseCurrencyCode, [$currencyCode]);
1143  if (!empty($rates) && isset($rates[$currencyCode])) {
1144  $totalEstimate = $totalEstimate / $rates[$currencyCode];
1145  }
1146  if (!isset($rates[$currencyCode]) || !$totalEstimate) {
1147  $totalEstimate = false;
1148  $this->_errors[] = __(
1149  'We had to skip DHL method %1 because we couldn\'t find exchange rate %2 (Base Currency).',
1150  $currencyCode,
1151  $baseCurrencyCode
1152  );
1153  }
1154  }
1155  }
1156  if ($totalEstimate) {
1157  $data = [
1158  'term' => $dhlProductDescription,
1159  'price_total' => $this->getMethodPrice($totalEstimate, $dhlProduct),
1160  ];
1161  if (!empty($this->_rates)) {
1162  foreach ($this->_rates as $product) {
1163  if ($product['data']['term'] == $data['term']
1164  && $product['data']['price_total'] == $data['price_total']
1165  ) {
1166  return $this;
1167  }
1168  }
1169  }
1170  $this->_rates[] = ['service' => $dhlProduct, 'data' => $data];
1171  } else {
1172  $this->_errors[] = __("Zero shipping charge for '%1'", $dhlProductDescription);
1173  }
1174  } else {
1175  $dhlProductDescription = false;
1176  if (isset($shipmentDetails->GlobalProductCode)) {
1177  $dhlProductDescription = $this->getDhlProductTitle((string)$shipmentDetails->GlobalProductCode);
1178  }
1179  $dhlProductDescription = $dhlProductDescription ? $dhlProductDescription : __("DHL");
1180  $this->_errors[] = __("Zero shipping charge for '%1'", $dhlProductDescription);
1181  }
1182 
1183  return $this;
1184  }
__()
Definition: __.php:13
$rates
Definition: tax.phtml:35

◆ _buildQuotesRequestXml()

_buildQuotesRequestXml ( )
protected

Build quotes request XML object

Returns
\SimpleXMLElement

Definition at line 983 of file Carrier.php.

984  {
985  $rawRequest = $this->_rawRequest;
986  $xmlStr = '<?xml version = "1.0" encoding = "UTF-8"?>' .
987  '<p:DCTRequest xmlns:p="http://www.dhl.com" xmlns:p1="http://www.dhl.com/datatypes" ' .
988  'xmlns:p2="http://www.dhl.com/DCTRequestdatatypes" ' .
989  'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' .
990  'xsi:schemaLocation="http://www.dhl.com DCT-req.xsd "/>';
991  $xml = $this->_xmlElFactory->create(['data' => $xmlStr]);
992  $nodeGetQuote = $xml->addChild('GetQuote', '', '');
993  $nodeRequest = $nodeGetQuote->addChild('Request');
994 
995  $nodeServiceHeader = $nodeRequest->addChild('ServiceHeader');
996  $nodeServiceHeader->addChild('SiteID', (string)$this->getConfigData('id'));
997  $nodeServiceHeader->addChild('Password', (string)$this->getConfigData('password'));
998 
999  $nodeFrom = $nodeGetQuote->addChild('From');
1000  $nodeFrom->addChild('CountryCode', $rawRequest->getOrigCountryId());
1001  $nodeFrom->addChild('Postalcode', $rawRequest->getOrigPostal());
1002  $nodeFrom->addChild('City', $rawRequest->getOrigCity());
1003 
1004  $nodeBkgDetails = $nodeGetQuote->addChild('BkgDetails');
1005  $nodeBkgDetails->addChild('PaymentCountryCode', $rawRequest->getOrigCountryId());
1006  $nodeBkgDetails->addChild(
1007  'Date',
1008  (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)
1009  );
1010  $nodeBkgDetails->addChild('ReadyTime', 'PT' . (int)(string)$this->getConfigData('ready_time') . 'H00M');
1011 
1012  $nodeBkgDetails->addChild('DimensionUnit', $this->_getDimensionUnit());
1013  $nodeBkgDetails->addChild('WeightUnit', $this->_getWeightUnit());
1014 
1015  $this->_makePieces($nodeBkgDetails);
1016 
1017  $nodeBkgDetails->addChild('PaymentAccountNumber', (string)$this->getConfigData('account'));
1018 
1019  $nodeTo = $nodeGetQuote->addChild('To');
1020  $nodeTo->addChild('CountryCode', $rawRequest->getDestCountryId());
1021  $nodeTo->addChild('Postalcode', $rawRequest->getDestPostal());
1022  $nodeTo->addChild('City', $rawRequest->getDestCity());
1023 
1024  if ($this->isDutiable($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId())) {
1025  // IsDutiable flag and Dutiable node indicates that cargo is not a documentation
1026  $nodeBkgDetails->addChild('IsDutiable', 'Y');
1027  $nodeDutiable = $nodeGetQuote->addChild('Dutiable');
1028  $baseCurrencyCode = $this->_storeManager
1029  ->getWebsite($this->_request->getWebsiteId())
1030  ->getBaseCurrencyCode();
1031  $nodeDutiable->addChild('DeclaredCurrency', $baseCurrencyCode);
1032  $nodeDutiable->addChild('DeclaredValue', sprintf("%.2F", $rawRequest->getValue()));
1033  }
1034 
1035  return $xml;
1036  }
isDutiable($origCountryId, $destCountryId)
Definition: Carrier.php:1967
_makePieces(\Magento\Shipping\Model\Simplexml\Element $nodeBkgDetails)
Definition: Carrier.php:793

◆ _checkDomesticStatus()

_checkDomesticStatus (   $origCountryCode,
  $destCountryCode 
)
protected

Check if shipping is domestic

Parameters
string$origCountryCode
string$destCountryCode
Returns
bool

Definition at line 1918 of file Carrier.php.

1919  {
1920  $this->_isDomestic = false;
1921 
1922  $origCountry = (string)$this->getCountryParams($origCountryCode)->getData('name');
1923  $destCountry = (string)$this->getCountryParams($destCountryCode)->getData('name');
1924  $isDomestic = (string)$this->getCountryParams($destCountryCode)->getData('domestic');
1925 
1926  if (($origCountry == $destCountry && $isDomestic)
1927  || ($this->_carrierHelper->isCountryInEU($origCountryCode)
1928  && $this->_carrierHelper->isCountryInEU($destCountryCode)
1929  )
1930  ) {
1931  $this->_isDomestic = true;
1932  }
1933 
1934  return $this->_isDomestic;
1935  }
getCountryParams($countryCode)
Definition: Carrier.php:1232

◆ _doShipmentRequest()

_doShipmentRequest ( \Magento\Framework\DataObject  $request)
protected

Do shipment request to carrier web service, obtain Print Shipping Labels and process errors in response

Parameters
\Magento\Framework\DataObject$request
Returns
\Magento\Framework\DataObject

Definition at line 1252 of file Carrier.php.

1253  {
1256  $this->setRequest($request);
1257 
1258  return $this->_doRequest();
1259  }
_prepareShipmentRequest(\Magento\Framework\DataObject $request)
setRequest(\Magento\Framework\DataObject $request)
Definition: Carrier.php:409
_mapRequestToShipment(\Magento\Framework\DataObject $request)
Definition: Carrier.php:1328

◆ _getAllItems()

_getAllItems ( )
protected

Prepare items to pieces

Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 702 of file Carrier.php.

703  {
704  $allItems = $this->_request->getAllItems();
705  $fullItems = [];
706 
707  foreach ($allItems as $item) {
708  if ($item->getProductType() == Type::TYPE_BUNDLE && $item->getProduct()->getShipmentType()) {
709  continue;
710  }
711 
712  $qty = $item->getQty();
713  $changeQty = true;
714  $checkWeight = true;
715  $decimalItems = [];
716 
717  if ($item->getParentItem()) {
718  if (!$item->getParentItem()->getProduct()->getShipmentType()) {
719  continue;
720  }
721  if ($item->getIsQtyDecimal()) {
722  $qty = $item->getParentItem()->getQty();
723  } else {
724  $qty = $item->getParentItem()->getQty() * $item->getQty();
725  }
726  }
727 
728  $itemWeight = $item->getWeight();
729  if ($item->getIsQtyDecimal() && $item->getProductType() != Type::TYPE_BUNDLE) {
730  $productId = $item->getProduct()->getId();
731  $stockItemDo = $this->stockRegistry->getStockItem($productId, $item->getStore()->getWebsiteId());
732  $isDecimalDivided = $stockItemDo->getIsDecimalDivided();
733  if ($isDecimalDivided) {
734  if ($stockItemDo->getEnableQtyIncrements()
735  && $stockItemDo->getQtyIncrements()
736  ) {
737  $itemWeight = $itemWeight * $stockItemDo->getQtyIncrements();
738  $qty = round($item->getWeight() / $itemWeight * $qty);
739  $changeQty = false;
740  } else {
741  $itemWeight = $this->_getWeight($itemWeight * $item->getQty());
742  $maxWeight = $this->_getWeight($this->_maxWeight, true);
743  if ($itemWeight > $maxWeight) {
744  $qtyItem = floor($itemWeight / $maxWeight);
745  $decimalItems[] = ['weight' => $maxWeight, 'qty' => $qtyItem];
746  $weightItem = $this->mathDivision->getExactDivision($itemWeight, $maxWeight);
747  if ($weightItem) {
748  $decimalItems[] = ['weight' => $weightItem, 'qty' => 1];
749  }
750  $checkWeight = false;
751  }
752  }
753  } else {
754  $itemWeight = $itemWeight * $item->getQty();
755  }
756  }
757 
758  if ($checkWeight && $this->_getWeight($itemWeight) > $this->_getWeight($this->_maxWeight, true)) {
759  return [];
760  }
761 
762  if ($changeQty
763  && !$item->getParentItem()
764  && $item->getIsQtyDecimal()
765  && $item->getProductType() != Type::TYPE_BUNDLE
766  ) {
767  $qty = 1;
768  }
769 
770  if (!empty($decimalItems)) {
771  foreach ($decimalItems as $decimalItem) {
772  $fullItems = array_merge(
773  $fullItems,
774  array_fill(0, $decimalItem['qty'] * $qty, $decimalItem['weight'])
775  );
776  }
777  } else {
778  $fullItems = array_merge($fullItems, array_fill(0, $qty, $this->_getWeight($itemWeight)));
779  }
780  }
781  sort($fullItems);
782 
783  return $fullItems;
784  }
_getWeight($weight, $maxWeight=false, $configWeightUnit=false)
Definition: Carrier.php:669

◆ _getDefaultValue()

_getDefaultValue (   $origValue,
  $pathToValue 
)
protected

Returns value of given variable

Parameters
string | int$origValue
string$pathToValue
Returns
string|int|null

Definition at line 307 of file Carrier.php.

308  {
309  if (!$origValue) {
310  $origValue = $this->_scopeConfig->getValue(
311  $pathToValue,
313  $this->getStore()
314  );
315  }
316 
317  return $origValue;
318  }

◆ _getDimension()

_getDimension (   $dimension,
  $configWeightUnit = false 
)
protected

Convert item dimension to needed dimension based on config dimension unit of measure

Parameters
float$dimension
string | bool$configWeightUnit
Returns
float

Definition at line 865 of file Carrier.php.

866  {
867  if (!$configWeightUnit) {
868  $configWeightUnit = $this->getCode(
869  'dimensions_variables',
870  (string)$this->getConfigData('unit_of_measure')
871  );
872  } else {
873  $configWeightUnit = $this->getCode('dimensions_variables', $configWeightUnit);
874  }
875 
876  if ($configWeightUnit == \Zend_Measure_Weight::POUND) {
877  $configDimensionUnit = \Zend_Measure_Length::INCH;
878  } else {
879  $configDimensionUnit = \Zend_Measure_Length::CENTIMETER;
880  }
881 
882  $countryDimensionUnit = $this->getCode('dimensions_variables', $this->_getDimensionUnit());
883 
884  if ($configDimensionUnit != $countryDimensionUnit) {
885  $dimension = $this->_carrierHelper->convertMeasureDimension(
886  (float)$dimension,
887  $configDimensionUnit,
888  $countryDimensionUnit
889  );
890  }
891 
892  return sprintf('%.3f', $dimension);
893  }
getCode($type, $code='')
Definition: Carrier.php:549

◆ _getDimensionUnit()

_getDimensionUnit ( )
protected

Returns dimension unit (cm or inch)

Returns
string
Exceptions

Definition at line 1192 of file Carrier.php.

1193  {
1194  $countryId = $this->_rawRequest->getOrigCountryId();
1195  $measureUnit = $this->getCountryParams($countryId)->getMeasureUnit();
1196  if (empty($measureUnit)) {
1197  throw new \Magento\Framework\Exception\LocalizedException(
1198  __("Cannot identify measure unit for %1", $countryId)
1199  );
1200  }
1201 
1202  return $measureUnit;
1203  }
__()
Definition: __.php:13
getCountryParams($countryCode)
Definition: Carrier.php:1232

◆ _getMinDimension()

_getMinDimension (   $dimensionUnit)
protected

Retrieve minimum allowed value for dimensions in given dimension unit

Parameters
string$dimensionUnit
Returns
int

Definition at line 1371 of file Carrier.php.

1372  {
1373  return $dimensionUnit == "CENTIMETER" ? self::DIMENSION_MIN_CM : self::DIMENSION_MIN_IN;
1374  }

◆ _getPerpackagePrice()

_getPerpackagePrice (   $cost,
  $handlingType,
  $handlingFee 
)
protected

Get final price for shipping method with handling fee per package

Parameters
float$cost
string$handlingType
float$handlingFee
Returns
float

Definition at line 1871 of file Carrier.php.

1872  {
1873  if ($handlingType == AbstractCarrier::HANDLING_TYPE_PERCENT) {
1874  return $cost + $cost * $this->_numBoxes * $handlingFee / 100;
1875  }
1876 
1877  return $cost + $this->_numBoxes * $handlingFee;
1878  }

◆ _getQuotes()

_getQuotes ( )
protected

Get shipping quotes

Returns
\Magento\Framework\Model\AbstractModel|Result

Definition at line 921 of file Carrier.php.

922  {
923  $responseBody = '';
924  try {
925  for ($offset = 0; $offset <= self::UNAVAILABLE_DATE_LOOK_FORWARD; $offset++) {
926  $debugPoint = [];
927 
928  $requestXml = $this->_buildQuotesRequestXml();
929  $date = date(self::REQUEST_DATE_FORMAT, strtotime($this->_getShipDate() . " +{$offset} days"));
930  $this->_setQuotesRequestXmlDate($requestXml, $date);
931 
932  $request = $requestXml->asXML();
933  $debugPoint['request'] = $this->filterDebugData($request);
934  $responseBody = $this->_getCachedQuotes($request);
935  $debugPoint['from_cache'] = $responseBody === null;
936 
937  if ($debugPoint['from_cache']) {
938  $responseBody = $this->_getQuotesFromServer($request);
939  }
940 
941  $debugPoint['response'] = $this->filterDebugData($responseBody);
942 
943  $bodyXml = $this->_xmlElFactory->create(['data' => $responseBody]);
944  $code = $bodyXml->xpath('//GetQuoteResponse/Note/Condition/ConditionCode');
945  if (isset($code[0]) && (int)$code[0] == self::CONDITION_CODE_SERVICE_DATE_UNAVAILABLE) {
946  $debugPoint['info'] = sprintf(__("DHL service is not available at %s date"), $date);
947  } else {
948  $this->_debug($debugPoint);
949  break;
950  }
951 
952  $this->_setCachedQuotes($request, $responseBody);
953  $this->_debug($debugPoint);
954  }
955  } catch (\Exception $e) {
956  $this->_errors[$e->getCode()] = $e->getMessage();
957  }
958 
959  return $this->_parseResponse($responseBody);
960  }
__()
Definition: __.php:13
_getQuotesFromServer($request)
Definition: Carrier.php:968
_setQuotesRequestXmlDate(\SimpleXMLElement $requestXml, $date)
Definition: Carrier.php:1045
$code
Definition: info.phtml:12

◆ _getQuotesFromServer()

_getQuotesFromServer (   $request)
protected

Get shipping quotes from DHL service

Parameters
string$request
Returns
string

Definition at line 968 of file Carrier.php.

969  {
970  $client = $this->_httpClientFactory->create();
971  $client->setUri((string)$this->getConfigData('gateway_url'));
972  $client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
973  $client->setRawData(utf8_encode($request));
974 
975  return $client->request(\Zend_Http_Client::POST)->getBody();
976  }

◆ _getWeight()

_getWeight (   $weight,
  $maxWeight = false,
  $configWeightUnit = false 
)
protected

Convert item weight to needed weight based on config weight unit dimensions

Parameters
float$weight
bool$maxWeight
string | bool$configWeightUnit
Returns
float

Definition at line 669 of file Carrier.php.

670  {
671  if ($maxWeight) {
672  $configWeightUnit = \Zend_Measure_Weight::KILOGRAM;
673  } elseif ($configWeightUnit) {
674  $configWeightUnit = $this->getCode('dimensions_variables', $configWeightUnit);
675  } else {
676  $configWeightUnit = $this->getCode(
677  'dimensions_variables',
678  (string)$this->getConfigData('unit_of_measure')
679  );
680  }
681 
682  $countryWeightUnit = $this->getCode('dimensions_variables', $this->_getWeightUnit());
683 
684  if ($configWeightUnit != $countryWeightUnit) {
685  $weight = $this->_carrierHelper->convertMeasureWeight(
686  (float)$weight,
687  $configWeightUnit,
688  $countryWeightUnit
689  );
690  }
691 
692  return sprintf('%.3f', $weight);
693  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
getCode($type, $code='')
Definition: Carrier.php:549

◆ _getWeightUnit()

_getWeightUnit ( )
protected

Returns weight unit (kg or pound)

Returns
string
Exceptions

Definition at line 1211 of file Carrier.php.

1212  {
1213  $countryId = $this->_rawRequest->getOrigCountryId();
1214  $weightUnit = $this->getCountryParams($countryId)->getWeightUnit();
1215  if (empty($weightUnit)) {
1216  throw new \Magento\Framework\Exception\LocalizedException(
1217  __("Cannot identify weight unit for %1", $countryId)
1218  );
1219  }
1220 
1221  return $weightUnit;
1222  }
__()
Definition: __.php:13
getCountryParams($countryCode)
Definition: Carrier.php:1232

◆ _makePieces()

_makePieces ( \Magento\Shipping\Model\Simplexml\Element  $nodeBkgDetails)
protected

Make pieces

Parameters
\Magento\Shipping\Model\Simplexml\Element$nodeBkgDetails
Returns
void @SuppressWarnings(PHPMD.CyclomaticComplexity)

Definition at line 793 of file Carrier.php.

794  {
795  $divideOrderWeight = (string)$this->getConfigData('divide_order_weight');
796  $nodePieces = $nodeBkgDetails->addChild('Pieces', '', '');
797  $items = $this->_getAllItems();
798  $numberOfPieces = 0;
799 
800  if ($divideOrderWeight && !empty($items)) {
801  $maxWeight = $this->_getWeight($this->_maxWeight, true);
802  $sumWeight = 0;
803 
804  $reverseOrderItems = $items;
805  arsort($reverseOrderItems);
806 
807  foreach ($reverseOrderItems as $key => $weight) {
808  if (!isset($items[$key])) {
809  continue;
810  }
811  unset($items[$key]);
812  $sumWeight = $weight;
813  foreach ($items as $key => $weight) {
814  if ($sumWeight + $weight < $maxWeight) {
815  unset($items[$key]);
816  $sumWeight += $weight;
817  } elseif ($sumWeight + $weight > $maxWeight) {
818  $numberOfPieces++;
819  $nodePiece = $nodePieces->addChild('Piece', '', '');
820  $nodePiece->addChild('PieceID', $numberOfPieces);
821  $this->_addDimension($nodePiece);
822  $nodePiece->addChild('Weight', sprintf('%.3f', $sumWeight));
823  break;
824  } else {
825  unset($items[$key]);
826  $numberOfPieces++;
827  $sumWeight += $weight;
828  $nodePiece = $nodePieces->addChild('Piece', '', '');
829  $nodePiece->addChild('PieceID', $numberOfPieces);
830  $this->_addDimension($nodePiece);
831  $nodePiece->addChild('Weight', sprintf('%.3f', $sumWeight));
832  $sumWeight = 0;
833  break;
834  }
835  }
836  }
837  if ($sumWeight > 0) {
838  $numberOfPieces++;
839  $nodePiece = $nodePieces->addChild('Piece', '', '');
840  $nodePiece->addChild('PieceID', $numberOfPieces);
841  $this->_addDimension($nodePiece);
842  $nodePiece->addChild('Weight', sprintf('%.3f', $sumWeight));
843  }
844  } else {
845  $nodePiece = $nodePieces->addChild('Piece', '', '');
846  $nodePiece->addChild('PieceID', 1);
847  $this->_addDimension($nodePiece);
848  $nodePiece->addChild('Weight', $this->_getWeight($this->_rawRequest->getWeight()));
849  }
850 
851  $handlingAction = $this->getConfigData('handling_action');
852  if ($handlingAction == AbstractCarrier::HANDLING_ACTION_PERORDER || !$numberOfPieces) {
853  $numberOfPieces = 1;
854  }
855  $this->_numBoxes = $numberOfPieces;
856  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
_addDimension($nodePiece)
Definition: Carrier.php:901
_getWeight($weight, $maxWeight=false, $configWeightUnit=false)
Definition: Carrier.php:669
$items

◆ _mapRequestToShipment()

_mapRequestToShipment ( \Magento\Framework\DataObject  $request)
protected

Map request to shipment

Parameters
\Magento\Framework\DataObject$request
Returns
void
Exceptions

Definition at line 1328 of file Carrier.php.

1329  {
1330  $request->setOrigCountryId($request->getShipperAddressCountryCode());
1331  $this->setRawRequest($request);
1332  $customsValue = 0;
1333  $packageWeight = 0;
1334  $packages = $request->getPackages();
1335  foreach ($packages as &$piece) {
1336  $params = $piece['params'];
1337  if ($params['width'] || $params['length'] || $params['height']) {
1338  $minValue = $this->_getMinDimension($params['dimension_units']);
1339  if ($params['width'] < $minValue || $params['length'] < $minValue || $params['height'] < $minValue) {
1340  $message = __('Height, width and length should be equal or greater than %1', $minValue);
1341  throw new \Magento\Framework\Exception\LocalizedException($message);
1342  }
1343  }
1344 
1345  $weightUnits = $piece['params']['weight_units'];
1346  $piece['params']['height'] = $this->_getDimension($piece['params']['height'], $weightUnits);
1347  $piece['params']['length'] = $this->_getDimension($piece['params']['length'], $weightUnits);
1348  $piece['params']['width'] = $this->_getDimension($piece['params']['width'], $weightUnits);
1349  $piece['params']['dimension_units'] = $this->_getDimensionUnit();
1350  $piece['params']['weight'] = $this->_getWeight($piece['params']['weight'], false, $weightUnits);
1351  $piece['params']['weight_units'] = $this->_getWeightUnit();
1352 
1353  $customsValue += $piece['params']['customs_value'];
1354  $packageWeight += $piece['params']['weight'];
1355  }
1356 
1357  $request->setPackages($packages)
1358  ->setPackageWeight($packageWeight)
1359  ->setPackageValue($customsValue)
1360  ->setValueWithDiscount($customsValue)
1361  ->setPackageCustomsValue($customsValue)
1362  ->setFreeMethodWeight(0);
1363  }
__()
Definition: __.php:13
$message
_getDimension($dimension, $configWeightUnit=false)
Definition: Carrier.php:865
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
_getMinDimension($dimensionUnit)
Definition: Carrier.php:1371
_getWeight($weight, $maxWeight=false, $configWeightUnit=false)
Definition: Carrier.php:669

◆ _parseResponse()

_parseResponse (   $response)
protected

Parse response from DHL web service

Parameters
string$response
Returns
bool|\Magento\Framework\DataObject|Result|Error
Exceptions

Definition at line 1060 of file Carrier.php.

1061  {
1062  $responseError = __('The response is in wrong format.');
1063  try {
1064  $this->xmlValidator->validate($response);
1065  $xml = simplexml_load_string($response);
1066  if (isset($xml->GetQuoteResponse->BkgDetails->QtdShp)) {
1067  foreach ($xml->GetQuoteResponse->BkgDetails->QtdShp as $quotedShipment) {
1068  $this->_addRate($quotedShipment);
1069  }
1070  } elseif (isset($xml->AirwayBillNumber)) {
1071  return $this->_prepareShippingLabelContent($xml);
1072  } else {
1073  $this->_errors[] = $responseError;
1074  }
1075  } catch (DocumentValidationException $e) {
1076  if ($e->getCode() > 0) {
1077  $this->_errors[$e->getCode()] = $e->getMessage();
1078  } else {
1079  $this->_errors[] = $e->getMessage();
1080  }
1081  }
1082  /* @var $result Result */
1083  $result = $this->_rateFactory->create();
1084  if ($this->_rates) {
1085  foreach ($this->_rates as $rate) {
1086  $method = $rate['service'];
1087  $data = $rate['data'];
1088  /* @var $rate \Magento\Quote\Model\Quote\Address\RateResult\Method */
1089  $rate = $this->_rateMethodFactory->create();
1090  $rate->setCarrier(self::CODE);
1091  $rate->setCarrierTitle($this->getConfigData('title'));
1092  $rate->setMethod($method);
1093  $rate->setMethodTitle($data['term']);
1094  $rate->setCost($data['price_total']);
1095  $rate->setPrice($data['price_total']);
1096  $result->append($rate);
1097  }
1098  } else {
1099  if (!empty($this->_errors)) {
1100  if ($this->_isShippingLabelFlag) {
1101  throw new \Magento\Framework\Exception\LocalizedException($responseError);
1102  }
1103  $this->debugErrors($this->_errors);
1104  }
1105  $result->append($this->getErrorMessage());
1106  }
1107 
1108  return $result;
1109  }
_addRate(\SimpleXMLElement $shipmentDetails)
Definition: Carrier.php:1118
$response
Definition: 404.php:11
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$method
Definition: info.phtml:13
_prepareShippingLabelContent(\SimpleXMLElement $xml)
Definition: Carrier.php:1944

◆ _parseXmlTrackingResponse()

_parseXmlTrackingResponse (   $trackings,
  $response 
)
protected

Parse xml tracking response

Parameters
string[]$trackings
string$response
Returns
void @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 1779 of file Carrier.php.

1780  {
1781  $errorTitle = __('Unable to retrieve tracking');
1782  $resultArr = [];
1783 
1784  if (strlen(trim($response)) > 0) {
1785  $xml = $this->parseXml($response, \Magento\Shipping\Model\Simplexml\Element::class);
1786  if (!is_object($xml)) {
1787  $errorTitle = __('Response is in the wrong format');
1788  }
1789  if (is_object($xml)
1790  && (isset($xml->Response->Status->ActionStatus)
1791  && $xml->Response->Status->ActionStatus == 'Failure'
1792  || isset($xml->GetQuoteResponse->Note->Condition))
1793  ) {
1794  if (isset($xml->Response->Status->Condition)) {
1795  $nodeCondition = $xml->Response->Status->Condition;
1796  }
1797  $code = isset($nodeCondition->ConditionCode) ? (string)$nodeCondition->ConditionCode : 0;
1798  $data = isset($nodeCondition->ConditionData) ? (string)$nodeCondition->ConditionData : '';
1799  $this->_errors[$code] = __('Error #%1 : %2', $code, $data);
1800  } elseif (is_object($xml) && is_object($xml->AWBInfo)) {
1801  foreach ($xml->AWBInfo as $awbinfo) {
1802  $awbinfoData = [];
1803  $trackNum = isset($awbinfo->AWBNumber) ? (string)$awbinfo->AWBNumber : '';
1804  if (!is_object($awbinfo) || !$awbinfo->ShipmentInfo) {
1805  $this->_errors[$trackNum] = __('Unable to retrieve tracking');
1806  continue;
1807  }
1808  $shipmentInfo = $awbinfo->ShipmentInfo;
1809 
1810  if ($shipmentInfo->ShipmentDesc) {
1811  $awbinfoData['service'] = (string)$shipmentInfo->ShipmentDesc;
1812  }
1813 
1814  $awbinfoData['weight'] = (string)$shipmentInfo->Weight . ' ' . (string)$shipmentInfo->WeightUnit;
1815 
1816  $packageProgress = [];
1817  if (isset($shipmentInfo->ShipmentEvent)) {
1818  foreach ($shipmentInfo->ShipmentEvent as $shipmentEvent) {
1819  $shipmentEventArray = [];
1820  $shipmentEventArray['activity'] = (string)$shipmentEvent->ServiceEvent->EventCode
1821  . ' ' . (string)$shipmentEvent->ServiceEvent->Description;
1822  $shipmentEventArray['deliverydate'] = (string)$shipmentEvent->Date;
1823  $shipmentEventArray['deliverytime'] = (string)$shipmentEvent->Time;
1824  $shipmentEventArray['deliverylocation'] = (string)$shipmentEvent->ServiceArea
1825  ->Description . ' [' . (string)$shipmentEvent->ServiceArea->ServiceAreaCode . ']';
1826  $packageProgress[] = $shipmentEventArray;
1827  }
1828  $awbinfoData['progressdetail'] = $packageProgress;
1829  }
1830  $resultArr[$trackNum] = $awbinfoData;
1831  }
1832  }
1833  }
1834 
1835  $result = $this->_trackFactory->create();
1836 
1837  if (!empty($resultArr)) {
1838  foreach ($resultArr as $trackNum => $data) {
1839  $tracking = $this->_trackStatusFactory->create();
1840  $tracking->setCarrier($this->_code);
1841  $tracking->setCarrierTitle($this->getConfigData('title'));
1842  $tracking->setTracking($trackNum);
1843  $tracking->addData($data);
1844  $result->append($tracking);
1845  }
1846  }
1847 
1848  if (!empty($this->_errors) || empty($resultArr)) {
1849  $resultArr = !empty($this->_errors) ? $this->_errors : $trackings;
1850  foreach ($resultArr as $trackNum => $err) {
1851  $error = $this->_trackErrorFactory->create();
1852  $error->setCarrier($this->_code);
1853  $error->setCarrierTitle($this->getConfigData('title'));
1854  $error->setTracking(!empty($this->_errors) ? $trackNum : $err);
1855  $error->setErrorMessage(!empty($this->_errors) ? $err : $errorTitle);
1856  $result->append($error);
1857  }
1858  }
1859 
1860  $this->_result = $result;
1861  }
$response
Definition: 404.php:11
if(!defined( 'PHP_VERSION_ID')||!(PHP_VERSION_ID===70002||PHP_VERSION_ID===70004||PHP_VERSION_ID >=70006))
Definition: bootstrap.php:14
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
parseXml($xmlContent, $customSimplexml='SimpleXMLElement')
$code
Definition: info.phtml:12

◆ _prepareShippingLabelContent()

_prepareShippingLabelContent ( \SimpleXMLElement  $xml)
protected

Prepare shipping label data

Parameters
\SimpleXMLElement$xml
Returns
\Magento\Framework\DataObject
Exceptions

Definition at line 1944 of file Carrier.php.

1945  {
1946  $result = new \Magento\Framework\DataObject();
1947  try {
1948  if (!isset($xml->AirwayBillNumber) || !isset($xml->LabelImage->OutputImage)) {
1949  throw new \Magento\Framework\Exception\LocalizedException(__('Unable to retrieve shipping label'));
1950  }
1951  $result->setTrackingNumber((string)$xml->AirwayBillNumber);
1952  $labelContent = (string)$xml->LabelImage->OutputImage;
1953  $result->setShippingLabelContent(base64_decode($labelContent));
1954  } catch (\Exception $e) {
1955  throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()));
1956  }
1957 
1958  return $result;
1959  }
__()
Definition: __.php:13

◆ _setFreeMethodRequest()

_setFreeMethodRequest (   $freeMethod)
protected

Set Free Method Request

Parameters
string$freeMethod
Returns
void

Definition at line 363 of file Carrier.php.

364  {
365  $this->_rawRequest->setFreeMethodRequest(true);
366  $freeWeight = $this->getTotalNumOfBoxes($this->_rawRequest->getFreeMethodWeight());
367  $this->_rawRequest->setWeight($freeWeight);
368  $this->_rawRequest->setService($freeMethod);
369  }

◆ _setQuotesRequestXmlDate()

_setQuotesRequestXmlDate ( \SimpleXMLElement  $requestXml,
  $date 
)
protected

Set pick-up date in request XML object

Parameters
\SimpleXMLElement$requestXml
string$date
Returns
\SimpleXMLElement

Definition at line 1045 of file Carrier.php.

1046  {
1047  $requestXml->GetQuote->BkgDetails->Date = $date;
1048 
1049  return $requestXml;
1050  }

◆ _shipmentDetails()

_shipmentDetails (   $xml,
  $rawRequest,
  $originRegion = '' 
)
protected

Generation Shipment Details Node according to origin region

Parameters
\Magento\Shipping\Model\Simplexml\Element$xml
RateRequest$rawRequest
string$originRegion
Returns
void @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

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)

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)

Definition at line 1588 of file Carrier.php.

1589  {
1590  $nodeShipmentDetails = $xml->addChild('ShipmentDetails', '', '');
1591  $nodeShipmentDetails->addChild('NumberOfPieces', count($rawRequest->getPackages()));
1592 
1593  if ($originRegion) {
1594  $nodeShipmentDetails->addChild(
1595  'CurrencyCode',
1596  $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode()
1597  );
1598  }
1599 
1600  $nodePieces = $nodeShipmentDetails->addChild('Pieces', '', '');
1601 
1602  /*
1603  * Package type
1604  * EE (DHL Express Envelope), OD (Other DHL Packaging), CP (Custom Packaging)
1605  * DC (Document), DM (Domestic), ED (Express Document), FR (Freight)
1606  * BD (Jumbo Document), BP (Jumbo Parcel), JD (Jumbo Junior Document)
1607  * JP (Jumbo Junior Parcel), PA (Parcel), DF (DHL Flyer)
1608  */
1609  $i = 0;
1610  foreach ($rawRequest->getPackages() as $package) {
1611  $nodePiece = $nodePieces->addChild('Piece', '', '');
1612  $packageType = 'EE';
1613  if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
1614  $packageType = 'CP';
1615  }
1616  $nodePiece->addChild('PieceID', ++$i);
1617  $nodePiece->addChild('PackageType', $packageType);
1618  $nodePiece->addChild('Weight', sprintf('%.1f', $package['params']['weight']));
1619  $params = $package['params'];
1620  if ($params['width'] && $params['length'] && $params['height']) {
1621  if (!$originRegion) {
1622  $nodePiece->addChild('Width', round($params['width']));
1623  $nodePiece->addChild('Height', round($params['height']));
1624  $nodePiece->addChild('Depth', round($params['length']));
1625  } else {
1626  $nodePiece->addChild('Depth', round($params['length']));
1627  $nodePiece->addChild('Width', round($params['width']));
1628  $nodePiece->addChild('Height', round($params['height']));
1629  }
1630  }
1631  $content = [];
1632  foreach ($package['items'] as $item) {
1633  $content[] = $item['name'];
1634  }
1635  $nodePiece->addChild('PieceContents', substr(implode(',', $content), 0, 34));
1636  }
1637 
1638  if (!$originRegion) {
1639  $nodeShipmentDetails->addChild('Weight', sprintf('%.1f', $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('Date', $this->_coreDate->date('Y-m-d'));
1644  $nodeShipmentDetails->addChild('Contents', 'DHL Parcel');
1650  $nodeShipmentDetails->addChild('DoorTo', 'DD');
1651  $nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1));
1652  if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
1653  $packageType = 'CP';
1654  }
1655  $nodeShipmentDetails->addChild('PackageType', $packageType);
1656  if ($this->isDutiable($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId())) {
1657  $nodeShipmentDetails->addChild('IsDutiable', 'Y');
1658  }
1659  $nodeShipmentDetails->addChild(
1660  'CurrencyCode',
1661  $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode()
1662  );
1663  } else {
1664  if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
1665  $packageType = 'CP';
1666  }
1667  $nodeShipmentDetails->addChild('PackageType', $packageType);
1668  $nodeShipmentDetails->addChild('Weight', sprintf('%.3f', $rawRequest->getPackageWeight()));
1669  $nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1));
1670  $nodeShipmentDetails->addChild('WeightUnit', substr($this->_getWeightUnit(), 0, 1));
1671  $nodeShipmentDetails->addChild('GlobalProductCode', $rawRequest->getShippingMethod());
1672  $nodeShipmentDetails->addChild('LocalProductCode', $rawRequest->getShippingMethod());
1673 
1679  $nodeShipmentDetails->addChild('DoorTo', 'DD');
1680  $nodeShipmentDetails->addChild('Date', $this->_coreDate->date('Y-m-d'));
1681  $nodeShipmentDetails->addChild('Contents', 'DHL Parcel TEST');
1682  }
1683  }
isDutiable($origCountryId, $destCountryId)
Definition: Carrier.php:1967
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18
$i
Definition: gallery.phtml:31

◆ collectRates()

collectRates ( RateRequest  $request)

Collect and get rates

Parameters
RateRequest$request
Returns
bool|Result|Error

Implements AbstractCarrierInterface.

Definition at line 326 of file Carrier.php.

327  {
328  if (!$this->canCollectRates()) {
329  return $this->getErrorMessage();
330  }
331 
332  $requestDhl = clone $request;
333  $this->setStore($requestDhl->getStoreId());
334 
335  $origCompanyName = $this->_getDefaultValue(
336  $requestDhl->getOrigCompanyName(),
338  );
339  $origCountryId = $this->_getDefaultValue($requestDhl->getOrigCountryId(), Shipment::XML_PATH_STORE_COUNTRY_ID);
340  $origState = $this->_getDefaultValue($requestDhl->getOrigState(), Shipment::XML_PATH_STORE_REGION_ID);
341  $origCity = $this->_getDefaultValue($requestDhl->getOrigCity(), Shipment::XML_PATH_STORE_CITY);
342  $origPostcode = $this->_getDefaultValue($requestDhl->getOrigPostcode(), Shipment::XML_PATH_STORE_ZIP);
343 
344  $requestDhl->setOrigCompanyName($origCompanyName)
345  ->setCountryId($origCountryId)
346  ->setOrigState($origState)
347  ->setOrigCity($origCity)
348  ->setOrigPostal($origPostcode);
349  $this->setRequest($requestDhl);
350 
351  $this->_result = $this->_getQuotes();
352  $this->_updateFreeMethodQuote($request);
353 
354  return $this->_result;
355  }
setRequest(\Magento\Framework\DataObject $request)
Definition: Carrier.php:409
_getDefaultValue($origValue, $pathToValue)
Definition: Carrier.php:307

◆ getAllowedMethods()

getAllowedMethods ( )

Get allowed shipping methods

Returns
string[]
Exceptions

Implements CarrierInterface.

Definition at line 513 of file Carrier.php.

514  {
515  $contentType = $this->getConfigData('content_type');
516 
517  if ($this->_isDomestic) {
518  $allowedMethods = array_merge(
519  explode(',', $this->getConfigData('doc_methods')),
520  explode(',', $this->getConfigData('nondoc_methods'))
521  );
522  } else {
523  switch ($contentType) {
525  $allowedMethods = explode(',', $this->getConfigData('doc_methods'));
526  break;
528  $allowedMethods = explode(',', $this->getConfigData('nondoc_methods'));
529  break;
530  default:
531  throw new \Magento\Framework\Exception\LocalizedException(__('Wrong Content Type'));
532  }
533  }
534  $methods = [];
535  foreach ($allowedMethods as $method) {
536  $methods[$method] = $this->getDhlProductTitle($method);
537  }
538 
539  return $methods;
540  }
__()
Definition: __.php:13
$methods
Definition: billing.phtml:71
$method
Definition: info.phtml:13

◆ getCode()

getCode (   $type,
  $code = '' 
)

Get configuration data of carrier

Parameters
string$type
string$code
Returns
array|bool

Definition at line 549 of file Carrier.php.

550  {
551  $codes = [
552  'unit_of_measure' => ['L' => __('Pounds'), 'K' => __('Kilograms')],
553  'unit_of_dimension' => ['I' => __('Inches'), 'C' => __('Centimeters')],
554  'unit_of_dimension_cut' => ['I' => __('inch'), 'C' => __('cm')],
555  'dimensions' => ['HEIGHT' => __('Height'), 'DEPTH' => __('Depth'), 'WIDTH' => __('Width')],
556  'size' => ['0' => __('Regular'), '1' => __('Specific')],
557  'dimensions_variables' => [
560  'POUND' => \Zend_Measure_Weight::POUND,
563  'KILOGRAM' => \Zend_Measure_Weight::KILOGRAM,
566  'INCH' => \Zend_Measure_Length::INCH,
569  'CENTIMETER' => \Zend_Measure_Length::CENTIMETER,
570  ],
571  ];
572 
573  if (!isset($codes[$type])) {
574  return false;
575  } elseif ('' === $code) {
576  return $codes[$type];
577  }
578 
579  $code = strtoupper($code);
580  if (!isset($codes[$type][$code])) {
581  return false;
582  } else {
583  return $codes[$type][$code];
584  }
585  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$type
Definition: item.phtml:13
$code
Definition: info.phtml:12

◆ getContainerTypes()

getContainerTypes ( \Magento\Framework\DataObject  $params = null)

Return container types of carrier

Parameters
\Magento\Framework\DataObject | null$params
Returns
array @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 1313 of file Carrier.php.

1314  {
1315  return [
1316  self::DHL_CONTENT_TYPE_DOC => __('Documents'),
1317  self::DHL_CONTENT_TYPE_NON_DOC => __('Non Documents')
1318  ];
1319  }
__()
Definition: __.php:13

◆ getCountryParams()

getCountryParams (   $countryCode)
protected

Get Country Params by Country Code

Parameters
string$countryCode
Returns
\Magento\Framework\DataObject
See also
$countryCode ISO 3166 Codes (Countries) A2

Definition at line 1232 of file Carrier.php.

1233  {
1234  if (empty($this->_countryParams)) {
1235  $etcPath = $this->_configReader->getModuleDir(Dir::MODULE_ETC_DIR, 'Magento_Dhl');
1236  $directoryRead = $this->readFactory->create($etcPath);
1237  $countriesXml = $directoryRead->readFile('countries.xml');
1238  $this->_countryParams = $this->_xmlElFactory->create(['data' => $countriesXml]);
1239  }
1240  if (isset($this->_countryParams->{$countryCode})) {
1241  $countryParams = new \Magento\Framework\DataObject($this->_countryParams->{$countryCode}->asArray());
1242  }
1243  return isset($countryParams) ? $countryParams : new \Magento\Framework\DataObject();
1244  }

◆ getDhlProducts()

getDhlProducts (   $doc)

Returns DHL shipment methods (depending on package content type, if necessary)

Parameters
string$docPackage content type (doc/non-doc) see DHL_CONTENT_TYPE_* constants
Returns
array

Definition at line 593 of file Carrier.php.

594  {
595  $docType = [
596  '2' => __('Easy shop'),
597  '5' => __('Sprintline'),
598  '6' => __('Secureline'),
599  '7' => __('Express easy'),
600  '9' => __('Europack'),
601  'B' => __('Break bulk express'),
602  'C' => __('Medical express'),
603  'D' => __('Express worldwide'),
604  'U' => __('Express worldwide'),
605  'K' => __('Express 9:00'),
606  'L' => __('Express 10:30'),
607  'G' => __('Domestic economy select'),
608  'W' => __('Economy select'),
609  'I' => __('Domestic express 9:00'),
610  'N' => __('Domestic express'),
611  'O' => __('Others'),
612  'R' => __('Globalmail business'),
613  'S' => __('Same day'),
614  'T' => __('Express 12:00'),
615  'X' => __('Express envelope'),
616  ];
617 
618  $nonDocType = [
619  '1' => __('Domestic express 12:00'),
620  '3' => __('Easy shop'),
621  '4' => __('Jetline'),
622  '8' => __('Express easy'),
623  'P' => __('Express worldwide'),
624  'Q' => __('Medical express'),
625  'E' => __('Express 9:00'),
626  'F' => __('Freight worldwide'),
627  'H' => __('Economy select'),
628  'J' => __('Jumbo box'),
629  'M' => __('Express 10:30'),
630  'V' => __('Europack'),
631  'Y' => __('Express 12:00'),
632  ];
633 
634  if ($this->_isDomestic) {
635  return $docType + $nonDocType;
636  }
637  if ($doc == self::DHL_CONTENT_TYPE_DOC) {
638  // Documents shipping
639  return $docType;
640  } else {
641  // Services for shipping non-documents cargo
642  return $nonDocType;
643  }
644  }
__()
Definition: __.php:13

◆ getDhlProductTitle()

getDhlProductTitle (   $code)

Returns title of DHL shipping method by its code

Parameters
string$codeOne-symbol code (see getDhlProducts())
Returns
bool @SuppressWarnings(PHPMD.BooleanGetMethodName)

Definition at line 653 of file Carrier.php.

654  {
655  $contentType = $this->getConfigData('content_type');
656  $dhlProducts = $this->getDhlProducts($contentType);
657 
658  return isset($dhlProducts[$code]) ? $dhlProducts[$code] : false;
659  }
$code
Definition: info.phtml:12

◆ getResult()

getResult ( )

Returns request result

Returns
Result|null

Definition at line 376 of file Carrier.php.

377  {
378  return $this->_result;
379  }

◆ getTracking()

getTracking (   $trackings)

Get tracking

Parameters
string|string[]$trackings
Returns
Result|null

Definition at line 1691 of file Carrier.php.

1692  {
1693  if (!is_array($trackings)) {
1694  $trackings = [$trackings];
1695  }
1696  $this->_getXMLTracking($trackings);
1697 
1698  return $this->_result;
1699  }

◆ isDutiable()

isDutiable (   $origCountryId,
  $destCountryId 
)
protected
Parameters
string$origCountryId
string$destCountryId
Returns
bool

Definition at line 1967 of file Carrier.php.

1968  {
1969  $this->_checkDomesticStatus($origCountryId, $destCountryId);
1970 
1971  return
1972  self::DHL_CONTENT_TYPE_NON_DOC == $this->getConfigData('content_type')
1973  || !$this->_isDomestic;
1974  }
_checkDomesticStatus($origCountryCode, $destCountryCode)
Definition: Carrier.php:1918

◆ proccessAdditionalValidation()

proccessAdditionalValidation ( \Magento\Framework\DataObject  $request)

Processing additional validation to check is carrier applicable.

Parameters
\Magento\Framework\DataObject$request
Returns
$this|\Magento\Framework\DataObject|boolean
Deprecated:
100.2.3

Definition at line 1268 of file Carrier.php.

1269  {
1270  return $this->processAdditionalValidation($request);
1271  }
processAdditionalValidation(\Magento\Framework\DataObject $request)
Definition: Carrier.php:1279

◆ processAdditionalValidation()

processAdditionalValidation ( \Magento\Framework\DataObject  $request)

Processing additional validation to check is carrier applicable.

Parameters
\Magento\Framework\DataObject$request
Returns
$this|\Magento\Framework\DataObject|boolean

Definition at line 1279 of file Carrier.php.

1280  {
1281  //Skip by item validation if there is no items in request
1282  if (!count($this->getAllItems($request))) {
1283  $this->_errors[] = __('There is no items in this order');
1284  }
1285 
1286  $countryParams = $this->getCountryParams(
1287  $this->_scopeConfig->getValue(
1289  \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1290  $request->getStoreId()
1291  )
1292  );
1293  if (!$countryParams->getData()) {
1294  $this->_errors[] = __('Please specify origin country.');
1295  }
1296 
1297  if (!empty($this->_errors)) {
1298  $this->debugErrors($this->_errors);
1299 
1300  return false;
1301  }
1302 
1303  return $this;
1304  }
__()
Definition: __.php:13
getCountryParams($countryCode)
Definition: Carrier.php:1232

◆ requestToShipment()

requestToShipment (   $request)

Do request to shipment

Parameters
\Magento\Shipping\Model\Shipment\Request$request
Returns
array|\Magento\Framework\DataObject
Exceptions

Implements AbstractCarrierInterface.

Definition at line 1887 of file Carrier.php.

1888  {
1889  $packages = $request->getPackages();
1890  if (!is_array($packages) || !$packages) {
1891  throw new \Magento\Framework\Exception\LocalizedException(__('No packages for request'));
1892  }
1894 
1895  $response = new \Magento\Framework\DataObject(
1896  [
1897  'info' => [
1898  [
1899  'tracking_number' => $result->getTrackingNumber(),
1900  'label_content' => $result->getShippingLabelContent(),
1901  ],
1902  ],
1903  ]
1904  );
1905 
1906  $request->setMasterTrackingId($result->getTrackingNumber());
1907 
1908  return $response;
1909  }
$response
Definition: 404.php:11
_doShipmentRequest(\Magento\Framework\DataObject $request)
Definition: Carrier.php:1252
__()
Definition: __.php:13

◆ setRequest()

setRequest ( \Magento\Framework\DataObject  $request)

Prepare and set request in property of current instance

Parameters
\Magento\Framework\DataObject$request
Returns
$this @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 409 of file Carrier.php.

410  {
411  $this->_request = $request;
412  $this->setStore($request->getStoreId());
413 
414  $requestObject = new \Magento\Framework\DataObject();
415 
416  $requestObject->setIsGenerateLabelReturn($request->getIsGenerateLabelReturn());
417 
418  $requestObject->setStoreId($request->getStoreId());
419 
420  if ($request->getLimitMethod()) {
421  $requestObject->setService($request->getLimitMethod());
422  }
423 
424  $requestObject = $this->_addParams($requestObject);
425 
426  if ($request->getDestPostcode()) {
427  $requestObject->setDestPostal($request->getDestPostcode());
428  }
429 
430  $requestObject->setOrigCountry(
432  )->setOrigCountryId(
434  );
435 
436  $shippingWeight = $request->getPackageWeight();
437 
438  $requestObject->setValue(sprintf('%.2f', $request->getPackageValue()))
439  ->setValueWithDiscount($request->getPackageValueWithDiscount())
440  ->setCustomsValue($request->getPackageCustomsValue())
441  ->setDestStreet($this->string->substr(str_replace("\n", '', $request->getDestStreet()), 0, 35))
442  ->setDestStreetLine2($request->getDestStreetLine2())
443  ->setDestCity($request->getDestCity())
444  ->setOrigCompanyName($request->getOrigCompanyName())
445  ->setOrigCity($request->getOrigCity())
446  ->setOrigPhoneNumber($request->getOrigPhoneNumber())
447  ->setOrigPersonName($request->getOrigPersonName())
448  ->setOrigEmail(
449  $this->_scopeConfig->getValue(
450  'trans_email/ident_general/email',
452  $requestObject->getStoreId()
453  )
454  )
455  ->setOrigCity($request->getOrigCity())
456  ->setOrigPostal($request->getOrigPostal())
457  ->setOrigStreetLine2($request->getOrigStreetLine2())
458  ->setDestPhoneNumber($request->getDestPhoneNumber())
459  ->setDestPersonName($request->getDestPersonName())
460  ->setDestCompanyName($request->getDestCompanyName());
461 
462  $originStreet2 = $this->_scopeConfig->getValue(
465  $requestObject->getStoreId()
466  );
467 
468  $requestObject->setOrigStreet($request->getOrigStreet() ? $request->getOrigStreet() : $originStreet2);
469 
470  if (is_numeric($request->getOrigState())) {
471  $requestObject->setOrigState($this->_regionFactory->create()->load($request->getOrigState())->getCode());
472  } else {
473  $requestObject->setOrigState($request->getOrigState());
474  }
475 
476  if ($request->getDestCountryId()) {
477  $destCountry = $request->getDestCountryId();
478  } else {
479  $destCountry = self::USA_COUNTRY_ID;
480  }
481 
482  // for DHL, Puerto Rico state for US will assume as Puerto Rico country
483  // for Puerto Rico, dhl will ship as international
484  if ($destCountry == self::USA_COUNTRY_ID
485  && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)
486  ) {
487  $destCountry = self::PUERTORICO_COUNTRY_ID;
488  }
489 
490  $requestObject->setDestCountryId($destCountry)
491  ->setDestState($request->getDestRegionCode())
492  ->setWeight($shippingWeight)
493  ->setFreeMethodWeight($request->getFreeMethodWeight())
494  ->setOrderShipment($request->getOrderShipment());
495 
496  if ($request->getPackageId()) {
497  $requestObject->setPackageId($request->getPackageId());
498  }
499 
500  $requestObject->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
501 
502  $this->setRawRequest($requestObject);
503 
504  return $this;
505  }
getCode($type, $code='')
Definition: Carrier.php:549
_addParams(\Magento\Framework\DataObject $requestObject)
Definition: Carrier.php:387
_getDefaultValue($origValue, $pathToValue)
Definition: Carrier.php:307

Field Documentation

◆ $_carrierHelper

$_carrierHelper
protected

Definition at line 158 of file Carrier.php.

◆ $_code

$_code = self::CODE
protected

Definition at line 99 of file Carrier.php.

◆ $_configReader

$_configReader
protected

Definition at line 173 of file Carrier.php.

◆ $_coreDate

$_coreDate
protected

Definition at line 163 of file Carrier.php.

◆ $_countryParams

$_countryParams
protected

Definition at line 78 of file Carrier.php.

◆ $_customizableContainerTypes

$_customizableContainerTypes = [self::DHL_CONTENT_TYPE_NON_DOC]
protected

Definition at line 52 of file Carrier.php.

◆ $_dateTime

$_dateTime
protected

Definition at line 188 of file Carrier.php.

◆ $_debugReplacePrivateDataKeys

$_debugReplacePrivateDataKeys
protected
Initial value:
= [
'SiteID', 'Password'
]

Definition at line 198 of file Carrier.php.

◆ $_errors

$_errors = []
protected

Definition at line 85 of file Carrier.php.

◆ $_freeMethod

$_freeMethod = 'free_method_nondoc'
protected

Definition at line 106 of file Carrier.php.

◆ $_httpClientFactory

$_httpClientFactory
protected

Definition at line 193 of file Carrier.php.

◆ $_isDomestic

$_isDomestic = false
protected

Definition at line 144 of file Carrier.php.

◆ $_isShippingLabelFlag

$_isShippingLabelFlag = false
protected

Definition at line 120 of file Carrier.php.

◆ $_maxWeight

$_maxWeight = 70
protected

Definition at line 113 of file Carrier.php.

◆ $_rates

$_rates = []
protected

Definition at line 92 of file Carrier.php.

◆ $_request

$_request
protected

Definition at line 64 of file Carrier.php.

◆ $_requestVariables

$_requestVariables
protected
Initial value:
= [
'id' => ['code' => 'dhl_id', 'setCode' => 'id'],
'password' => ['code' => 'dhl_password', 'setCode' => 'password'],
'account' => ['code' => 'dhl_account', 'setCode' => 'account_nbr'],
'shipping_key' => ['code' => 'dhl_shipping_key', 'setCode' => 'shipping_key'],
'shipping_intlkey' => ['code' => 'dhl_shipping_intl_key', 'setCode' => 'shipping_intl_key'],
'shipment_type' => ['code' => 'dhl_shipment_type', 'setCode' => 'shipment_type'],
'dutiable' => ['code' => 'dhl_dutiable', 'setCode' => 'dutiable'],
'dutypaymenttype' => ['code' => 'dhl_duty_payment_type', 'setCode' => 'duty_payment_type'],
'contentdesc' => ['code' => 'dhl_content_desc', 'setCode' => 'content_desc'],
]

Definition at line 127 of file Carrier.php.

◆ $_result

$_result
protected

Definition at line 71 of file Carrier.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 168 of file Carrier.php.

◆ $mathDivision

$mathDivision
protected

Definition at line 178 of file Carrier.php.

◆ $readFactory

$readFactory
protected

Definition at line 183 of file Carrier.php.

◆ $string

$string
protected

Definition at line 151 of file Carrier.php.

◆ CODE

const CODE = 'dhl'

Code of the carrier

Definition at line 57 of file Carrier.php.

◆ DHL_CONTENT_TYPE_DOC

const DHL_CONTENT_TYPE_DOC = 'D'

#+ Carrier Product indicator

Definition at line 31 of file Carrier.php.

◆ DHL_CONTENT_TYPE_NON_DOC

const DHL_CONTENT_TYPE_NON_DOC = 'N'

Definition at line 32 of file Carrier.php.

◆ DIMENSION_MIN_CM

const DIMENSION_MIN_CM = 3

#- #+ Minimum allowed values for shipping package dimensions

Definition at line 38 of file Carrier.php.

◆ DIMENSION_MIN_IN

const DIMENSION_MIN_IN = 1

Definition at line 39 of file Carrier.php.

◆ XML_PATH_EU_COUNTRIES_LIST

const XML_PATH_EU_COUNTRIES_LIST = 'general/country/eu_countries'

#- Config path to UE country list

Definition at line 45 of file Carrier.php.


The documentation for this class was generated from the following file: