Closed gwharton closed 3 years ago
Hi @gwharton. Thank you for your report. To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, please, review the Magento Contributor Assistant documentation.
Please, add a comment to assign the issue: @magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.
:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
Hi @engcom-Oscar. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hi @gwharton , thank you for your report. I have checked this issue and it reproducing even without MSI modules, on vanila 2.4-develop branch of Magento. This why I have removed MSI from description, then we could proceed to work with it on our repository.
:white_check_mark: Confirmed by @engcom-Oscar
Thank you for verifying the issue. Based on the provided information internal tickets MC-37666
were created
Issue Available: @engcom-Oscar, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Well, it took me about 7 hours to get to the bottom of this one.
Magento\Sales\Observer\Frontend\RestoreCustomerGroupId is fired by the event sales_quote_address_collect_totals_after
This is called numerous times throughout the checkout process.
It looks as if this plugin checks if the setting for "Tax Calculation Based On" is set to "Shipping Address", and if the Customer Group Id of the quote has previously changed (indicating that the group has changed due to VAT validation) then the change in Group ID is reverted.
I have no idea why, but this seems intentional. VAT should be calculated based on where the goods are being delivered to, not the billing address, so it seems odd to kill the updated Group ID, and hence the Customer Tax Class ID in this case.
If the Group ID is not set correctly, then the quote->getCustomerTaxClassId function will not work, as it generates the tax class in real time from the group ID.
This needs some thought.
Also needs addressing if you want to keep the adjusted customer group in the quote object and order object after VAT validation for guest orders.
The issue has been fixed by Magento team and delivered with internal PR in the scope of MC-37666
Related commits https://github.com/magento/magento2/search?q=MC-37666&type=commits
@sdzhepa, This doesn't fix the problem for me.
Problem 1
The "sales_customer_validate_vat_number" event is fired on the frontend, and also webapi when VAT validation is carried out.
The following observer subscribes to that event. "Magento\Sales\Observer\Frontend\RestoreCustomerGroupId"
That Observer removes any changes to the quote->CustomerGroupId field which were made by the VAT Validation routines.
I guess this event is not triggered by the unit test as the VAT validation object is mocked, and never fires this event.
With these events in place, when the order is placed, the Observer resets the customer group in the quote to 0, which is then copied forwards into the $order object.
Problem 2
The fix put in place
If it is a guest order, then doesn't $quote->getCustomer() return an empty customer object
and would just result in the fix setting the $quote->setCustomerGroupId() call with null parameter.
My Workaround
Stop the overwriting of the CustomerGroupId in the quote object on VAT validation. I have no idea why this is put in, in the first place. Seems incorrect for it to be there.
etc/frontend/events.xml etc/webapi_rest/events.xml etc/webapi_soap/events.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_quote_address_collect_totals_after">
<observer name="sales_customer_validate_vat_number" disabled="true" />
</event>
</config>
Stop the overwriting of the CustomerGroupId in the quote object on order placement
--- Model/QuoteManagement.orig.php 2020-09-19 18:09:21.263000000 +0100
+++ Model/QuoteManagement.php 2020-09-19 18:09:25.540000000 +0100
@@ -395,7 +395,6 @@
}
}
$quote->setCustomerIsGuest(true);
- $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
}
$remoteAddress = $this->remoteAddress->getRemoteAddress();
status?
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Actual result (*)
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.