2

Is their any way to override createAccountWithPasswordHash method from

Magento\Customer\Model\AccountManagement file ?

i tried 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">
    <preference for="Magento\Customer\Model\AccountManagement" type="Vendor\Customer\Model\AccountManagement" />
</config>

Vendor/Customer/Model/AccountManagement.php

<?php

namespace Vendor\Customer\Model;

/**
 * Handle various customer account actions
 */
class AccountManagement extends \Magento\Customer\Model\AccountManagement
{
    public function createAccountWithPasswordHash(CustomerInterface $customer, $hash, $redirectUrl = '')
    {
        echo 'checkoverridecreateAccountWithPasswordHash'; exit;
    }
}

Getting error on setup upgrade

PHP Fatal error: Could not check compatibility between Vendor\Customer\Model\AccountManagement::createAccountWithPasswordHash(Vendor\Customer\Model\CustomerInterface $customer, $hash, $redirectUrl = '') and Magento\Customer\Model\AccountManagement::createAccountWithPasswordHash(Magento\Customer\Api\Data\CustomerInterface $customer, $hash, $redirectUrl = ''), because class Vendor\Customer\Model\CustomerInterface is not available in /Vendor/Customer/Model/AccountManagement.php on line 10

3
  • any thoughts on this ?
    – devhs
    Aug 5, 2021 at 11:30
  • Class DollsKill\Customer\Model\AccountManagement\Interceptor does not exist
    – devhs
    Aug 5, 2021 at 11:45
  • any thoughts on this ?
    – devhs
    Aug 5, 2021 at 12:46

2 Answers 2

0

add below dependency in your file

<?php

namespace Vendor\Customer\Model;

use Magento\Customer\Api\Data\CustomerInterface;

use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Store\Model\StoreManagerInterface;

/*
 * Handle various customer account actions
 */
class AccountManagement extends \Magento\Customer\Model\AccountManagement
{
    /**
     * @var \Magento\Store\Model\StoreManagerInterface
     */
    private $storeManager;

    /**
     * @param StoreManagerInterface $storeManager
    **/
     
    public function __construct(
        StoreManagerInterface $storeManager
    ) {
        $this->storeManager = $storeManager;
    }
    /**
     * Handle various customer account actions
     */
    class AccountManagement extends \Magento\Customer\Model\AccountManagement
    {
        public function createAccountWithPasswordHash(CustomerInterface $customer, $hash, $redirectUrl = '')
        {
            echo 'checkoverridecreateAccountWithPasswordHash'; exit;
        }
    }

and check. I hope it's working.

9
  • Thanks for the answer can you please add full file code ?
    – devhs
    Aug 5, 2021 at 11:41
  • I think i execution faces issues due to improper parent construct code
    – devhs
    Aug 5, 2021 at 11:44
  • check updated ans
    – Devidas
    Aug 5, 2021 at 11:47
  • Thanks let me check it.
    – devhs
    Aug 5, 2021 at 11:56
  • Notice: Undefined property: Vendor\\Customer\\Model\\AccountManagement\\Interceptor::$storeManager
    – devhs
    Aug 5, 2021 at 11:57
0

replace first argument CustomerInterface with \Magento\Customer\Api\Data\CustomerInterface

Your Answer

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

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