Open ottosschweiz opened 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)
@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.
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
@ottosschweiz, thank you for your report. We've acknowledged the issue and added to our backlog.
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.
Any updates related to this issue?
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
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!
[ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.
: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.
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
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!
[ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.
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.
What's the status of this ticket?
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>
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?
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..
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:
Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.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.
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..
@magento I am working on this
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...
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
Customer Date of Birth Field is not displayed in Checkout
Hence Confirming the issue.
Thanks.
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-11746 is successfully created for this GitHub issue.
: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.
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11746
:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11746
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?
Preconditions
Steps to reproduce
Expected result
Actual result
Additional Information