128 'id' => [
'code' =>
'dhl_id',
'setCode' =>
'id'],
129 'password' => [
'code' =>
'dhl_password',
'setCode' =>
'password'],
130 'account' => [
'code' =>
'dhl_account',
'setCode' =>
'account_nbr'],
131 'shipping_key' => [
'code' =>
'dhl_shipping_key',
'setCode' =>
'shipping_key'],
132 'shipping_intlkey' => [
'code' =>
'dhl_shipping_intl_key',
'setCode' =>
'shipping_intl_key'],
133 'shipment_type' => [
'code' =>
'dhl_shipment_type',
'setCode' =>
'shipment_type'],
134 'dutiable' => [
'code' =>
'dhl_dutiable',
'setCode' =>
'dutiable'],
135 'dutypaymenttype' => [
'code' =>
'dhl_duty_payment_type',
'setCode' =>
'duty_payment_type'],
136 'contentdesc' => [
'code' =>
'dhl_content_desc',
'setCode' =>
'content_desc'],
207 private $xmlValidator;
243 \
Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory,
244 \
Magento\Shipping\Model\Rate\ResultFactory $rateFactory,
246 \
Magento\Shipping\Model\Tracking\ResultFactory $trackFactory,
247 \
Magento\Shipping\Model\Tracking\
Result\ErrorFactory $trackErrorFactory,
248 \
Magento\Shipping\Model\Tracking\
Result\StatusFactory $trackStatusFactory,
249 \
Magento\Directory\Model\RegionFactory $regionFactory,
250 \
Magento\Directory\Model\CountryFactory $countryFactory,
251 \
Magento\Directory\Model\CurrencyFactory $currencyFactory,
252 \
Magento\Directory\Helper\Data $directoryData,
255 \
Magento\Framework\Stdlib\DateTime\DateTime $coreDate,
262 \
Magento\Framework\HTTP\ZendClientFactory $httpClientFactory,
267 $this->_carrierHelper = $carrierHelper;
268 $this->_coreDate = $coreDate;
270 $this->_configReader = $configReader;
274 $this->_httpClientFactory = $httpClientFactory;
293 if ($this->
getConfigData(
'content_type') == self::DHL_CONTENT_TYPE_DOC) {
294 $this->_freeMethod =
'free_method_doc';
296 $this->xmlValidator = $xmlValidator
310 $origValue = $this->_scopeConfig->getValue(
333 $this->setStore($requestDhl->getStoreId());
336 $requestDhl->getOrigCompanyName(),
344 $requestDhl->setOrigCompanyName($origCompanyName)
345 ->setCountryId($origCountryId)
346 ->setOrigState($origState)
347 ->setOrigCity($origCity)
348 ->setOrigPostal($origPostcode);
365 $this->_rawRequest->setFreeMethodRequest(
true);
367 $this->_rawRequest->setWeight($freeWeight);
368 $this->_rawRequest->setService($freeMethod);
389 foreach ($this->_requestVariables as
$code => $objectCode) {
390 if ($this->_request->getDhlId()) {
391 $value = $this->_request->getData($objectCode[
'code']);
395 $requestObject->setData($objectCode[
'setCode'],
$value);
398 return $requestObject;
412 $this->setStore(
$request->getStoreId());
414 $requestObject = new \Magento\Framework\DataObject();
416 $requestObject->setIsGenerateLabelReturn(
$request->getIsGenerateLabelReturn());
418 $requestObject->setStoreId(
$request->getStoreId());
421 $requestObject->setService(
$request->getLimitMethod());
424 $requestObject = $this->
_addParams($requestObject);
427 $requestObject->setDestPostal(
$request->getDestPostcode());
430 $requestObject->setOrigCountry(
436 $shippingWeight =
$request->getPackageWeight();
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())
449 $this->_scopeConfig->getValue(
450 'trans_email/ident_general/email',
452 $requestObject->getStoreId()
455 ->setOrigCity(
$request->getOrigCity())
456 ->setOrigPostal(
$request->getOrigPostal())
457 ->setOrigStreetLine2(
$request->getOrigStreetLine2())
458 ->setDestPhoneNumber(
$request->getDestPhoneNumber())
459 ->setDestPersonName(
$request->getDestPersonName())
460 ->setDestCompanyName(
$request->getDestCompanyName());
462 $originStreet2 = $this->_scopeConfig->getValue(
465 $requestObject->getStoreId()
468 $requestObject->setOrigStreet(
$request->getOrigStreet() ?
$request->getOrigStreet() : $originStreet2);
470 if (is_numeric(
$request->getOrigState())) {
471 $requestObject->setOrigState($this->_regionFactory->create()->load(
$request->getOrigState())->
getCode());
473 $requestObject->setOrigState(
$request->getOrigState());
477 $destCountry =
$request->getDestCountryId();
484 if ($destCountry == self::USA_COUNTRY_ID
490 $requestObject->setDestCountryId($destCountry)
491 ->setDestState(
$request->getDestRegionCode())
492 ->setWeight($shippingWeight)
493 ->setFreeMethodWeight(
$request->getFreeMethodWeight())
494 ->setOrderShipment(
$request->getOrderShipment());
497 $requestObject->setPackageId(
$request->getPackageId());
500 $requestObject->setBaseSubtotalInclTax(
$request->getBaseSubtotalInclTax());
517 if ($this->_isDomestic) {
518 $allowedMethods = array_merge(
523 switch ($contentType) {
525 $allowedMethods = explode(
',', $this->
getConfigData(
'doc_methods'));
528 $allowedMethods = explode(
',', $this->
getConfigData(
'nondoc_methods'));
531 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Wrong Content Type'));
535 foreach ($allowedMethods as
$method) {
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' => [
573 if (!isset($codes[
$type])) {
576 return $codes[
$type];
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'),
612 'R' =>
__(
'Globalmail business'),
613 'S' =>
__(
'Same day'),
614 'T' =>
__(
'Express 12:00'),
615 'X' =>
__(
'Express envelope'),
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'),
634 if ($this->_isDomestic) {
635 return $docType + $nonDocType;
637 if ($doc == self::DHL_CONTENT_TYPE_DOC) {
658 return isset($dhlProducts[
$code]) ? $dhlProducts[
$code] :
false;
669 protected function _getWeight($weight, $maxWeight =
false, $configWeightUnit =
false)
673 }
elseif ($configWeightUnit) {
674 $configWeightUnit = $this->
getCode(
'dimensions_variables', $configWeightUnit);
676 $configWeightUnit = $this->
getCode(
677 'dimensions_variables',
684 if ($configWeightUnit != $countryWeightUnit) {
685 $weight = $this->_carrierHelper->convertMeasureWeight(
692 return sprintf(
'%.3f', $weight);
704 $allItems = $this->_request->getAllItems();
707 foreach ($allItems as
$item) {
712 $qty =
$item->getQty();
717 if (
$item->getParentItem()) {
718 if (!
$item->getParentItem()->getProduct()->getShipmentType()) {
721 if (
$item->getIsQtyDecimal()) {
722 $qty =
$item->getParentItem()->getQty();
724 $qty =
$item->getParentItem()->getQty() *
$item->getQty();
728 $itemWeight =
$item->getWeight();
731 $stockItemDo = $this->stockRegistry->getStockItem(
$productId,
$item->getStore()->getWebsiteId());
732 $isDecimalDivided = $stockItemDo->getIsDecimalDivided();
733 if ($isDecimalDivided) {
734 if ($stockItemDo->getEnableQtyIncrements()
735 && $stockItemDo->getQtyIncrements()
737 $itemWeight = $itemWeight * $stockItemDo->getQtyIncrements();
738 $qty = round(
$item->getWeight() / $itemWeight * $qty);
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);
748 $decimalItems[] = [
'weight' => $weightItem,
'qty' => 1];
750 $checkWeight =
false;
754 $itemWeight = $itemWeight *
$item->getQty();
758 if ($checkWeight && $this->
_getWeight($itemWeight) > $this->
_getWeight($this->_maxWeight,
true)) {
763 && !
$item->getParentItem()
764 &&
$item->getIsQtyDecimal()
770 if (!empty($decimalItems)) {
771 foreach ($decimalItems as $decimalItem) {
772 $fullItems = array_merge(
774 array_fill(0, $decimalItem[
'qty'] * $qty, $decimalItem[
'weight'])
778 $fullItems = array_merge($fullItems, array_fill(0, $qty, $this->
_getWeight($itemWeight)));
795 $divideOrderWeight = (string)$this->
getConfigData(
'divide_order_weight');
796 $nodePieces = $nodeBkgDetails->addChild(
'Pieces',
'',
'');
800 if ($divideOrderWeight && !empty(
$items)) {
801 $maxWeight = $this->
_getWeight($this->_maxWeight,
true);
804 $reverseOrderItems =
$items;
805 arsort($reverseOrderItems);
807 foreach ($reverseOrderItems as $key => $weight) {
808 if (!isset(
$items[$key])) {
812 $sumWeight = $weight;
813 foreach (
$items as $key => $weight) {
814 if ($sumWeight + $weight < $maxWeight) {
816 $sumWeight += $weight;
817 }
elseif ($sumWeight + $weight > $maxWeight) {
819 $nodePiece = $nodePieces->addChild(
'Piece',
'',
'');
820 $nodePiece->addChild(
'PieceID', $numberOfPieces);
822 $nodePiece->addChild(
'Weight', sprintf(
'%.3f', $sumWeight));
827 $sumWeight += $weight;
828 $nodePiece = $nodePieces->addChild(
'Piece',
'',
'');
829 $nodePiece->addChild(
'PieceID', $numberOfPieces);
831 $nodePiece->addChild(
'Weight', sprintf(
'%.3f', $sumWeight));
837 if ($sumWeight > 0) {
839 $nodePiece = $nodePieces->addChild(
'Piece',
'',
'');
840 $nodePiece->addChild(
'PieceID', $numberOfPieces);
842 $nodePiece->addChild(
'Weight', sprintf(
'%.3f', $sumWeight));
845 $nodePiece = $nodePieces->addChild(
'Piece',
'',
'');
846 $nodePiece->addChild(
'PieceID', 1);
848 $nodePiece->addChild(
'Weight', $this->
_getWeight($this->_rawRequest->getWeight()));
855 $this->_numBoxes = $numberOfPieces;
867 if (!$configWeightUnit) {
868 $configWeightUnit = $this->
getCode(
869 'dimensions_variables',
873 $configWeightUnit = $this->
getCode(
'dimensions_variables', $configWeightUnit);
884 if ($configDimensionUnit != $countryDimensionUnit) {
885 $dimension = $this->_carrierHelper->convertMeasureDimension(
887 $configDimensionUnit,
888 $countryDimensionUnit
892 return sprintf(
'%.3f', $dimension);
909 if ($sizeChecker && $height && $depth && $width) {
910 $nodePiece->addChild(
'Height', $height);
911 $nodePiece->addChild(
'Depth', $depth);
912 $nodePiece->addChild(
'Width', $width);
929 $date = date(self::REQUEST_DATE_FORMAT, strtotime($this->
_getShipDate() .
" +{$offset} days"));
935 $debugPoint[
'from_cache'] = $responseBody ===
null;
937 if ($debugPoint[
'from_cache']) {
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);
948 $this->
_debug($debugPoint);
953 $this->
_debug($debugPoint);
956 $this->_errors[$e->getCode()] = $e->getMessage();
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));
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');
995 $nodeServiceHeader = $nodeRequest->addChild(
'ServiceHeader');
996 $nodeServiceHeader->addChild(
'SiteID', (
string)$this->
getConfigData(
'id'));
997 $nodeServiceHeader->addChild(
'Password', (
string)$this->
getConfigData(
'password'));
999 $nodeFrom = $nodeGetQuote->addChild(
'From');
1000 $nodeFrom->addChild(
'CountryCode', $rawRequest->getOrigCountryId());
1001 $nodeFrom->addChild(
'Postalcode', $rawRequest->getOrigPostal());
1002 $nodeFrom->addChild(
'City', $rawRequest->getOrigCity());
1004 $nodeBkgDetails = $nodeGetQuote->addChild(
'BkgDetails');
1005 $nodeBkgDetails->addChild(
'PaymentCountryCode', $rawRequest->getOrigCountryId());
1006 $nodeBkgDetails->addChild(
1008 (
new \DateTime())->format(\
Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)
1010 $nodeBkgDetails->addChild(
'ReadyTime',
'PT' . (
int)(
string)$this->
getConfigData(
'ready_time') .
'H00M');
1013 $nodeBkgDetails->addChild(
'WeightUnit', $this->
_getWeightUnit());
1017 $nodeBkgDetails->addChild(
'PaymentAccountNumber', (
string)$this->
getConfigData(
'account'));
1019 $nodeTo = $nodeGetQuote->addChild(
'To');
1020 $nodeTo->addChild(
'CountryCode', $rawRequest->getDestCountryId());
1021 $nodeTo->addChild(
'Postalcode', $rawRequest->getDestPostal());
1022 $nodeTo->addChild(
'City', $rawRequest->getDestCity());
1024 if ($this->
isDutiable($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId())) {
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()));
1047 $requestXml->GetQuote->BkgDetails->Date = $date;
1062 $responseError =
__(
'The response is in wrong format.');
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) {
1070 }
elseif (isset($xml->AirwayBillNumber)) {
1073 $this->_errors[] = $responseError;
1076 if ($e->getCode() > 0) {
1077 $this->_errors[$e->getCode()] = $e->getMessage();
1079 $this->_errors[] = $e->getMessage();
1083 $result = $this->_rateFactory->create();
1084 if ($this->_rates) {
1085 foreach ($this->_rates as
$rate) {
1089 $rate = $this->_rateMethodFactory->create();
1090 $rate->setCarrier(self::CODE);
1099 if (!empty($this->_errors)) {
1100 if ($this->_isShippingLabelFlag) {
1101 throw new \Magento\Framework\Exception\LocalizedException($responseError);
1118 protected function _addRate(\SimpleXMLElement $shipmentDetails)
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())
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();
1134 if ($currencyCode != $baseCurrencyCode) {
1136 $currency = $this->_currencyFactory->create();
1137 $rates = $currency->getCurrencyRates($currencyCode, [$baseCurrencyCode]);
1138 if (!empty(
$rates) && isset(
$rates[$baseCurrencyCode])) {
1140 $totalEstimate = $totalEstimate *
$rates[$baseCurrencyCode];
1142 $rates = $currency->getCurrencyRates($baseCurrencyCode, [$currencyCode]);
1144 $totalEstimate = $totalEstimate /
$rates[$currencyCode];
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).',
1156 if ($totalEstimate) {
1158 'term' => $dhlProductDescription,
1159 'price_total' => $this->
getMethodPrice($totalEstimate, $dhlProduct),
1161 if (!empty($this->_rates)) {
1162 foreach ($this->_rates as
$product) {
1170 $this->_rates[] = [
'service' => $dhlProduct,
'data' =>
$data];
1172 $this->_errors[] =
__(
"Zero shipping charge for '%1'", $dhlProductDescription);
1175 $dhlProductDescription =
false;
1176 if (isset($shipmentDetails->GlobalProductCode)) {
1177 $dhlProductDescription = $this->
getDhlProductTitle((
string)$shipmentDetails->GlobalProductCode);
1179 $dhlProductDescription = $dhlProductDescription ? $dhlProductDescription :
__(
"DHL");
1180 $this->_errors[] =
__(
"Zero shipping charge for '%1'", $dhlProductDescription);
1194 $countryId = $this->_rawRequest->getOrigCountryId();
1196 if (empty($measureUnit)) {
1197 throw new \Magento\Framework\Exception\LocalizedException(
1198 __(
"Cannot identify measure unit for %1", $countryId)
1202 return $measureUnit;
1213 $countryId = $this->_rawRequest->getOrigCountryId();
1215 if (empty($weightUnit)) {
1216 throw new \Magento\Framework\Exception\LocalizedException(
1217 __(
"Cannot identify weight unit for %1", $countryId)
1234 if (empty($this->_countryParams)) {
1236 $directoryRead = $this->readFactory->create($etcPath);
1237 $countriesXml = $directoryRead->readFile(
'countries.xml');
1238 $this->_countryParams = $this->_xmlElFactory->create([
'data' => $countriesXml]);
1240 if (isset($this->_countryParams->{$countryCode})) {
1241 $countryParams = new \Magento\Framework\DataObject($this->_countryParams->{$countryCode}->asArray());
1243 return isset($countryParams) ? $countryParams : new \Magento\Framework\DataObject();
1254 $this->_prepareShipmentRequest(
$request);
1255 $this->_mapRequestToShipment(
$request);
1258 return $this->_doRequest();
1270 return $this->processAdditionalValidation(
$request);
1282 if (!count($this->getAllItems(
$request))) {
1283 $this->_errors[] =
__(
'There is no items in this order');
1286 $countryParams = $this->getCountryParams(
1287 $this->_scopeConfig->getValue(
1288 Shipment::XML_PATH_STORE_COUNTRY_ID,
1293 if (!$countryParams->getData()) {
1294 $this->_errors[] =
__(
'Please specify origin country.');
1297 if (!empty($this->_errors)) {
1298 $this->debugErrors($this->_errors);
1316 self::DHL_CONTENT_TYPE_DOC =>
__(
'Documents'),
1317 self::DHL_CONTENT_TYPE_NON_DOC =>
__(
'Non Documents')
1334 $packages =
$request->getPackages();
1335 foreach ($packages as &$piece) {
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);
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();
1353 $customsValue += $piece[
'params'][
'customs_value'];
1354 $packageWeight += $piece[
'params'][
'weight'];
1358 ->setPackageWeight($packageWeight)
1359 ->setPackageValue($customsValue)
1360 ->setValueWithDiscount($customsValue)
1361 ->setPackageCustomsValue($customsValue)
1362 ->setFreeMethodWeight(0);
1373 return $dimensionUnit ==
"CENTIMETER" ? self::DIMENSION_MIN_CM : self::DIMENSION_MIN_IN;
1385 protected function _doRequest()
1387 $rawRequest = $this->_request;
1389 $originRegion = $this->getCountryParams(
1390 $this->_scopeConfig->getValue(
1391 Shipment::XML_PATH_STORE_COUNTRY_ID,
1397 if (!$originRegion) {
1398 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Wrong Region'));
1401 if ($originRegion ==
'AM') {
1405 $xmlStr =
'<?xml version="1.0" encoding="UTF-8"?>' .
1406 '<req:ShipmentValidateRequest' .
1408 ' xmlns:req="http://www.dhl.com"' .
1409 ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
1410 ' xsi:schemaLocation="http://www.dhl.com ship-val-req' .
1411 ($originRegion ?
'_' .
1412 $originRegion :
'') .
1414 $xml = $this->_xmlElFactory->create([
'data' => $xmlStr]);
1416 $nodeRequest = $xml->addChild(
'Request',
'',
'');
1417 $nodeServiceHeader = $nodeRequest->addChild(
'ServiceHeader');
1418 $nodeServiceHeader->addChild(
'SiteID', (
string)$this->getConfigData(
'id'));
1419 $nodeServiceHeader->addChild(
'Password', (
string)$this->getConfigData(
'password'));
1421 if (!$originRegion) {
1422 $xml->addChild(
'RequestedPickupTime',
'N',
'');
1424 if ($originRegion !==
'AP') {
1425 $xml->addChild(
'NewShipper',
'N',
'');
1427 $xml->addChild(
'LanguageCode',
'EN',
'');
1428 $xml->addChild(
'PiecesEnabled',
'Y',
'');
1431 $nodeBilling = $xml->addChild(
'Billing',
'',
'');
1432 $nodeBilling->addChild(
'ShipperAccountNumber', (
string)$this->getConfigData(
'account'));
1439 $nodeBilling->addChild(
'ShippingPaymentType',
'S');
1444 $nodeBilling->addChild(
'BillingAccountNumber', (
string)$this->getConfigData(
'account'));
1445 $nodeBilling->addChild(
'DutyPaymentType',
'S');
1446 $nodeBilling->addChild(
'DutyAccountNumber', (
string)$this->getConfigData(
'account'));
1449 $nodeConsignee = $xml->addChild(
'Consignee',
'',
'');
1451 $companyName = $rawRequest->getRecipientContactCompanyName() ? $rawRequest
1452 ->getRecipientContactCompanyName() : $rawRequest
1453 ->getRecipientContactPersonName();
1455 $nodeConsignee->addChild(
'CompanyName', substr($companyName, 0, 35));
1457 $address = $rawRequest->getRecipientAddressStreet1() .
' ' . $rawRequest->getRecipientAddressStreet2();
1460 foreach (
$address as $addressLine) {
1461 $nodeConsignee->addChild(
'AddressLine', $addressLine);
1464 $nodeConsignee->addChild(
'AddressLine',
$address);
1467 $nodeConsignee->addChild(
'City', $rawRequest->getRecipientAddressCity());
1468 if ($originRegion !==
'AP') {
1469 $nodeConsignee->addChild(
'Division', $rawRequest->getRecipientAddressStateOrProvinceCode());
1471 $nodeConsignee->addChild(
'PostalCode', $rawRequest->getRecipientAddressPostalCode());
1472 $nodeConsignee->addChild(
'CountryCode', $rawRequest->getRecipientAddressCountryCode());
1473 $nodeConsignee->addChild(
1475 $this->getCountryParams($rawRequest->getRecipientAddressCountryCode())->getName()
1477 $nodeContact = $nodeConsignee->addChild(
'Contact');
1478 $nodeContact->addChild(
'PersonName', substr($rawRequest->getRecipientContactPersonName(), 0, 34));
1479 $nodeContact->addChild(
'PhoneNumber', substr($rawRequest->getRecipientContactPhoneNumber(), 0, 24));
1486 $nodeCommodity = $xml->addChild(
'Commodity',
'',
'');
1487 $nodeCommodity->addChild(
'CommodityCode',
'1');
1490 if ($this->isDutiable(
1491 $rawRequest->getShipperAddressCountryCode(),
1492 $rawRequest->getRecipientAddressCountryCode()
1494 $nodeDutiable = $xml->addChild(
'Dutiable',
'',
'');
1495 $nodeDutiable->addChild(
1497 sprintf(
"%.2F", $rawRequest->getOrderShipment()->getOrder()->getSubtotal())
1499 $baseCurrencyCode = $this->_storeManager->getWebsite($rawRequest->getWebsiteId())->getBaseCurrencyCode();
1500 $nodeDutiable->addChild(
'DeclaredCurrency', $baseCurrencyCode);
1508 $nodeReference = $xml->addChild(
'Reference',
'',
'');
1509 $nodeReference->addChild(
'ReferenceID',
'shipment reference');
1510 $nodeReference->addChild(
'ReferenceType',
'St');
1513 $this->_shipmentDetails($xml, $rawRequest, $originRegion);
1516 $nodeShipper = $xml->addChild(
'Shipper',
'',
'');
1517 $nodeShipper->addChild(
'ShipperID', (
string)$this->getConfigData(
'account'));
1518 $nodeShipper->addChild(
'CompanyName', $rawRequest->getShipperContactCompanyName());
1519 if ($originRegion !==
'AP') {
1520 $nodeShipper->addChild(
'RegisteredAccount', (
string)$this->getConfigData(
'account'));
1523 $address = $rawRequest->getShipperAddressStreet1() .
' ' . $rawRequest->getShipperAddressStreet2();
1526 foreach (
$address as $addressLine) {
1527 $nodeShipper->addChild(
'AddressLine', $addressLine);
1530 $nodeShipper->addChild(
'AddressLine',
$address);
1533 $nodeShipper->addChild(
'City', $rawRequest->getShipperAddressCity());
1534 if ($originRegion !==
'AP') {
1535 $nodeShipper->addChild(
'Division', $rawRequest->getShipperAddressStateOrProvinceCode());
1537 $nodeShipper->addChild(
'PostalCode', $rawRequest->getShipperAddressPostalCode());
1538 $nodeShipper->addChild(
'CountryCode', $rawRequest->getShipperAddressCountryCode());
1539 $nodeShipper->addChild(
1541 $this->getCountryParams($rawRequest->getShipperAddressCountryCode())->getName()
1543 $nodeContact = $nodeShipper->addChild(
'Contact',
'',
'');
1544 $nodeContact->addChild(
'PersonName', substr($rawRequest->getShipperContactPersonName(), 0, 34));
1545 $nodeContact->addChild(
'PhoneNumber', substr($rawRequest->getShipperContactPhoneNumber(), 0, 24));
1547 $xml->addChild(
'LabelImageFormat',
'PDF',
'');
1554 $responseBody = $this->_getCachedQuotes(
$request);
1555 if ($responseBody ===
null) {
1556 $debugData = [
'request' => $this->filterDebugData(
$request)];
1559 $client = $this->_httpClientFactory->create();
1560 $client->setUri((
string)$this->getConfigData(
'gateway_url'));
1561 $client->setConfig([
'maxredirects' => 0,
'timeout' => 30]);
1563 $responseBody = $client->request(\
Magento\Framework\HTTP\ZendClient::POST)->getBody();
1564 $responseBody = utf8_decode($responseBody);
1565 $debugData[
'result'] = $this->filterDebugData($responseBody);
1566 $this->_setCachedQuotes(
$request, $responseBody);
1567 }
catch (\Exception $e) {
1568 $this->_errors[$e->getCode()] = $e->getMessage();
1571 $this->_debug($debugData);
1573 $this->_isShippingLabelFlag =
true;
1575 return $this->_parseResponse($responseBody);
1590 $nodeShipmentDetails = $xml->addChild(
'ShipmentDetails',
'',
'');
1591 $nodeShipmentDetails->addChild(
'NumberOfPieces', count($rawRequest->getPackages()));
1593 if ($originRegion) {
1594 $nodeShipmentDetails->addChild(
1596 $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode()
1600 $nodePieces = $nodeShipmentDetails->addChild(
'Pieces',
'',
'');
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';
1616 $nodePiece->addChild(
'PieceID', ++
$i);
1617 $nodePiece->addChild(
'PackageType', $packageType);
1618 $nodePiece->addChild(
'Weight', sprintf(
'%.1f', $package[
'params'][
'weight']));
1621 if (!$originRegion) {
1622 $nodePiece->addChild(
'Width', round(
$params[
'width']));
1623 $nodePiece->addChild(
'Height', round(
$params[
'height']));
1624 $nodePiece->addChild(
'Depth', round(
$params[
'length']));
1626 $nodePiece->addChild(
'Depth', round(
$params[
'length']));
1627 $nodePiece->addChild(
'Width', round(
$params[
'width']));
1628 $nodePiece->addChild(
'Height', round(
$params[
'height']));
1632 foreach ($package[
'items'] as
$item) {
1635 $nodePiece->addChild(
'PieceContents', substr(implode(
',',
$content), 0, 34));
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';
1655 $nodeShipmentDetails->addChild(
'PackageType', $packageType);
1656 if ($this->isDutiable($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId())) {
1657 $nodeShipmentDetails->addChild(
'IsDutiable',
'Y');
1659 $nodeShipmentDetails->addChild(
1661 $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode()
1664 if ($package[
'params'][
'container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
1665 $packageType =
'CP';
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());
1679 $nodeShipmentDetails->addChild(
'DoorTo',
'DD');
1680 $nodeShipmentDetails->addChild(
'Date', $this->_coreDate->date(
'Y-m-d'));
1681 $nodeShipmentDetails->addChild(
'Contents',
'DHL Parcel TEST');
1693 if (!is_array($trackings)) {
1694 $trackings = [$trackings];
1696 $this->_getXMLTracking($trackings);
1698 return $this->_result;
1707 protected function _getXMLTracking($trackings)
1709 $xmlStr =
'<?xml version="1.0" encoding="UTF-8"?>' .
1710 '<req:KnownTrackingRequest' .
1711 ' xmlns:req="http://www.dhl.com"' .
1712 ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' .
1713 ' xsi:schemaLocation="http://www.dhl.com TrackingRequestKnown.xsd" />';
1715 $xml = $this->_xmlElFactory->create([
'data' => $xmlStr]);
1717 $requestNode = $xml->addChild(
'Request',
'',
'');
1718 $serviceHeaderNode = $requestNode->addChild(
'ServiceHeader',
'',
'');
1719 $serviceHeaderNode->addChild(
'SiteID', (
string)$this->getConfigData(
'id'));
1720 $serviceHeaderNode->addChild(
'Password', (
string)$this->getConfigData(
'password'));
1722 $xml->addChild(
'LanguageCode',
'EN',
'');
1723 foreach ($trackings as $tracking) {
1724 $xml->addChild(
'AWBNumber', $tracking,
'');
1731 $xml->addChild(
'LevelOfDetails',
'ALL_CHECK_POINTS',
'');
1748 $responseBody = $this->_getCachedQuotes(
$request);
1749 if ($responseBody ===
null) {
1750 $debugData = [
'request' => $this->filterDebugData(
$request)];
1753 $client = $this->_httpClientFactory->create();
1754 $client->setUri((
string)$this->getConfigData(
'gateway_url'));
1755 $client->setConfig([
'maxredirects' => 0,
'timeout' => 30]);
1757 $responseBody = $client->request(\
Magento\Framework\HTTP\ZendClient::POST)->getBody();
1758 $debugData[
'result'] = $this->filterDebugData($responseBody);
1759 $this->_setCachedQuotes(
$request, $responseBody);
1760 }
catch (\Exception $e) {
1761 $this->_errors[$e->getCode()] = $e->getMessage();
1764 $this->_debug($debugData);
1767 $this->_parseXmlTrackingResponse($trackings, $responseBody);
1781 $errorTitle =
__(
'Unable to retrieve tracking');
1785 $xml = $this->parseXml(
$response, \
Magento\Shipping\Model\Simplexml\Element::class);
1786 if (!is_object($xml)) {
1787 $errorTitle =
__(
'Response is in the wrong format');
1790 && (isset($xml->Response->Status->ActionStatus)
1791 && $xml->Response->Status->ActionStatus ==
'Failure' 1792 || isset($xml->GetQuoteResponse->Note->Condition))
1794 if (isset($xml->Response->Status->Condition)) {
1795 $nodeCondition = $xml->Response->Status->Condition;
1797 $code = isset($nodeCondition->ConditionCode) ? (string)$nodeCondition->ConditionCode : 0;
1798 $data = isset($nodeCondition->ConditionData) ? (string)$nodeCondition->ConditionData :
'';
1800 }
elseif (is_object($xml) && is_object($xml->AWBInfo)) {
1801 foreach ($xml->AWBInfo as $awbinfo) {
1803 $trackNum = isset($awbinfo->AWBNumber) ? (string)$awbinfo->AWBNumber :
'';
1804 if (!is_object($awbinfo) || !$awbinfo->ShipmentInfo) {
1805 $this->_errors[$trackNum] =
__(
'Unable to retrieve tracking');
1808 $shipmentInfo = $awbinfo->ShipmentInfo;
1810 if ($shipmentInfo->ShipmentDesc) {
1811 $awbinfoData[
'service'] = (string)$shipmentInfo->ShipmentDesc;
1814 $awbinfoData[
'weight'] = (string)$shipmentInfo->Weight .
' ' . (
string)$shipmentInfo->WeightUnit;
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;
1828 $awbinfoData[
'progressdetail'] = $packageProgress;
1830 $resultArr[$trackNum] = $awbinfoData;
1835 $result = $this->_trackFactory->create();
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);
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);
1873 if ($handlingType == AbstractCarrier::HANDLING_TYPE_PERCENT) {
1874 return $cost + $cost * $this->_numBoxes * $handlingFee / 100;
1877 return $cost + $this->_numBoxes * $handlingFee;
1889 $packages =
$request->getPackages();
1890 if (!is_array($packages) || !$packages) {
1891 throw new \Magento\Framework\Exception\LocalizedException(
__(
'No packages for request'));
1895 $response = new \Magento\Framework\DataObject(
1899 'tracking_number' =>
$result->getTrackingNumber(),
1900 'label_content' =>
$result->getShippingLabelContent(),
1920 $this->_isDomestic =
false;
1922 $origCountry = (string)$this->getCountryParams($origCountryCode)->getData(
'name');
1923 $destCountry = (string)$this->getCountryParams($destCountryCode)->getData(
'name');
1924 $isDomestic = (string)$this->getCountryParams($destCountryCode)->getData(
'domestic');
1926 if (($origCountry == $destCountry && $isDomestic)
1927 || ($this->_carrierHelper->isCountryInEU($origCountryCode)
1928 && $this->_carrierHelper->isCountryInEU($destCountryCode)
1931 $this->_isDomestic =
true;
1934 return $this->_isDomestic;
1946 $result = new \Magento\Framework\DataObject();
1948 if (!isset($xml->AirwayBillNumber) || !isset($xml->LabelImage->OutputImage)) {
1949 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Unable to retrieve shipping label'));
1951 $result->setTrackingNumber((
string)$xml->AirwayBillNumber);
1952 $labelContent = (string)$xml->LabelImage->OutputImage;
1953 $result->setShippingLabelContent(base64_decode($labelContent));
1955 throw new \Magento\Framework\Exception\LocalizedException(
__($e->getMessage()));
1969 $this->_checkDomesticStatus($origCountryId, $destCountryId);
1972 self::DHL_CONTENT_TYPE_NON_DOC == $this->getConfigData(
'content_type')
1973 || !$this->_isDomestic;
proccessAdditionalValidation(\Magento\Framework\DataObject $request)
_addRate(\SimpleXMLElement $shipmentDetails)
processAdditionalValidation(\Magento\Framework\DataObject $request)
if(!defined( 'PHP_VERSION_ID')||!(PHP_VERSION_ID===70002||PHP_VERSION_ID===70004||PHP_VERSION_ID >=70006))
elseif(isset( $params[ 'redirect_parent']))
const PUERTORICO_COUNTRY_ID
getContainerTypes(\Magento\Framework\DataObject $params=null)
const DHL_CONTENT_TYPE_DOC
_checkDomesticStatus($origCountryCode, $destCountryCode)
_getPerpackagePrice($cost, $handlingType, $handlingFee)
const UNAVAILABLE_DATE_LOOK_FORWARD
_doShipmentRequest(\Magento\Framework\DataObject $request)
getTotalNumOfBoxes($weight)
setRequest(\Magento\Framework\DataObject $request)
_setFreeMethodRequest($freeMethod)
const HANDLING_ACTION_PERORDER
getMethodPrice($cost, $method='')
const XML_PATH_STORE_COUNTRY_ID
isDutiable($origCountryId, $destCountryId)
const DHL_CONTENT_TYPE_NON_DOC
const XML_PATH_STORE_REGION_ID
__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)
$_debugReplacePrivateDataKeys
requestToShipment($request)
_getCachedQuotes($requestParams)
_parseResponse($response)
_addParams(\Magento\Framework\DataObject $requestObject)
_setCachedQuotes($requestParams, $response)
const XML_PATH_EU_COUNTRIES_LIST
const XML_PATH_STORE_CITY
_getDimension($dimension, $configWeightUnit=false)
_shipmentDetails($xml, $rawRequest, $originRegion='')
_addDimension($nodePiece)
_getQuotesFromServer($request)
_setQuotesRequestXmlDate(\SimpleXMLElement $requestXml, $date)
const XML_PATH_STORE_ADDRESS2
_updateFreeMethodQuote($request)
_prepareShippingLabelContent(\SimpleXMLElement $xml)
_makePieces(\Magento\Shipping\Model\Simplexml\Element $nodeBkgDetails)
_getDefaultValue($origValue, $pathToValue)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
getDhlProductTitle($code)
_mapRequestToShipment(\Magento\Framework\DataObject $request)
_getMinDimension($dimensionUnit)
getCountryParams($countryCode)
collectRates(RateRequest $request)
$_customizableContainerTypes
_parseXmlTrackingResponse($trackings, $response)
_getWeight($weight, $maxWeight=false, $configWeightUnit=false)