Skip to content

Commit 7c5c08d

Browse files
committed
MAGETWO-35076: Impossible to place order with DHL EU shipping method
1 parent 0c03986 commit 7c5c08d

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ protected function _parseResponse($response)
10341034

10351035
if (strlen(trim($response)) > 0) {
10361036
if (strpos(trim($response), '<?xml') === 0) {
1037-
$xml = simplexml_load_string($response);
1037+
$xml = $this->parseXml($response);
10381038
if (is_object($xml)) {
10391039
if (in_array($xml->getName(), ['ErrorResponse', 'ShipmentValidateErrorResponse'])
10401040
|| isset($xml->GetQuoteResponse->Note->Condition)
@@ -1775,7 +1775,7 @@ protected function _parseXmlTrackingResponse($trackings, $response)
17751775
$resultArr = [];
17761776

17771777
if (strlen(trim($response)) > 0) {
1778-
$xml = simplexml_load_string($response);
1778+
$xml = $this->parseXml($response);
17791779
if (!is_object($xml)) {
17801780
$errorTitle = __('Response is in the wrong format');
17811781
}

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ protected function _parseXmlResponse($response)
706706
$priceArr = [];
707707

708708
if (strlen(trim($response)) > 0) {
709-
if ($xml = $this->_parseXml($response)) {
709+
if ($xml = $this->parseXml($response)) {
710710
if (is_object($xml->Error) && is_object($xml->Error->Message)) {
711711
$errorTitle = (string)$xml->Error->Message;
712712
} elseif (is_object($xml->SoftError) && is_object($xml->SoftError->Message)) {
@@ -760,27 +760,6 @@ protected function _parseXmlResponse($response)
760760
return $result;
761761
}
762762

763-
/**
764-
* Parse XML string and return XML document object or false
765-
*
766-
* @param string $xmlContent
767-
* @return \Magento\Shipping\Model\Simplexml\Element|bool
768-
* @throws \Exception
769-
*/
770-
protected function _parseXml($xmlContent)
771-
{
772-
try {
773-
try {
774-
return simplexml_load_string($xmlContent);
775-
} catch (\Exception $e) {
776-
throw new \Exception(__('Failed to parse xml document: %1', $xmlContent));
777-
}
778-
} catch (\Exception $e) {
779-
$this->_logger->critical($e);
780-
return false;
781-
}
782-
}
783-
784763
/**
785764
* Get configuration data of carrier
786765
*

app/code/Magento/Shipping/Model/Carrier/AbstractCarrierOnline.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,25 @@ public function getMethodPrice($cost, $method = '')
607607
$cost
608608
);
609609
}
610+
611+
/**
612+
* Parse XML string and return XML document object or false
613+
*
614+
* @param string $xmlContent
615+
* @return \Magento\Shipping\Model\Simplexml\Element|bool
616+
* @throws \Exception
617+
*/
618+
public function parseXml($xmlContent)
619+
{
620+
try {
621+
try {
622+
return simplexml_load_string($xmlContent);
623+
} catch (\Exception $e) {
624+
throw new \Exception(__('Failed to parse xml document: %1', $xmlContent));
625+
}
626+
} catch (\Exception $e) {
627+
$this->_logger->critical($e);
628+
return false;
629+
}
630+
}
610631
}

app/code/Magento/Shipping/Test/Unit/Model/Carrier/AbstractCarrierOnlineTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,12 @@ public function testComposePackages()
104104

105105
$this->carrier->proccessAdditionalValidation($request);
106106
}
107+
108+
public function testParseXml()
109+
{
110+
$xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetResponse><value>42</value>></GetResponse>";
111+
$simpleXmlElement = $this->carrier->parseXml($xmlString);
112+
$this->assertEquals('GetResponse', $simpleXmlElement->getName());
113+
$this->assertEquals(42, (int)$simpleXmlElement->value);
114+
}
107115
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ protected function _parseXmlResponse($response)
512512
$response
513513
);
514514
}
515-
$xml = simplexml_load_string($response);
515+
$xml = $this->parseXml($response);
516516

517517
if (is_object($xml)) {
518518
$allowedMethods = explode(',', $this->getConfigData('allowed_methods'));
@@ -1042,7 +1042,7 @@ protected function _parseXmlTrackingResponse($trackingvalue, $response)
10421042
$resultArr = [];
10431043
if (strlen(trim($response)) > 0) {
10441044
if (strpos(trim($response), '<?xml') === 0) {
1045-
$xml = simplexml_load_string($response);
1045+
$xml = $this->parseXml($response);
10461046
if (is_object($xml)) {
10471047
if (isset($xml->Number) && isset($xml->Description) && (string)$xml->Description != '') {
10481048
$errorTitle = (string)$xml->Description;
@@ -1869,7 +1869,7 @@ protected function _doShipmentRequest(\Magento\Framework\Object $request)
18691869
$client->setParameterGet('XML', $requestXml);
18701870
$response = $client->request()->getBody();
18711871

1872-
$response = simplexml_load_string($response);
1872+
$response = $this->parseXml($response);
18731873
if ($response === false || $response->getName() == 'Error') {
18741874
$debugData['result'] = [
18751875
'error' => $response->Description,

0 commit comments

Comments
 (0)