Customer Tax Group not applied on order creation
Question
Setup
I have
- Crated different
Customer Tax Classes
(Retail/Company) - Created different
Tax Rates
(21%/0%) and applied them withTax Rule
- In Store Config enabled
Enable Automatic Assignment to Customer Group
and selected correctCustomer Tax Classes
based onBilling Address
andValidate on each transaction
The problem
In the store front everything works as expected. The prices during checkout are calculated with different Tax Rates
based on the billing address with and without VAT ID
.
BUT the Order
is saved with the Retail
tax values, even though the Company
tax group is saved properly.
So both the admin Sales -> Orders
and API
show that order correctly with the Company
customer tax group, but the tax rates are applied from the Retail
class.
Solution
Fixed this by modifing app/code/Magento/Quote/Model/QuoteManagement.php
by adding 3 lines after the first one in the following method:
public function placeOrder($cartId, PaymentInterface $paymentMethod = null){
$quote = $this->quoteRepository->getActive($cartId);
$quote->setTotalsCollectedFlag(false); // add this lines
$quote->collectTotals(); // add this lines
$quote->save(); // add this lines
This forces Magento to recollect prices according to the billing address before saving it to the database.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange