Skip to content

Commit b8926cd

Browse files
author
Ievgen Sentiabov
committed
Merge branch 'DHL' of github.corp.ebay.com:magento-mpi/magento2ce into MAGETWO-43005
2 parents 2a200ea + fde44a6 commit b8926cd

File tree

3 files changed

+81
-18
lines changed

3 files changed

+81
-18
lines changed

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

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin
3939
const DIMENSION_MIN_IN = 1;
4040
/**#@-*/
4141

42+
/**
43+
* Config path to UE country list
44+
*/
45+
const XML_PATH_EU_COUNTRIES_LIST = 'general/country/eu_countries';
46+
4247
/**
4348
* Container types that could be customized
4449
*
@@ -924,7 +929,7 @@ protected function _getQuotes()
924929
$bodyXml = $this->_xmlElFactory->create(['data' => $responseBody]);
925930
$code = $bodyXml->xpath('//GetQuoteResponse/Note/Condition/ConditionCode');
926931
if (isset($code[0]) && (int)$code[0] == self::CONDITION_CODE_SERVICE_DATE_UNAVAILABLE) {
927-
$debugPoint['info'] = sprintf(__('DHL service is not available on %s.'), $date);
932+
$debugPoint['info'] = sprintf(__("DHL service is not available at %s date"), $date);
928933
} else {
929934
break;
930935
}
@@ -1001,9 +1006,7 @@ protected function _buildQuotesRequestXml()
10011006
$nodeTo->addChild('Postalcode', $rawRequest->getDestPostal());
10021007
$nodeTo->addChild('City', $rawRequest->getDestCity());
10031008

1004-
$this->_checkDomesticStatus($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId());
1005-
1006-
if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC && !$this->_isDomestic) {
1009+
if ($this->isDutiable($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId())) {
10071010
// IsDutiable flag and Dutiable node indicates that cargo is not a documentation
10081011
$nodeBkgDetails->addChild('IsDutiable', 'Y');
10091012
$nodeDutiable = $nodeGetQuote->addChild('Dutiable');
@@ -1042,7 +1045,7 @@ protected function _setQuotesRequestXmlDate(\SimpleXMLElement $requestXml, $date
10421045
*/
10431046
protected function _parseResponse($response)
10441047
{
1045-
$responseError = __('Please enter a response in the correct format.');
1048+
$responseError = __('The response is in wrong format.');
10461049

10471050
if (strlen(trim($response)) > 0) {
10481051
if (strpos(trim($response), '<?xml') === 0) {
@@ -1162,7 +1165,7 @@ protected function _addRate(\SimpleXMLElement $shipmentDetails)
11621165
if (!isset($rates[$currencyCode]) || !$totalEstimate) {
11631166
$totalEstimate = false;
11641167
$this->_errors[] = __(
1165-
'We had to skip DHL method %1 because we can\'t find exchange rate %2 (Base Currency).',
1168+
'We had to skip DHL method %1 because we couldn\'t find exchange rate %2 (Base Currency).',
11661169
$currencyCode,
11671170
$baseCurrencyCode
11681171
);
@@ -1284,7 +1287,7 @@ public function proccessAdditionalValidation(\Magento\Framework\DataObject $requ
12841287
{
12851288
//Skip by item validation if there is no items in request
12861289
if (!count($this->getAllItems($request))) {
1287-
$this->_errors[] = __('There are no items in this order.');
1290+
$this->_errors[] = __('There is no items in this order');
12881291
}
12891292

12901293
$countryParams = $this->getCountryParams(
@@ -1295,7 +1298,7 @@ public function proccessAdditionalValidation(\Magento\Framework\DataObject $requ
12951298
)
12961299
);
12971300
if (!$countryParams->getData()) {
1298-
$this->_errors[] = __('Please specify an origin country.');
1301+
$this->_errors[] = __('Please, specify origin country');
12991302
}
13001303

13011304
if (!empty($this->_errors)) {
@@ -1342,7 +1345,7 @@ protected function _mapRequestToShipment(\Magento\Framework\DataObject $request)
13421345
if ($params['width'] || $params['length'] || $params['height']) {
13431346
$minValue = $this->_getMinDimension($params['dimension_units']);
13441347
if ($params['width'] < $minValue || $params['length'] < $minValue || $params['height'] < $minValue) {
1345-
$message = __('Height, width and length should be equal or greater than %1.', $minValue);
1348+
$message = __('Height, width and length should be equal or greater than %1', $minValue);
13461349
throw new \Magento\Framework\Exception\LocalizedException($message);
13471350
}
13481351
}
@@ -1487,13 +1490,11 @@ protected function _doRequest()
14871490
$nodeCommodity = $xml->addChild('Commodity', '', '');
14881491
$nodeCommodity->addChild('CommodityCode', '1');
14891492

1490-
$this->_checkDomesticStatus(
1493+
/** Dutiable */
1494+
if ($this->isDutiable(
14911495
$rawRequest->getShipperAddressCountryCode(),
14921496
$rawRequest->getRecipientAddressCountryCode()
1493-
);
1494-
1495-
/** Dutiable */
1496-
if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC && !$this->_isDomestic) {
1497+
)) {
14971498
$nodeDutiable = $xml->addChild('Dutiable', '', '');
14981499
$nodeDutiable->addChild(
14991500
'DeclaredValue',
@@ -1651,7 +1652,7 @@ protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
16511652
$packageType = 'CP';
16521653
}
16531654
$nodeShipmentDetails->addChild('PackageType', $packageType);
1654-
if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC) {
1655+
if ($this->isDutiable($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId())) {
16551656
$nodeShipmentDetails->addChild('IsDutiable', 'Y');
16561657
}
16571658
$nodeShipmentDetails->addChild(
@@ -1775,7 +1776,7 @@ protected function _getXMLTracking($trackings)
17751776
*/
17761777
protected function _parseXmlTrackingResponse($trackings, $response)
17771778
{
1778-
$errorTitle = __('For some reason we can\'t retrieve tracking info right now.');
1779+
$errorTitle = __('Unable to retrieve tracking');
17791780
$resultArr = [];
17801781

17811782
if (strlen(trim($response)) > 0) {
@@ -1799,7 +1800,7 @@ protected function _parseXmlTrackingResponse($trackings, $response)
17991800
$awbinfoData = [];
18001801
$trackNum = isset($awbinfo->AWBNumber) ? (string)$awbinfo->AWBNumber : '';
18011802
if (!is_object($awbinfo) || !$awbinfo->ShipmentInfo) {
1802-
$this->_errors[$trackNum] = __('For some reason we can\'t retrieve tracking info right now.');
1803+
$this->_errors[$trackNum] = __('Unable to retrieve tracking');
18031804
continue;
18041805
}
18051806
$shipmentInfo = $awbinfo->ShipmentInfo;
@@ -1920,7 +1921,11 @@ protected function _checkDomesticStatus($origCountryCode, $destCountryCode)
19201921
$destCountry = (string)$this->getCountryParams($destCountryCode)->getData('name');
19211922
$isDomestic = (string)$this->getCountryParams($destCountryCode)->getData('domestic');
19221923

1923-
if ($origCountry == $destCountry && $isDomestic) {
1924+
if (($origCountry == $destCountry && $isDomestic)
1925+
|| ($this->_carrierHelper->isCountryInEU($origCountryCode)
1926+
&& $this->_carrierHelper->isCountryInEU($destCountryCode)
1927+
)
1928+
) {
19241929
$this->_isDomestic = true;
19251930
}
19261931

@@ -1950,4 +1955,19 @@ protected function _prepareShippingLabelContent(\SimpleXMLElement $xml)
19501955

19511956
return $result;
19521957
}
1958+
1959+
/**
1960+
* @param string $origCountryId
1961+
* @param string $destCountryId
1962+
*
1963+
* @return bool
1964+
*/
1965+
protected function isDutiable($origCountryId, $destCountryId)
1966+
{
1967+
$this->_checkDomesticStatus($origCountryId, $destCountryId);
1968+
1969+
return
1970+
self::DHL_CONTENT_TYPE_NON_DOC == $this->getConfigData('content_type')
1971+
&& !$this->_isDomestic;
1972+
}
19531973
}

app/code/Magento/Shipping/Helper/Carrier.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class Carrier extends \Magento\Framework\App\Helper\AbstractHelper
1515
*/
1616
const XML_PATH_CARRIERS_ROOT = 'carriers';
1717

18+
/**
19+
* Config path to UE country list
20+
*/
21+
const XML_PATH_EU_COUNTRIES_LIST = 'general/country/eu_countries';
22+
1823
/**
1924
* Locale interface
2025
*
@@ -141,4 +146,25 @@ public function getMeasureDimensionName($key)
141146
}
142147
return '';
143148
}
149+
150+
/**
151+
* Check whether specified country is in EU countries list
152+
*
153+
* @param string $countryCode
154+
* @param null|int $storeId
155+
* @return bool
156+
*/
157+
public function isCountryInEU($countryCode, $storeId = null)
158+
{
159+
$euCountries = explode(
160+
',',
161+
$this->scopeConfig->getValue(
162+
self::XML_PATH_EU_COUNTRIES_LIST,
163+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
164+
$storeId
165+
)
166+
);
167+
168+
return in_array($countryCode, $euCountries);
169+
}
144170
}

app/code/Magento/Shipping/Test/Unit/Helper/CarrierTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,21 @@ public function testGetCarrierConfigValue()
8787
);
8888
$this->assertEquals($configValue, $this->helper->getCarrierConfigValue($carrierCode, $configPath));
8989
}
90+
91+
public function testIsCountryInEU()
92+
{
93+
$this->scopeConfig->expects(
94+
$this->exactly(2)
95+
)->method(
96+
'getValue'
97+
)->with(
98+
'general/country/eu_countries',
99+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
100+
)->will(
101+
$this->returnValue("GB")
102+
);
103+
104+
$this->assertEquals(true, $this->helper->isCountryInEU("GB"));
105+
$this->assertEquals(false, $this->helper->isCountryInEU("US"));
106+
}
90107
}

0 commit comments

Comments
 (0)