Skip to content

Commit 893d3c4

Browse files
committed
Fix taxes as surcharge
1 parent 2bad989 commit 893d3c4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Dto/Item.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,26 @@ public function __construct(ProductCollectionItem $item, IsotopeProductCollectio
4040
$taxFreePrice = (int) round($item->getTaxFreePrice() * 100);
4141
$price = (int) round($item->getPrice() * 100);
4242

43-
$this->total_tax_amount = $price - $taxFreePrice;
43+
if (null !== $taxRate) {
44+
if ($price > $taxFreePrice) {
45+
// Taxes are included in the price
46+
$this->total_tax_amount = (int) round($this->total_amount - $this->total_amount * 10000 / (10000 + $taxRate));
47+
} else {
48+
// Taxes are added as surcharge
49+
$taxRate = 0;
50+
}
51+
}
4452

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

51-
$this->tax_rate = $taxRate ?? 0;
52-
53-
if (0 !== $this->tax_rate) {
54-
$this->total_tax_amount = (int) round($this->total_amount - $this->total_amount * 10000 / (10000 + $this->tax_rate));
58+
$this->total_tax_amount = $price - $taxFreePrice;
5559
}
5660

61+
$this->tax_rate = $taxRate;
62+
5763
$this->addType($item);
5864
$this->addProductUrl($item);
5965
$this->addImageUrl($item);

0 commit comments

Comments
 (0)