Skip to content

Commit 8a6974a

Browse files
author
gwharton
committed
Changed logic to obtain tax information from response to get rid of maths.
Previously the routine obtained the base cost, and then if taxes existed, it added the tax on to get the total. Now the function checks for the presence of the "TotalChargesWithTaxes" field. If present and the "Request Tax-Inclusive Rate" option is set, then the total is obtained from the "TotalChargesWithTaxes" field. If not present, or the "Request Tax-Inclusive Rate" option is not set, then the total is obtained from the original field which does not include tax. Also moved the setting of the "responseCurrencyCode" variable into the same logic. This ensures that the correct response currency code is always set correctly based on the value returned from UPS. Previously "responseCurrencyCode" would only have ever been set correctly if negotiated rates were never used.
1 parent 3872d94 commit 8a6974a

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -825,32 +825,43 @@ protected function _parseXmlResponse($xmlResponse)
825825
if (in_array($code, $allowedMethods)) {
826826
//The location of tax information is in a different place depending on whether we are using negotiated rates or not
827827
if ($negotiatedActive) {
828-
$includeTaxesArr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment/NegotiatedRates/TaxCharges");
828+
$includeTaxesArr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment/NegotiatedRates/NetSummaryCharges/TotalChargesWithTaxes");
829829
$includeTaxesActive = $this->getConfigFlag(
830830
'include_taxes'
831831
) && !empty($includeTaxesArr);
832-
$cost = (double)$shipElement->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue;
833832
if ($includeTaxesActive) {
834-
$taxes = (double)$shipElement->NegotiatedRates->TaxCharges->MonetaryValue;
835-
$cost += $taxes;
833+
$cost = $shipElement->NegotiatedRates->NetSummaryCharges->TotalChargesWithTaxes->MonetaryValue;
834+
$responseCurrencyCode = $this->mapCurrencyCode(
835+
(string)$shipElement->NegotiatedRates->NetSummaryCharges->TotalChargesWithTaxes->CurrencyCode
836+
);
837+
}
838+
else {
839+
$cost = $shipElement->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue;
840+
$responseCurrencyCode = $this->mapCurrencyCode(
841+
(string)$shipElement->NegotiatedRates->NetSummaryCharges->GrandTotal->CurrencyCode
842+
);
836843
}
837844
} else {
838-
$includeTaxesArr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment/TaxCharges");
845+
$includeTaxesArr = $xml->getXpath("//RatingServiceSelectionResponse/RatedShipment/TotalChargesWithTaxes");
839846
$includeTaxesActive = $this->getConfigFlag(
840847
'include_taxes'
841848
) && !empty($includeTaxesArr);
842-
$cost = (double)$shipElement->TotalCharges->MonetaryValue;
843849
if ($includeTaxesActive) {
844-
$taxes = (double)$shipElement->TaxCharges->MonetaryValue;
845-
$cost += $taxes;
850+
$cost = $shipElement->TotalChargesWithTaxes->MonetaryValue;
851+
$responseCurrencyCode = $this->mapCurrencyCode(
852+
(string)$shipElement->TotalChargesWithTaxes->CurrencyCode
853+
);
854+
}
855+
else {
856+
$cost = $shipElement->TotalCharges->MonetaryValue;
857+
$responseCurrencyCode = $this->mapCurrencyCode(
858+
(string)$shipElement->TotalCharges->CurrencyCode
859+
);
846860
}
847861
}
848862

849863
//convert price with Origin country currency code to base currency code
850864
$successConversion = true;
851-
$responseCurrencyCode = $this->mapCurrencyCode(
852-
(string)$shipElement->TotalCharges->CurrencyCode
853-
);
854865
if ($responseCurrencyCode) {
855866
if (in_array($responseCurrencyCode, $allowedCurrencies)) {
856867
$cost = (double)$cost * $this->_getBaseCurrencyRate($responseCurrencyCode);

0 commit comments

Comments
 (0)