2

I have two modules, as "AuthorizenetCim" and "AuthorizeRobin".

In "AuthorizenetCim" model file, I want to get collection of "AuthorizeRobin" module.

So my constructor for "AuthorizenetCim" (/model/Gateway.php) is:

public function __construct(
    \ParadoxLabs\TokenBase\Helper\Data $helper,
    \ParadoxLabs\TokenBase\Model\Gateway\Xml $xml,
    \ParadoxLabs\TokenBase\Model\Gateway\ResponseFactory $responseFactory,
    \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory,
    \Magento\Framework\Module\Dir $moduleDir,
    \Magento\Framework\Registry $registry,
    /*Injecting other module's model factory */
    \Neo\Authorizerobin\Model\AuthorizerobinFactory $authorizeRobinFactory,
    /*Injection done*/
    array $data = []
) {
    $this->moduleDir = $moduleDir;
    $this->registry = $registry;
    $this->authorizeRobinFactory = $authorizeRobinFactory;

    parent::__construct(
        $helper,
        $xml,
        $responseFactory,
        $httpClientFactory,
        $data
    );
}

But I am getting following error for my constructor:

    <b>Fatal error</b>:  Uncaught TypeError: Argument 7 passed to ParadoxLabs\Authnetcim\Model\Gateway::__construct
() must be an instance of Neo\Authorizerobin\Model\AuthorizerobinFactory, array given, called in /var
/www/html/magento2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 and
 defined in /var/www/html/magento2/app/code/ParadoxLabs/Authnetcim/Model/Gateway.php:182

Stack trace:
#0 /var/www/html/magento2/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93): ParadoxLabs
\Authnetcim\Model\Gateway-&gt;__construct(Object(ParadoxLabs\TokenBase\Helper\Data), Object(ParadoxLabs
\TokenBase\Model\Gateway\Xml), Object(ParadoxLabs\TokenBase\Model\Gateway\ResponseFactory), Object(Magento
\Framework\HTTP\ZendClientFactory), Object(Magento\Framework\Module\Dir), Object(Magento\Framework\Registry
), Array)


#1 /var/www/html/magento2/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework
\ObjectManager\Factory\AbstractFactory-&gt;createObject('ParadoxLabs\\Aut...', Array)


#2 /var/ in <b>/var/www/html/magento2/app/code/ParadoxLabs/Authnetcim/Model/Gateway.php</b> on line 
<b>182</b><br />
{"messages":{"error":[{"code":500,"message":"Server internal error. See details in report api\/308753050106"
}]}}
3
  • 1
    Try to remove an old generated files using rm -rf var/generation/* from the magento root directory Apr 7, 2017 at 10:47
  • Thanks @SiarheyUchukhlebau worked for me. +1 from me. Also I can accept it as answer, if you want to give as answer Apr 7, 2017 at 11:01
  • I posted my comment as an answer Apr 7, 2017 at 11:24

1 Answer 1

10

Try to remove an old generated files using rm -rf var/generation/* command (rm -rf generated/* for the Magento >=2.2) from the magento root directory, because magento pre-generates all class files with their constructors. Generated classes extends the original classes and used by magento to call a plugins.

3
  • 1
    what to try when that doesn't work? xD
    – treyBake
    Nov 6, 2017 at 14:52
  • 1
    @ThisGuyHasTwoThumbs In case when this does not work you should check all classes passed as an arguments to the __construct method, seems some of it is incorrect. Nov 9, 2017 at 8:27
  • 1
    also remember to compile: php bin/magento setup:di:compile Sep 13, 2018 at 9:19

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.