1

I have a fresh installation of magento 2.2.5 with Magetigue theme and I have migrated the data from magento 1.9.3.7 to magento 2.2.5 using data migration tool. Now when I try to create an account by entering all the fields and click the create button, It reloads the same registration page showing an error message that " "" is a required Field". I have checked the app/design/frontend/THEME_VENDOR/THEME/Magento_Customer/templates/form/register.phtml file and it contains the form key

<?= /* @noEscape */ $block->getBlockHtml('formkey'); ?>

So, its not a form key problem I have deleted all the cookies too, but still no luck.

I have traced the post request after clicking the create customer button in the network tab and the post request goes to CreatePost.php in /vendor/magento/module-customer/Controller/Account/CreatePost.php and the request status is 302 found.

I have added a log code in CreatePost.php

And found that the problem lies in this code:

try {
            $address = $this->extractAddress();
            $addresses = $address === null ? [] : [$address];

            $customer = $this->customerExtractor->extract('customer_account_create', $this->_request);
            $customer->setAddresses($addresses);

            $password = $this->getRequest()->getParam('password');
            $confirmation = $this->getRequest()->getParam('password_confirmation');
            $redirectUrl = $this->session->getBeforeAuthUrl();

            $this->checkPasswordConfirmation($password, $confirmation);

            $customer = $this->accountManagement
                ->createAccount($customer, $password, $redirectUrl);

Can somebody help resolve this?

Regards,

0

After debugging the issue, I found that the problem was with the rp_token field of customer_entity table. When I tried to edit the customer from backend it shows the same error i.e. " "" is a required field ", but when I click the reset password button first and then click the save customer button it doesn't show any error and the customer gets saved. The reset password sets the value of rp_token field in the customer_entity table. In order to make it work I edited the vendor/magento/module-eav/Model/Validator/Attribute/Data.php File and edited the isValid($entity) function as:

public function isValid($entity)
{
    /** @var $attributes Attribute[] */
    $attributes = $this->_getAttributes($entity);

    $data = [];
    if ($this->_data) {
        $data = $this->_data;
    } elseif ($entity instanceof \Magento\Framework\DataObject) {
        $data = $entity->getData();
    }

    foreach ($attributes as $attribute) {
        $attributeCode = $attribute->getAttributeCode();

         if($attributeCode == "rp_token" || $attributeCode == "rp_token_created_at"){
            continue;
        }


        if (!$attribute->getDataModel() && !$attribute->getFrontendInput()) {
            continue;
        }
        $dataModel = $this->_attrDataFactory->create($attribute, $entity);
        $dataModel->setExtractedData($data);
        if (!isset($data[$attributeCode])) {
            $data[$attributeCode] = null;
        }
        $result = $dataModel->validateValue($data[$attributeCode]);
        if (true !== $result) {
            $this->_addErrorMessages($attributeCode, (array)$result);
        }
    }
    return count($this->_messages) == 0;
}

Though editing the core files of Magento is not a good convention. But just to make it work I edited this function and It worked.

P.S: A better solution will be to create a module that will override this function...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.