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

Simplify Tax Calculation for custom adjustments #2660

Open
solverat opened this issue Jul 3, 2024 · 0 comments
Open

Simplify Tax Calculation for custom adjustments #2660

solverat opened this issue Jul 3, 2024 · 0 comments

Comments

@solverat
Copy link
Contributor

solverat commented Jul 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant