0

I have upgraded the magento from 2.4.0 to 2.4.7 latest version. When I try to register the new customer, then it is throwing the error: "There is already an account with this email address. If you are sure that it is your email address, click here to get your password and access your account."

When I check the code line by line, I found that this file "/var/www/html/protecta/vendor/magento/module-customer/Model/CustomerExtractor.php"

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Customer\Model;

use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Framework\App\RequestInterface;

/**
 * Customer Extractor model.
 */
class CustomerExtractor
{
    /**
     * @var \Magento\Customer\Model\Metadata\FormFactory
     */
    protected $formFactory;

    /**
     * @var \Magento\Customer\Api\Data\CustomerInterfaceFactory
     */
    protected $customerFactory;

    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    protected $storeManager;

    /**
     * @var GroupManagementInterface
     */
    protected $customerGroupManagement;

    /**
     * @var \Magento\Framework\Api\DataObjectHelper
     */
    protected $dataObjectHelper;

    /**
     * @param Metadata\FormFactory $formFactory
     * @param \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param GroupManagementInterface $customerGroupManagement
     * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
     */
    public function __construct(
        \Magento\Customer\Model\Metadata\FormFactory $formFactory,
        \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        GroupManagementInterface $customerGroupManagement,
        \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
    ) {
        $this->formFactory = $formFactory;
        $this->customerFactory = $customerFactory;
        $this->storeManager = $storeManager;
        $this->customerGroupManagement = $customerGroupManagement;
        $this->dataObjectHelper = $dataObjectHelper;
    }

    /**
     * Creates a Customer object populated with the given form code and request data.
     *
     * @param string $formCode
     * @param RequestInterface $request
     * @param array $attributeValues
     * @return CustomerInterface
     */
    public function extract(
        $formCode,
        RequestInterface $request,
        array $attributeValues = []
    ) {
        $customerForm = $this->formFactory->create(
            CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
            $formCode,
            $attributeValues
        );

        // Extract and compact data
        $customerData = $customerForm->extractData($request);
        file_put_contents(BP.'/var/log/failed-register.log', 'ExtractedData : '.json_encode($customerData).PHP_EOL, FILE_APPEND);

        $customerData = $customerForm->compactData($customerData);
        file_put_contents(BP.'/var/log/failed-register.log', 'CompactData : '.json_encode($customerData).PHP_EOL, FILE_APPEND);

        // Check allowed attributes
        $allowedAttributes = $customerForm->getAllowedAttributes();
        file_put_contents(BP.'/var/log/failed-register.log', 'AllowedAttributes : '.json_encode($allowedAttributes).PHP_EOL, FILE_APPEND);

        // Create customer data object
        $customerDataObject = $this->customerFactory->create();
        $this->dataObjectHelper->populateWithArray(
            $customerDataObject,
            $customerData,
            \Magento\Customer\Api\Data\CustomerInterface::class
        );

        // Check the populated customer data object
        $reflection = new \ReflectionClass($customerDataObject);
        $properties = $reflection->getProperties();
        $data = [];
        foreach ($properties as $property) {
            $property->setAccessible(true);
            $data[$property->getName()] = $property->getValue($customerDataObject);
        }
        file_put_contents(BP.'/var/log/failed-register.log', 'PopulatedCustomerDataObject : '.json_encode($data).PHP_EOL, FILE_APPEND);

        // Set store and website IDs
        $store = $this->storeManager->getStore();
        $storeId = $store->getId();
        $customerDataObject->setWebsiteId($store->getWebsiteId());
        $customerDataObject->setStoreId($storeId);

        // Check final customer data object
        $properties = $reflection->getProperties();
        $data = [];
        foreach ($properties as $property) {
            $property->setAccessible(true);
            $data[$property->getName()] = $property->getValue($customerDataObject);
        }
        file_put_contents(BP.'/var/log/failed-register.log', 'FinalCustomerDataObject : '.json_encode($customerDataObject).PHP_EOL, FILE_APPEND);

        return $customerDataObject;
    }
}

When I log the file_put_contents(BP.'/var/log/failed-register.log', 'FinalCustomerDataObject : '.json_encode($customerDataObject).PHP_EOL, FILE_APPEND);

Then is returning the empty value.

1

1 Answer 1

0

The above error mention that,

The Customer already exist with same email id, which you try to register.

Now here you have 2 ways.

  1. So now try to register with different email id.
  2. First remove that email address account from the magento admin, then try to register with same email address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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