magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

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

Open ottosschweiz opened 6 years ago

ottosschweiz commented 6 years ago

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
Karlasa commented 6 years ago

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)

ottosschweiz commented 6 years ago

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

koenner01 commented 6 years ago

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

ghost commented 6 years ago

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

Morgy93 commented 6 years ago

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.

tvynograd commented 5 years ago

Any updates related to this issue?

m2-assistant[bot] commented 4 years ago

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:


magento-engcom-team commented 4 years ago

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

m2-assistant[bot] commented 4 years ago

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:


AleksLi commented 4 years ago

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.

duckchip commented 4 years ago

What's the status of this ticket?

duckchip commented 4 years ago

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>
fritzmg commented 4 years ago

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?

alam-ejaz commented 3 years ago

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

m2-assistant[bot] commented 3 years ago

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:


mobweb commented 3 years ago

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.

bytes-commerce commented 2 years ago

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

GurramSravya commented 1 year ago

@magento I am working on this

davirs commented 8 months ago

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

engcom-Bravo commented 5 months ago

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

Screenshot 2024-04-05 at 12 17 54

Customer Date of Birth Field is not displayed in Checkout

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 5 months ago

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

m2-assistant[bot] commented 5 months ago

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

github-jira-sync-bot commented 5 months ago

: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 commented 5 months ago

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

davirs commented 4 months ago

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?