magento2: The customer group is not changed automatically when VAT is removed from the address
Preconditions and environment
-
Magento version 2.4.2, but I believe the bug is relevant for all the versions from 2.4.2 because it was introduced here: https://github.com/magento/magento2/commit/f6bb0228a30f9c12059cce724a522257d6f50d14
-
Configure Magento in order to assign the group automatically based on billing address:
- Customers > Customer Configuration > Create New Account Options:
- Enable Automatic Assignment to Customer Group = YES
- Tax Calculation Based On = Billing address
- Default Group = Ganeral
- Group for Valid VAT ID - Domestic = B2B (please create this group first)
- Group for Valid VAT ID - Intra-Union = B2B
- Validate on Each Transaction = YES
- Customers > Customer Configuration > Create New Account Options:
Steps to reproduce
- Create a customer
- Create a default billing address with valid VAT, as a result the customer group is changed to b2b automatically
- Remove the VAT from the address
Expected result
The customer group is changed to General.
Actual result
The customer group is not changed. It still B2B, no matter customer doesn’t have the VAT anymore. As a result, the customer does not pay tax, but he should actually because the customer doesn’t have a VAT and should be treated as a private customer.is
Additional information
As I said, the bug was introduced here: https://github.com/magento/magento2/commit/f6bb0228a30f9c12059cce724a522257d6f50d14
If I roll back the change in the app/code/Magento/Customer/Observer/AfterAddressSaveObserver.php it works fine for me.
I implemented a patch which works fine for me:
--- ./Observer/AfterAddressSaveObserver.php.org 2023-04-04 18:00:58.000000000 +0200
+++ ./Observer/AfterAddressSaveObserver.php 2023-04-04 18:02:52.000000000 +0200
@@ -141,8 +141,7 @@
if ($customerAddress->getVatId() == ''
|| !$this->_customerVat->isCountryInEU($customerAddress->getCountry())
) {
- $defaultGroupId = $customer->getGroupId() ? $customer->getGroupId() :
- $this->_groupManagement->getDefaultGroup($customer->getStore())->getId();
+ $defaultGroupId = $this->_groupManagement->getDefaultGroup($customer->getStore())->getId();
if (!$customer->getDisableAutoGroupChange() && $customer->getGroupId() != $defaultGroupId) {
$customer->setGroupId($defaultGroupId);
$customer->save();
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18
Hi @sevka, here is your Magento Instance: https://e219d599b92fc5e05c5cf42d4e7c3b3b.instances-prod.magento-community.engineering Admin access: https://e219d599b92fc5e05c5cf42d4e7c3b3b.instances-prod.magento-community.engineering/admin_5082 Login: 40ad5432 Password: 79d6a224ba7b