Skip to content

Commit

Permalink
Fix taxes as surcharge
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhj committed Aug 4, 2021
1 parent 2bad989 commit 893d3c4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Dto/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,26 @@ public function __construct(ProductCollectionItem $item, IsotopeProductCollectio
$taxFreePrice = (int) round($item->getTaxFreePrice() * 100);
$price = (int) round($item->getPrice() * 100);

$this->total_tax_amount = $price - $taxFreePrice;
if (null !== $taxRate) {
if ($price > $taxFreePrice) {
// Taxes are included in the price
$this->total_tax_amount = (int) round($this->total_amount - $this->total_amount * 10000 / (10000 + $taxRate));
} else {
// Taxes are added as surcharge
$taxRate = 0;
}
}

// No distinct tax rate was found, maybe multiple taxes apply, simply calculate the tax_rate
if (null === $taxRate && $taxFreePrice > 0) {
$taxRate = ($price - $taxFreePrice) / $taxFreePrice;
$taxRate = (int) round($taxRate * 100);
}

$this->tax_rate = $taxRate ?? 0;

if (0 !== $this->tax_rate) {
$this->total_tax_amount = (int) round($this->total_amount - $this->total_amount * 10000 / (10000 + $this->tax_rate));
$this->total_tax_amount = $price - $taxFreePrice;
}

$this->tax_rate = $taxRate;

$this->addType($item);
$this->addProductUrl($item);
$this->addImageUrl($item);
Expand Down

0 comments on commit 893d3c4

Please sign in to comment.