CoreShop
CoreShop copied to clipboard
Simplify Tax Calculation for custom adjustments
| Q | A |
|---|---|
| Bug report? | no |
| Feature request? | yes |
| BC Break report? | no |
| RFC? | yes |
Improvement: Simplify Tax Calculation for custom adjustments.
Currently, if you're adding an additional (positive) adjustment to the cart item, you manually have to call the tax calculator:
$withTax = true;
$taxCalculator = $this->taxCalculatorFactory->getTaxCalculator(
$item->getProduct(),
$cart->getShippingAddress() ?: $this->defaultAddressProvider->getAddress($cart),
$context,
);
if ($taxCalculator instanceof TaxCalculatorInterface) {
$taxItems = $item->getTaxes() ?? new Fieldcollection();
if ($withTax) {
$taxItems->setItems(
$this->taxCollector->collectTaxesFromGross(
$taxCalculator,
$amountGrossTotal,
$taxItems->getItems(),
),
);
} else {
$taxItems->setItems(
$this->taxCollector->collectTaxes(
$taxCalculator,
$amountNetTotal,
$taxItems->getItems(),
),
);
}
}
$item->addAdjustment(
$this->adjustmentFactory->createWithData(
'my_adjustment',
'',
$amountGrossTotal,
$amountNetTotal,
)
);
This is basically the same thing as CartItemRuleApplier and CartItemRuleApplier does.
Proposal: Add a service which handles those things for us.