Closed speedupmate closed 5 years ago
I have a Enterprise support ticket about custom customer address field that has kind of the same issue: #579367. It has been exactly a month now and still no fix.
@speedupmate thank you for your bug report. We've created internal ticket MAGETWO-75443 to track progress on the issue.
@okorshenko I'll have a look into this one.
I think I'm not able to come up with a good solution to this right now. This seems to be a very hard structural problem, regarding customer attributes and customer address attributes. It seems to affect attributes gender and date of birth which are not shown in checkout because they are customer attributes.
When creating a customer account after checkout, currently, billing address is used to extract required attributes for creation of the customer.
$customerData = $this->objectCopyService->copyFieldsetToTarget(
'order_address',
'to_customer',
$order->getBillingAddress(),
[]
);
But these obviously do not include these attributes. They would need to be added to checkout, but I'm not quite sure where. Adding them to billing address form seems odd to me. Also Prefix and Gender are somehow mutally exclusive: would mean I need to enter both Gender and Name Prefix for the billing address.
My other approach was to ask for these missing values in a modal dialog for before post request to checkout/account/create is fired. But somehow I don't like this concept. It also seems odd to ask for missing gender and mabye date of birth after checkout has been finished.
You are right this is a structural problem and I bet none of your team-mates can explain why in m2 addresses are not just addresses (separated just by type) with shared API but completely separate implementations of either billing- or shipping address together with dependencies (like shipping address being the main citizen) and api inconsistency in every level (backend, frontend, api etc) + mixed customer attributes on top of that
if you plan to ask those at final stage include the whole address (or just registration) data for overview and ask missing fields to be filled up, otherwise it is out of context for the customer
This issue also happens when you set 'Date of Birth' to be a required field.
My other approach was to ask for these missing values in a modal dialog for before post request to checkout/account/create is fired. But somehow I don't like this concept.
Adding an extra step after checkout success sounds most logical, although you're probably right that a popup looks a bit out of place in this case.
Why not make it an actual separate page? it could also show the fields copied from address, allowing to correct them (if needed) prior to actually creating the account. Actually, if you think about it, you could just redirect to the usual customer/account/create
page and pre-fill the fields there.
just a reminder: if only virtual items are in cart and a quote is virtual , gender (or any customer attribute set as required and not present in frontend) is needed to be displayed in billing address context also
This is not a new issue. If you add any required customer address attribute (not customer attribute) , and you try to save customer account information, the system will throw an error (e.g. "abc" is a required field). I have reported this issue since 2016, but it has not fixed yet!
We are having a Magento Cloud support ticket (number 13144) open around this issue for about a month now, the latest news is that they "might" have a fix next week somewhere. If it is a fix which can be applied to Magento Open Source, I'll try to remember to post it over here.
@PascalBrouwers: you guys ever got a solution through the Enterprise support?
We have received some bs answer on the cloud ticket @hostep is refering to:
I have received feedback from my engineers. They have told me based on how this 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. As a workaround, their suggestion is to temporarily hide the create account button until this can be updated. This can be done by adding display: none CSS
So for now Magento is basically giving us 2 options
Looking back at the trackrecord of Magento to see what 'it will take time' means, we can assume we don't have to expect any fix anytime soon and will have to continue to address this ourselves.
@koenner01 write a observer/plugin and satisfy the dependencies , i've done it the day i reported this , they have lot in their plate and you can't expect that everything just falls from the sky
Yeah I know that they have a lot on their plate but come on this is a pretty big feature to drop the ball on...
We ALSO have a lot on OUR plate but every corner we turn something is broken, it's just depressing. The quality control (if any exists) is seriously lacking on a lot of points in Magento 2. They probably rely way to much on automated testing and skip to many manual steps before actually launching major versions.
@speedupmate can you post your observer/trick you have realized please? So we'll get an idea about the potentially solution, waiting for the Magento bug fix. Thanks
@walterbak
etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="core_copy_fieldset_order_address_to_customer_address">
<observer name="Vendor_Module::copyQuoteFieldsToOrder" instance="Vendor\Module\Observer\FixCustomerAddressCustomAttribute" />
</event>
</config>
etc/di.xml
<?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="Vendor\Module\Observer\FixCustomerAddressCustomAttributes">
<arguments>
<argument name="attributeCodes" xsi:type="array">
<item name="0" xsi:type="string" translate="true">my_cusom_attribute</item>
</argument>
</arguments>
</type>
</config>
Observer/FixCustomerAddressCustomAttributes.php
<?php
namespace Vendor\Module\Observer;
class FixCustomerAddressCustomAttributes implements \Magento\Framework\Event\ObserverInterface
{
/**
* @var \Magento\Framework\Api\AttributeValueFactory
*/
private $attributeValueFactory;
/**
* @var array
*/
private $attributeCodes = [];
/**
* FixCustomerAddressCustomAttribute constructor.
* @param \Magento\Framework\Api\AttributeValueFactory $attributeValueFactory
* @param array $attributeCodes
*/
public function __construct(
\Magento\Framework\Api\AttributeValueFactory $attributeValueFactory,
$attributeCodes = []
)
{
$this->attributeValueFactory = $attributeValueFactory;
// we can load it from attributes collection
// but this is a simplest way
$this->attributeCodes = array_merge($this->attributeCodes, $attributeCodes);
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var \Magento\Sales\Model\Order\Address $source */
$source = $observer->getSource();
/** @var \Magento\Framework\DataObject $target */
$target = $observer->getTarget();
$customAttributes = [];
foreach ($this->attributeCodes as $attributeCode) {
if ($source->hasData($attributeCode)) {
/** @var \Magento\Framework\Api\AttributeValue $attributeValue */
$attributeValue = $this->attributeValueFactory->create();
$attributeValue->setAttributeCode($attributeCode);
$attributeValue->setValue($source->getData($attributeCode));
$customAttributes[] = $attributeValue;
}
}
$target->setData('custom_attributes', $customAttributes);
return $this;
}
}
Hi @TomashKhamlai. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:
[x] 1. Add/Edit Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[x] 2. Verify that the issue is reproducible on 2.3-develop
branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop
branch, please, add the label Reproduced on 2.3.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. Verify that the issue is reproducible on 2.2-develop
branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop
branch, please add the label Reproduced on 2.2.x
[ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.
The issue is not reproducible anymore on the 2.3-develop.
Still happens on 2.4.2 Enterprise
this is also reported https://github.com/magento/magento2/issues/3457 (see screenshots there) but actually not solved even if ticket is closed
When gender field is required in customer address options and you try to checkout then gender field is not implemented for billing or shipping address form. After placing order and reaching success page customer is presented with "create account" button. Clicking the button executes ajax call and call fails with exception and message "gender is required field" is displayed to customer.
Preconditions
Steps to reproduce
To reproduce this issue
Expected result
Actual result
actual result is exception on customer object validation since https://github.com/magento/magento2/blob/develop/app/code/Magento/Sales/Model/Order/CustomerManagement.php tries to create a customer account and fails cause :