Skip to content

[Bug] Company field in shipping address is set to null in multi-store setup when adding a new address during the checkout shipping step #39424

Open
@bohdan-harniuk

Description

@bohdan-harniuk

Preconditions and environment

  • Magento versions: 2.4.8-beta1, 2.4.7, 2.4.7-p3, 2.4.7-p2, 2.4.7-p1, 2.4.7-beta3, 2.4.7-beta2, 2.4.7-beta1, 2.4.6, 2.4.6-p8, 2.4.6-p7, 2.4.6-p6, 2.4.6-p5, 2.4.6-p4, 2.4.6-p3, 2.4.6-p2, 2.4.6-p1
  • Anything else that would help a developer reproduce the bug

Steps to reproduce

  1. Navigate to Stores -> Configuration -> Customers -> Customer Configuration.
  2. Ensure you are in the Default Config scope.
  3. Navigate to Name and Address Options -> Show Company, and set it to No.
    Screenshot 2024-12-03 at 11 46 52
  4. Save the configuration.
  5. Switch to the Website scope.
  6. Navigate to Name and Address Options -> Show Company, and set it to Optional or Required.
    Screenshot 2024-12-03 at 11 48 25
  7. Save the configuration.
  8. Clear the configuration cache.
  9. Log in as a customer on the storefront (on a website where the company field for the address entity is set to Optional or Required).
  10. Add a product to the cart.
  11. Proceed to the checkout and navigate to the shipping step.
  12. Add a new shipping address and populate the Company name field.
  13. Choose a shipping method.
  14. Navigate to the payment step.
  15. Check the quote_address database table for the current quote. The company field is empty, but it is expected to contain the value provided by the customer.
  16. Choose a payment method.
  17. Place the order.
  18. Navigate to the Customer Account Page -> Address Book.
  19. Edit the address created during the checkout process.
  20. The Company field is empty, but it is expected to contain the value provided by the customer.
Screen.Recording.2024-12-03.at.11.51.27.mov

Expected result

  1. After navigating to the payment step with the new address selected, the corresponding row in the quote_address table must contain the company name provided by the customer.
  2. After successfully completing the checkout process, the shipping address in the placed order must include the company name provided by the customer.
  3. If the Save in address book option is selected for the new address, the company field must be populated with the value provided by the customer.

Actual result

  1. After navigating to the payment step with the new address selected, the corresponding row in the quote_address table contains an empty value for the company field.
  2. After successfully completing the checkout process, the shipping address in the placed order does not include the company name.
  3. If the Save in address book option is selected for the new address, the company field of the newly created address in the address book contains an empty value.

Additional information

This issue was introduced by changes made in the following commit: 039bf9b.

Reason: When checking if the company field should be shown for the address entity, the default scope is used. However, this field is configurable at both the default and website scopes. If the field is set to Not Visible in the default scope and configured with a different value (e.g., Optional or Required) at the website scope, the configuration at the website scope is ignored.

You can apply the following patch to resolve this issue:

Subject: [PATCH] Generated by Magento and Adobe Commerce PhpStorm by Atwix plugin
---
Index: vendor/magento/module-quote/Model/ShippingAddressManagement.php
===================================================================
diff --git a/vendor/magento/module-quote/Model/ShippingAddressManagement.php b/vendor/magento/module-quote/Model/ShippingAddressManagement.php
--- a/vendor/magento/module-quote/Model/ShippingAddressManagement.php	
+++ b/vendor/magento/module-quote/Model/ShippingAddressManagement.php	(date 1733221123066)
@@ -10,6 +10,7 @@
 use Magento\Framework\App\ObjectManager;
 use Magento\Framework\Exception\InputException;
 use Magento\Framework\Exception\NoSuchEntityException;
+use Magento\Store\Model\ScopeInterface;
 use Psr\Log\LoggerInterface as Logger;
 
 /**
@@ -93,8 +94,7 @@
         $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0;
         $sameAsBilling = $address->getSameAsBilling() ? 1 : 0;
         $customerAddressId = $address->getCustomerAddressId();
-        if ($saveInAddressBook &&
-            !$this->scopeConfig->getValue(Customer::XML_PATH_CUSTOMER_ADDRESS_SHOW_COMPANY)) {
+        if ($saveInAddressBook && !$this->isCompanyFieldVisibleForAddress()) {
             $address->setCompany(null);
         }
         $this->addressValidator->validateForCart($quote, $address);
@@ -139,4 +139,17 @@
         /** @var \Magento\Quote\Model\Quote\Address $address */
         return $quote->getShippingAddress();
     }
+
+    /**
+     * Determine whether the company field should be displayed for the customer address.
+     *
+     * @return bool
+     */
+    private function isCompanyFieldVisibleForAddress(): bool
+    {
+        return !!$this->scopeConfig->getValue(
+            Customer::XML_PATH_CUSTOMER_ADDRESS_SHOW_COMPANY,
+            ScopeInterface::SCOPE_WEBSITE
+        );
+    }
 }

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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: Cart & CheckoutComponent: CheckoutIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: dev in progressReported on 2.4.8-beta1Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions