magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Customer Date of Birth field not displayed in Checkout when field is set optional or required in Customer Name and Address Options

Open ottosschweiz opened this issue 7 years ago • 25 comments

Preconditions

  1. Clean Magento 2.4

Steps to reproduce

  1. Set Customer Date of Birth optional or required in Customer Name and Address options
  2. Save Configuration
  3. Go to Checkout (after clearing Cache etc.)

Expected result

  1. Field for Customer Date of Birth is displayed in Checkout

Actual result

  1. Customer Date of Birth Field is not displayed in Checkout magento_customer_configuration magento_checkout_view

Additional Information

  1. For all the other fields, except for Date of Birth and Gender, these settings work. If a value is optional or required, a filed for those values is displayed in the Checkout View (like Phone number, Prefix, Suffix etc.)
  2. In Magento 1.9 this worked perfectly. If the Date of Birth was set optional or required in the Customer Settings, the field is displayed in the Checkout View

ottosschweiz avatar Apr 03 '18 11:04 ottosschweiz

Dob and Gender are not part of shipping address but are connected with customer and if you enable those settings then your registered users must have Dob and gender configured. ( It adds those fields under customer registration and for older users redirects to customer edit page before checkout)

Karlasa avatar Apr 05 '18 13:04 Karlasa

@Karlasa Thank you for your input. I also read about this, but I opened this issue because it worked in Magento 1.9. If you set customer-dob as required in the address and name settings, the field will be displayed in the shipping address form in checkout.

Since this was a real nice thing because we allow guest orders and need those information in our newer shop with version 2.2, I thought this might be an issue or a thing that went lost.

ottosschweiz avatar Apr 05 '18 14:04 ottosschweiz

The implementation logic for custom customer attributes has not been added to the checkout; In my opinion a major design flaw.

This also causes problems when you have (custom) customer attributes that are required. If you want to create an account after successfully placing an order an error will be given because Magento will freak out because he can't find the attributes on the customer or customer address from the order.

We currently have a ticket on the cloud support running for the second part of this problem, but the response there was:

Based on how the software was developed there are no problems the forms to use the attribute in doesn't include storefront checkout only admin and this is where the problem generates for you. The product dev team is going to ultimately address this but it will take time.

Also related https://github.com/magento/magento2/issues/10489

koenner01 avatar Apr 12 '18 14:04 koenner01

@ottosschweiz, thank you for your report. We've acknowledged the issue and added to our backlog.

ghost avatar Jul 17 '18 12:07 ghost

Something we can to do elevate the priority? Since this worked flawlessly with Magento 1 it's a bummer that it got removed for Magento 2.

Morgy93 avatar Jul 27 '18 08:07 Morgy93

Any updates related to this issue?

tvynograd avatar Dec 17 '18 12:12 tvynograd

Hi @engcom-Echo. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- 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!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


m2-assistant[bot] avatar Dec 30 '19 13:12 m2-assistant[bot]

:white_check_mark: Confirmed by @engcom-Echo Thank you for verifying the issue. Based on the provided information internal tickets MC-30134 were created

Issue Available: @engcom-Echo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

magento-engcom-team avatar Dec 30 '19 13:12 magento-engcom-team

Hi @geet07. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 2. Verify that the issue is reproducible on 2.4-develop branch

    Details- 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!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


m2-assistant[bot] avatar Jan 18 '20 07:01 m2-assistant[bot]

I'm working on this issue in one of the projects and I found where collection of attributes coming from and that might help understand the issue.

\Magento\Checkout\Block\Checkout\LayoutProcessor::getAddressAttributes the collection of attributes came only for customer_address entity type. But dob, gender, and some other attributes are customer attributes. So, that's why attributes aren't there.

AleksLi avatar Mar 26 '20 12:03 AleksLi

What's the status of this ticket?

duckchip avatar Apr 27 '20 13:04 duckchip

I created the following Plugin that adds the gender:

<?php
namespace Vendor\Module\Plugin\Checkout\Model\Checkout;


use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Framework\Serialize\Serializer\Json;

/**
 * Class LayoutProcessor
 * @package Vendor\Module\Plugin\Checkout\Model\Checkout
 */
class GenderLayoutProcessor
{
    private $customerMetaData;

    private $json;

    public function __construct(
        CustomerMetadataInterface $customerMetadata,
        Json $json
    )
    {
        $this->json = $json;
        $this->customerMetaData = $customerMetadata;
    }

    /**
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
    public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, array $jsLayout)
    {
        $shippingAddress = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
        ['children']['shippingAddress']['children']['shipping-address-fieldset']['children'];

        $this->addGenderField($shippingAddress);
        // Loop all payment methods (because billing address is appended to the payments)
        $configuration = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'];
        foreach ($configuration as $paymentGroup => $groupConfig) {
            if (isset($groupConfig['component']) AND $groupConfig['component'] === 'Magento_Checkout/js/view/billing-address') {
                $paymentLayout = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'][$paymentGroup]['children']['form-fields']['children'];
                $this->addGenderField($paymentLayout);
            }
        }

        return $jsLayout;
    }

    private function addGenderField(&$jsLayout)
    {
        $options = $this->getGenderOptions() ?: [];
        $enabled  = $this->isEnabled();
        if (!empty($options) && $enabled) {
            $jsLayout['gender'] = [
                'component' => 'Magento_Ui/js/form/element/select',
                'config' => [
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/select',
                    'id' => 'gender',
                    'options' => $options
                ],
                'label' => __('Gender'),
                'provider' => 'checkoutProvider',
                'visible' => true,
                'validation' => [
                    'required-entry' => true
                ],
                'sortOrder' => 10,
                'id' => 'gender'
            ];
        }
    }
    /**
     * Retrieve customer attribute instance
     *
     * @param string $attributeCode
     * @return \Magento\Customer\Api\Data\AttributeMetadataInterface|null
     */
    protected function _getAttribute($attributeCode)
    {
        try {
            return $this->customerMetaData->getAttributeMetadata($attributeCode);
        } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
            return null;
        }
    }

    private function getGenderOptions(): array
    {
        $optionsData = [];
        $options = $this->_getAttribute('gender')->getOptions() ?: [];

        foreach ($options as $option) {
            $optionsData[] = [
                'label' => __($option->getLabel()),
                'value' => $option->getValue()
            ];
        }

        return $optionsData;
    }

    public function isEnabled()
    {
        return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isVisible() : false;
    }
}

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="gender_layout_processor" type="Vendor\Module\Plugin\Checkout\Model\Checkout\GenderLayoutProcessor" sortOrder="300"/>
    </type>
</config>

duckchip avatar Apr 27 '20 14:04 duckchip

Since there is no gender and dob field in the database for quote_address, I am wondering where this is supposed to be saved anyway?

@duckchip thank you for that :). We were able to show the Date Of Birth field in the checkout using a customized version of your code. However - the birth date isn't actually saved to the quote. Neither would the gender, presumably?

fritzmg avatar May 11 '20 17:05 fritzmg

I created the following Plugin that adds the gender:

<?php
namespace Vendor\Module\Plugin\Checkout\Model\Checkout;


use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Framework\Serialize\Serializer\Json;

/**
 * Class LayoutProcessor
 * @package Vendor\Module\Plugin\Checkout\Model\Checkout
 */
class GenderLayoutProcessor
{
    private $customerMetaData;

    private $json;

    public function __construct(
        CustomerMetadataInterface $customerMetadata,
        Json $json
    )
    {
        $this->json = $json;
        $this->customerMetaData = $customerMetadata;
    }

    /**
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
    public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, array $jsLayout)
    {
        $shippingAddress = &$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']
        ['children']['shippingAddress']['children']['shipping-address-fieldset']['children'];

        $this->addGenderField($shippingAddress);
        // Loop all payment methods (because billing address is appended to the payments)
        $configuration = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'];
        foreach ($configuration as $paymentGroup => $groupConfig) {
            if (isset($groupConfig['component']) AND $groupConfig['component'] === 'Magento_Checkout/js/view/billing-address') {
                $paymentLayout = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children'][$paymentGroup]['children']['form-fields']['children'];
                $this->addGenderField($paymentLayout);
            }
        }

        return $jsLayout;
    }

    private function addGenderField(&$jsLayout)
    {
        $options = $this->getGenderOptions() ?: [];
        $enabled  = $this->isEnabled();
        if (!empty($options) && $enabled) {
            $jsLayout['gender'] = [
                'component' => 'Magento_Ui/js/form/element/select',
                'config' => [
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/select',
                    'id' => 'gender',
                    'options' => $options
                ],
                'label' => __('Gender'),
                'provider' => 'checkoutProvider',
                'visible' => true,
                'validation' => [
                    'required-entry' => true
                ],
                'sortOrder' => 10,
                'id' => 'gender'
            ];
        }
    }
    /**
     * Retrieve customer attribute instance
     *
     * @param string $attributeCode
     * @return \Magento\Customer\Api\Data\AttributeMetadataInterface|null
     */
    protected function _getAttribute($attributeCode)
    {
        try {
            return $this->customerMetaData->getAttributeMetadata($attributeCode);
        } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
            return null;
        }
    }

    private function getGenderOptions(): array
    {
        $optionsData = [];
        $options = $this->_getAttribute('gender')->getOptions() ?: [];

        foreach ($options as $option) {
            $optionsData[] = [
                'label' => __($option->getLabel()),
                'value' => $option->getValue()
            ];
        }

        return $optionsData;
    }

    public function isEnabled()
    {
        return $this->_getAttribute('gender') ? (bool)$this->_getAttribute('gender')->isVisible() : false;
    }
}
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="gender_layout_processor" type="Vendor\Module\Plugin\Checkout\Model\Checkout\GenderLayoutProcessor" sortOrder="300"/>
    </type>
</config>

I created the field with this code, but the value is not saving into order..

alam-ejaz avatar Dec 28 '20 14:12 alam-ejaz

Hi @engcom-Charlie. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

    1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
    1. Verify that the issue is reproducible on 2.4-develop branch
      Details- 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!
    1. If the issue is not relevant or is not reproducible any more, feel free to close it.

m2-assistant[bot] avatar Dec 30 '20 11:12 m2-assistant[bot]

Any update on this? This is an important feature for us as we need the DOB of all (registered) customers, and 99% of our signups are during checkout.

mobweb avatar Aug 03 '21 05:08 mobweb

In Magento 2.4.3 we have Dob Field for guests and new customer registration, however, the field is not appearing for logged in customers that already have at least one address.

I think its hilarious how buggy Magento2 is. I am developing within Magento for now 8 years, but Magento2 is really nothing I can sell to my customers with all this bugs..

bytes-commerce avatar Nov 25 '21 00:11 bytes-commerce

@magento I am working on this

GurramSravya avatar Aug 28 '23 05:08 GurramSravya

2024, same problems... This post was made in April 2018! nothing justifies so much delay... On top of that for an item that worked perfectly well in magento 1...

davirs avatar Jan 24 '24 20:01 davirs

Hi @ottosschweiz,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the attached screenshots.

Steps to reproduce

  • Set Customer Date of Birth optional or required in Customer Name and Address options
  • Save Configuration
  • Go to Checkout (after clearing Cache etc
Screenshot 2024-04-05 at 12 17 54

Customer Date of Birth Field is not displayed in Checkout

Hence Confirming the issue.

Thanks.

engcom-Bravo avatar Apr 05 '24 06:04 engcom-Bravo

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-11746 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Apr 05 '24 08:04 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

m2-assistant[bot] avatar Apr 05 '24 08:04 m2-assistant[bot]

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11746

github-jira-sync-bot avatar Apr 05 '24 09:04 github-jira-sync-bot

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11746

github-jira-sync-bot avatar Apr 05 '24 09:04 github-jira-sync-bot

05/15/2024 And this basic functionality has not yet been resolved. It's not that possible that after 6 years it's still open.

@engcom-Bravo, Any news about it?

davirs avatar May 15 '24 17:05 davirs