1

I have successfully rewrite Magento\Customer\Model\AccountManagement using preference but after enabling paypal express its giving me error like below, on checkout and cart page.

<?xml version="1.0" encoding="UTF-8"?>
   <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\Module\Model\AccountManagement" />
   </config>

PHP Fatal error: Uncaught TypeError: Argument 21 passed to Magento\Paypal\Model\Express\Checkout::__construct() must be an instance of Magento\Customer\Model\AccountManagement, instance of Vendor\Module\Model\AccountManagement given in

/var/www/html/magento/vendor/magento/module-paypal/Model/Express/Checkout.php:300\nStack trace:\n#0 [internal function]: Magento\Paypal\Model\Express\Checkout->__construct(Object(Magento\Framework\Logger\Monolog),

Object(Magento\Customer\Model\Url), Object(Magento\Tax\Helper\Data), Object(Magento\Checkout\Helper\Data), Object(Magento\Customer\Model\Session), Object(Magento\Framework\App\Cache\Type\Config), Object(Magento\Framework\Locale\Resolver), Object(Magento\Paypal\Model\Info), Object(Magento\Store\Model\StoreManager), Object(Magento\Framework\Url), Object(Magento\Paypal\Model\CartFactory), Object(Magento\Checkout\Model\Type\OnepageFactory), Object(Magento\Quote\Model\QuoteManagement), Object(Magento\Paypal\Model\Billing\AgreementFactory), Object(Magento\Paypal\Model\Api\Type\Fact in

/var/www/html/magento/vendor/magento/module-paypal/Model/Express/Checkout.php on line 300, referer:

EDIT

My files Constructor

 public function __construct(
    CustomerFactory $customerFactory,
    ManagerInterface $eventManager,
    StoreManagerInterface $storeManager,
    Random $mathRandom,
    Validator $validator,
    ValidationResultsInterfaceFactory $validationResultsDataFactory,
    AddressRepositoryInterface $addressRepository,
    CustomerMetadataInterface $customerMetadataService,
    CustomerRegistry $customerRegistry,
    PsrLogger $logger,
    Encryptor $encryptor,
    ConfigShare $configShare,
    StringHelper $stringHelper,
    CustomerRepositoryInterface $customerRepository,
    ScopeConfigInterface $scopeConfig,
    TransportBuilder $transportBuilder,
    DataObjectProcessor $dataProcessor,
    Registry $registry,
    CustomerViewHelper $customerViewHelper,
    DateTime $dateTime,
    CustomerModel $customerModel,
    ObjectFactory $objectFactory,
    ExtensibleDataObjectConverter $extensibleDataObjectConverter
) {
    $this->customerFactory = $customerFactory;
    $this->eventManager = $eventManager;
    $this->storeManager = $storeManager;
    $this->mathRandom = $mathRandom;
    $this->validator = $validator;
    $this->validationResultsDataFactory = $validationResultsDataFactory;
    $this->addressRepository = $addressRepository;
    $this->customerMetadataService = $customerMetadataService;
    $this->customerRegistry = $customerRegistry;
    $this->logger = $logger;
    $this->encryptor = $encryptor;
    $this->configShare = $configShare;
    $this->stringHelper = $stringHelper;
    $this->customerRepository = $customerRepository;
    $this->scopeConfig = $scopeConfig;
    $this->transportBuilder = $transportBuilder;
    $this->dataProcessor = $dataProcessor;
    $this->registry = $registry;
    $this->customerViewHelper = $customerViewHelper;
    $this->dateTime = $dateTime;
    $this->customerModel = $customerModel;
    $this->objectFactory = $objectFactory;
    $this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
    $this->objectManager = ObjectManager::getInstance();
}

please suggest me ASAP.

  • Please update your Vendor\Module\Model\AccountManagement constructor in the question. – Toan Nguyen Nov 14 '17 at 23:27
0

Make sure you cleanup your temp/cache/generated files and then recompile your codebase (if running in PROD mode)

To cleanup temp/cache/generated files:

rm -rfv $MAGENTO_HOME/pub/static/*
rm -rfv $MAGENTO_HOME/generated/*
rm -rfv $MAGENTO_HOME/var/composer_home/*
rm -rfv $MAGENTO_HOME/var/view_preprocessed/*
rm -rfv $MAGENTO_HOME/var/generation/*
rm -rfv $MAGENTO_HOME/var/di/*
rm -rfv $MAGENTO_HOME/var/tmp/*
rm -rfv $MAGENTO_HOME/var/cache/*
rm -rfv $MAGENTO_HOME/var/page_cache/*
rm -rfv $MAGENTO_HOME/var/session/*

To Re-Compile your files:

cd $MAGENTO_HOME/
$MAGENTO_HOME/bin/magento setup:di:compile

If you continue to see the error message - please post the code for your rewrite class (i.e. Vendor\Module\Model\AccountManagement) here for further troubleshooting.

0
 1. Replace "Vendor" - with your Custom Module Package Name,

 2. Replace "Module" - with your Module Name in :  

    <?xml version="1.0" encoding="UTF-8"?>
    <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\Module\Model\AccountManagement" />
    </config>
  • yes, that already i have done and preference is working fine, but when i enable paypal express its giving me error on paypal payment method. – chirag Nov 14 '17 at 12:40

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.