Skip to content

Commit e468b8e

Browse files
author
Viktor Paladiychuk
committed
Merge remote-tracking branch 'origin/develop' into S60PR
2 parents e63d916 + 444e252 commit e468b8e

File tree

37 files changed

+326
-169
lines changed

37 files changed

+326
-169
lines changed

app/code/Magento/Dhl/Block/Adminhtml/Unitofmeasure.php

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,45 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
96
namespace Magento\Dhl\Block\Adminhtml;
107

8+
use Magento\Dhl\Model;
9+
use Magento\Shipping\Helper;
10+
use Magento\Backend\Block\Template\Context;
11+
use Magento\Config\Block\System\Config\Form\Field;
12+
use Magento\Framework\Data\Form\Element\AbstractElement;
13+
1114
/**
1215
* Frontend model for DHL shipping methods for documentation
1316
*/
14-
class Unitofmeasure extends \Magento\Config\Block\System\Config\Form\Field
17+
class Unitofmeasure extends Field
1518
{
1619
/**
1720
* Carrier helper
1821
*
19-
* @var \Magento\Shipping\Helper\Carrier
22+
* @var Helper\Carrier
2023
*/
21-
protected $_carrierHelper;
24+
protected $carrierHelper;
2225

2326
/**
24-
* @var \Magento\Dhl\Model\Carrier
27+
* @var Model\Carrier
2528
*/
2629
protected $carrierDhl;
2730

2831
/**
29-
* @param \Magento\Backend\Block\Template\Context $context
30-
* @param \Magento\Dhl\Model\Carrier $carrierDhl
31-
* @param \Magento\Shipping\Helper\Carrier $carrierHelper
32+
* @param Context $context
33+
* @param Model\Carrier $carrierDhl
34+
* @param Helper\Carrier $carrierHelper
3235
* @param array $data
3336
*/
3437
public function __construct(
35-
\Magento\Backend\Block\Template\Context $context,
36-
\Magento\Dhl\Model\Carrier $carrierDhl,
37-
\Magento\Shipping\Helper\Carrier $carrierHelper,
38+
Context $context,
39+
Model\Carrier $carrierDhl,
40+
Helper\Carrier $carrierHelper,
3841
array $data = []
3942
) {
4043
$this->carrierDhl = $carrierDhl;
41-
$this->_carrierHelper = $carrierHelper;
44+
$this->carrierHelper = $carrierHelper;
4245
parent::__construct($context, $data);
4346
}
4447

@@ -51,29 +54,25 @@ public function _construct()
5154
{
5255
parent::_construct();
5356

54-
$carrierModel = $this->carrierDhl;
57+
$this->setInch($this->carrierDhl->getCode('unit_of_dimension_cut', 'I'));
58+
$this->setCm($this->carrierDhl->getCode('unit_of_dimension_cut', 'C'));
5559

56-
$this->setInch($this->escapeJsQuote($carrierModel->getCode('unit_of_dimension_cut', 'I')));
57-
$this->setCm($this->escapeJsQuote($carrierModel->getCode('unit_of_dimension_cut', 'C')));
58-
59-
$this->setHeight($this->escapeJsQuote($carrierModel->getCode('dimensions', 'height')));
60-
$this->setDepth($this->escapeJsQuote($carrierModel->getCode('dimensions', 'depth')));
61-
$this->setWidth($this->escapeJsQuote($carrierModel->getCode('dimensions', 'width')));
60+
$this->setHeight($this->carrierDhl->getCode('dimensions', 'height'));
61+
$this->setDepth($this->carrierDhl->getCode('dimensions', 'depth'));
62+
$this->setWidth($this->carrierDhl->getCode('dimensions', 'width'));
6263

6364
$kgWeight = 70;
6465

6566
$this->setDivideOrderWeightNoteKg(
66-
$this->escapeJsQuote(
67-
__(
68-
'Select this to allow DHL to optimize shipping charges by splitting the order if it exceeds %1 %2.',
69-
$kgWeight,
70-
'kg'
71-
)
67+
__(
68+
'Select this to allow DHL to optimize shipping charges by splitting the order if it exceeds %1 %2.',
69+
$kgWeight,
70+
'kg'
7271
)
7372
);
7473

7574
$weight = round(
76-
$this->_carrierHelper->convertMeasureWeight(
75+
$this->carrierHelper->convertMeasureWeight(
7776
$kgWeight,
7877
\Zend_Measure_Weight::KILOGRAM,
7978
\Zend_Measure_Weight::POUND
@@ -82,12 +81,10 @@ public function _construct()
8281
);
8382

8483
$this->setDivideOrderWeightNoteLbp(
85-
$this->escapeJsQuote(
86-
__(
87-
'Select this to allow DHL to optimize shipping charges by splitting the order if it exceeds %1 %2.',
88-
$weight,
89-
'pounds'
90-
)
84+
__(
85+
'Select this to allow DHL to optimize shipping charges by splitting the order if it exceeds %1 %2.',
86+
$weight,
87+
'pounds'
9188
)
9289
);
9390

@@ -97,10 +94,10 @@ public function _construct()
9794
/**
9895
* Retrieve Element HTML fragment
9996
*
100-
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
97+
* @param AbstractElement $element
10198
* @return string
10299
*/
103-
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
100+
protected function _getElementHtml(AbstractElement $element)
104101
{
105102
return parent::_getElementHtml($element) . $this->_toHtml();
106103
}

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/Dhl/view/adminhtml/templates/unitofmeasure.phtml

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,34 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
?>
9-
<?php
106
/**
11-
* @var $block \Magento\Dhl\Block\Adminhtml\Unitofmeasure
7+
* @var \Magento\Dhl\Block\Adminhtml\Unitofmeasure $block
128
*/
139
?>
1410
<script>
15-
require(['prototype'], function(){
16-
1711
//<![CDATA[
18-
function changeDimensions()
19-
{
20-
var dimensionUnit = '(<?php /* @escapeNotVerified */ echo $block->getInch(); ?>)';
21-
var dhlUnitOfMeasureNote = '<?php /* @escapeNotVerified */ echo $block->getDivideOrderWeightNoteLbp(); ?>';
22-
if ($("carriers_dhl_unit_of_measure").value == "K") {
23-
dimensionUnit = '(<?php /* @escapeNotVerified */ echo $block->getCm(); ?>)';
24-
dhlUnitOfMeasureNote = '<?php /* @escapeNotVerified */ echo $block->getDivideOrderWeightNoteKg(); ?>';
25-
}
26-
$$('[for="carriers_dhl_height"]')[0].innerHTML = '<?php /* @escapeNotVerified */ echo $block->getHeight(); ?> ' + dimensionUnit;
27-
$$('[for="carriers_dhl_depth"]')[0].innerHTML = '<?php /* @escapeNotVerified */ echo $block->getDepth(); ?> ' + dimensionUnit;
28-
$$('[for="carriers_dhl_width"]')[0].innerHTML = '<?php /* @escapeNotVerified */ echo $block->getWidth(); ?> ' + dimensionUnit;
12+
require(["prototype"], function(){
13+
function changeDimensions() {
14+
var dimensionUnit = "(<?php echo $block->escapeHtml($block->getInch()); ?>)";
15+
var dhlUnitOfMeasureNote = "<?php echo $block->escapeHtml($block->getDivideOrderWeightNoteLbp()); ?>";
16+
if ($("carriers_dhl_unit_of_measure").value == "K") {
17+
dimensionUnit = "(<?php echo $block->escapeHtml($block->getCm()); ?>)";
18+
dhlUnitOfMeasureNote = "<?php echo $block->escapeHtml($block->getDivideOrderWeightNoteKg()); ?>";
19+
}
20+
$$('[for="carriers_dhl_height"]')[0].innerHTML = "<?php
21+
echo $block->escapeHtml($block->getHeight()); ?> " + dimensionUnit;
22+
$$('[for="carriers_dhl_depth"]')[0].innerHTML = "<?php
23+
echo $block->escapeHtml($block->getDepth()); ?> " + dimensionUnit;
24+
$$('[for="carriers_dhl_width"]')[0].innerHTML = "<?php
25+
echo $block->escapeHtml($block->getWidth()); ?> " + dimensionUnit;
2926

30-
$('carriers_dhl_divide_order_weight').next().down().innerHTML = dhlUnitOfMeasureNote;
31-
}
32-
33-
window.changeDimensions = changeDimensions;
34-
35-
document.observe("dom:loaded", function() {
36-
$("carriers_dhl_unit_of_measure").observe("change", changeDimensions);
37-
changeDimensions();
27+
$("carriers_dhl_divide_order_weight").next().down().innerHTML = dhlUnitOfMeasureNote;
28+
}
29+
window.changeDimensions = changeDimensions;
30+
document.observe("dom:loaded", function() {
31+
$("carriers_dhl_unit_of_measure").observe("change", changeDimensions);
32+
changeDimensions();
33+
});
3834
});
3935
//]]>
40-
41-
});
4236
</script>

app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ class Csv extends \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter
3333
*/
3434
protected $_fileHandler;
3535

36+
/**
37+
* {@inheritdoc }
38+
*/
39+
public function __construct(\Magento\Framework\Filesystem $filesystem, $destination = null)
40+
{
41+
register_shutdown_function([$this, 'destruct']);
42+
parent::__construct($filesystem, $destination);
43+
}
44+
3645
/**
3746
* Object destructor.
47+
*
48+
* @return void
3849
*/
39-
public function __destruct()
50+
public function destruct()
4051
{
4152
if (is_object($this->_fileHandler)) {
4253
$this->_fileHandler->close();

app/code/Magento/ImportExport/Model/Import/Source/Csv.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(
4444
$delimiter = ',',
4545
$enclosure = '"'
4646
) {
47+
register_shutdown_function([$this, 'destruct']);
4748
try {
4849
$this->_file = $directory->openFile($directory->getRelativePath($file), 'r');
4950
} catch (\Magento\Framework\Exception\FileSystemException $e) {
@@ -58,8 +59,10 @@ public function __construct(
5859

5960
/**
6061
* Close file handle
62+
*
63+
* @return void
6164
*/
62-
public function __destruct()
65+
public function destruct()
6366
{
6467
if (is_object($this->_file)) {
6568
$this->_file->close();

0 commit comments

Comments
 (0)