Skip to content

$customerDataObject returning empty Object in magento 2.4.7?

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 MagentoCustomerModel;

use MagentoCustomerApiCustomerMetadataInterface;
use MagentoCustomerApiDataCustomerInterface;
use MagentoCustomerApiGroupManagementInterface;
use MagentoFrameworkAppRequestInterface;

/**
 * Customer Extractor model.
 */
class CustomerExtractor
{
    /**
     * @var MagentoCustomerModelMetadataFormFactory
     */
    protected $formFactory;

    /**
     * @var MagentoCustomerApiDataCustomerInterfaceFactory
     */
    protected $customerFactory;

    /**
     * @var MagentoStoreModelStoreManagerInterface
     */
    protected $storeManager;

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

    /**
     * @var MagentoFrameworkApiDataObjectHelper
     */
    protected $dataObjectHelper;

    /**
     * @param MetadataFormFactory $formFactory
     * @param MagentoCustomerApiDataCustomerInterfaceFactory $customerFactory
     * @param MagentoStoreModelStoreManagerInterface $storeManager
     * @param GroupManagementInterface $customerGroupManagement
     * @param MagentoFrameworkApiDataObjectHelper $dataObjectHelper
     */
    public function __construct(
        MagentoCustomerModelMetadataFormFactory $formFactory,
        MagentoCustomerApiDataCustomerInterfaceFactory $customerFactory,
        MagentoStoreModelStoreManagerInterface $storeManager,
        GroupManagementInterface $customerGroupManagement,
        MagentoFrameworkApiDataObjectHelper $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,
            MagentoCustomerApiDataCustomerInterface::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.