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.5k stars 9.31k forks source link

Can't create customer account on checkout success page when gender field is required #10489

Closed speedupmate closed 5 years ago

speedupmate commented 7 years ago

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

  1. issue is present all magento2 versions including upcoming 2.2

Steps to reproduce

To reproduce this issue

  1. Login into magento admin panel
  2. Go Stores > Configuration> Customers > Customer Configuration>Name and Address Option
  3. set Show Gender field to required
  4. go to front-end , reach checkout - no gender field present (not implemented)
  5. finish checkout and press "create account" in success page
  6. Error is displayed "Gender is a required field"

Expected result

  1. if gender (or any other required customer attribute that is not implemented for frontend) is enabled there should be a way to input the data
  2. account create method should be able to get the gender data and create account

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 :

  1. value not inserted cause field is missing from frontend (not implemented)
  2. account is created based on order address data (and not having the values needed)
PascalBrouwers commented 7 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.

magento-engcom-team commented 7 years ago

@speedupmate thank you for your bug report. We've created internal ticket MAGETWO-75443 to track progress on the issue.

bka commented 7 years ago

@okorshenko I'll have a look into this one.

bka commented 7 years ago

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.

auswahl_048

speedupmate commented 7 years ago

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

joachimVT commented 7 years ago

This issue also happens when you set 'Date of Birth' to be a required field.

korostii commented 6 years ago

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.

speedupmate commented 6 years ago

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

tanghia commented 6 years ago

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!

hostep commented 6 years ago

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?

koenner01 commented 6 years ago

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.

speedupmate commented 6 years ago

@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

koenner01 commented 6 years ago

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.

walterbak commented 6 years ago

@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

mekedron commented 6 years ago

@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;
    }
}
magento-engcom-team commented 5 years ago

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:

TomashKhamlai commented 5 years ago

The issue is not reproducible anymore on the 2.3-develop.

jlenzstaysafe commented 3 years ago

Still happens on 2.4.2 Enterprise