Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the tax free price calculation if price display is set to fixed #2531

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ public function getTaxFreeTotal()
if (!isset($this->arrCache['taxFreeTotal'])) {
$arrSurcharges = $this->getSurcharges();

if (Config::PRICE_DISPLAY_GROSS === $this->getConfig()->priceDisplay) {
if (\in_array($this->getConfig()->getPriceDisplay(), [Config::PRICE_DISPLAY_GROSS, Config::PRICE_DISPLAY_FIXED], true)) {
$fltAmount = $this->getTotal();

foreach ($arrSurcharges as $objSurcharge) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,26 +337,41 @@ protected static function buildSurcharge($strClass, $strLabel, $objSource, Isoto

if ($intTaxClass == -1) {
$objSurcharge->applySplittedTax($objCollection, $objSource);
} elseif ($intTaxClass > 0) {
} elseif ($intTaxClass > 0 && ($objTaxClass = TaxClass::findByPk($intTaxClass)) !== null) {

/** @var TaxClass $objTaxClass */
if (($objTaxClass = TaxClass::findByPk($intTaxClass)) !== null) {
$fltPrice = $objSurcharge->total_price;
$fltNetPrice = $objSurcharge->total_price;
$arrAddresses = array(
'billing' => $objCollection->getBillingAddress(),
'shipping' => $objCollection->getShippingAddress(),
);

/** @var TaxRate $objIncludes */
if (
($objIncludes = $objTaxClass->getRelated('includes')) !== null
&& $objIncludes->isApplicable($fltPrice, $arrAddresses)
) {
$fltNetPrice -= $objIncludes->calculateAmountIncludedInPrice($fltPrice);
}

/** @var TaxRate $objIncludes */
if (($objIncludes = $objTaxClass->getRelated('includes')) !== null) {
/** @var TaxClass $objTaxClass */
if (Config::PRICE_DISPLAY_FIXED === $objCollection->getConfig()->getPriceDisplay()) {
if (($objRates = $objTaxClass->getRelated('rates')) !== null) {

$fltPrice = $objSurcharge->total_price;
$arrAddresses = array(
'billing' => $objCollection->getBillingAddress(),
'shipping' => $objCollection->getShippingAddress(),
);
/** @var \Isotope\Model\TaxRate $objTaxRate */
foreach ($objRates as $objTaxRate) {
if ($objTaxRate->isApplicable($objSurcharge->total_price, $arrAddresses)) {
$fltNetPrice -= $objTaxRate->calculateAmountIncludedInPrice($objSurcharge->total_price);

if ($objIncludes->isApplicable($fltPrice, $arrAddresses)) {
$fltTax = $objIncludes->calculateAmountIncludedInPrice($fltPrice);
$objSurcharge->tax_free_total_price = $fltPrice - $fltTax;
if ($objTaxRate->stop) {
break;
}
}
}
}
}

$objSurcharge->tax_free_total_price = $fltNetPrice;
}

return $objSurcharge;
Expand Down
33 changes: 29 additions & 4 deletions system/modules/isotope/library/Isotope/Model/TaxClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function calculatePrice($fltPrice, array $arrAddresses = null)
{
switch (Isotope::getConfig()->getPriceDisplay()) {
case Config::PRICE_DISPLAY_NET:
return $this->calculateNetPrice($fltPrice);
return $this->calculateNetPrice($fltPrice, $arrAddresses);

case Config::PRICE_DISPLAY_GROSS:
return $this->calculateGrossPrice($fltPrice, $arrAddresses);
Expand All @@ -90,14 +90,39 @@ public function calculatePrice($fltPrice, array $arrAddresses = null)
*
* @return float
*/
public function calculateNetPrice($fltPrice)
public function calculateNetPrice($fltPrice, array $arrAddresses = null)
{
if (!\is_array($arrAddresses)) {
$arrAddresses = array(
'billing' => Isotope::getCart()->getBillingAddress(),
'shipping' => Isotope::getCart()->getShippingAddress(),
);
}

$fltNetPrice = $fltPrice;

/** @var \Isotope\Model\TaxRate $objIncludes */
if (($objIncludes = $this->getRelated('includes')) !== null) {
$fltPrice -= $objIncludes->calculateAmountIncludedInPrice($fltPrice);
$fltNetPrice -= $objIncludes->calculateAmountIncludedInPrice($fltPrice);
}

return $fltPrice;
if (Config::PRICE_DISPLAY_FIXED === Isotope::getConfig()->getPriceDisplay()) {
if (($objRates = $this->getRelated('rates')) !== null) {

/** @var \Isotope\Model\TaxRate $objTaxRate */
foreach ($objRates as $objTaxRate) {
if ($objTaxRate->isApplicable($fltPrice, $arrAddresses)) {
$fltNetPrice -= $objTaxRate->calculateAmountIncludedInPrice($fltPrice);

if ($objTaxRate->stop) {
break;
}
}
}
}
}

return $fltNetPrice;
}


Expand Down