0

Getting issue in my controller Exception #0 (Exception): Recoverable Error: Argument 2 passed

My controller is

       /**
        * Webkul Software.
        *
        * @category  Webkul
        * @package   Webkul_Marketplace
        * @author    Webkul
        * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https://webkul.com)
        * @license   https://store.webkul.com/license.html
        */

        namespace Webkul\Marketplace\Controller\Account;

        use Magento\Framework\App\Action\Action;
        use Magento\Customer\Model\Session;
        use Magento\Framework\App\Action\Context;
        use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
        use Magento\Framework\App\Filesystem\DirectoryList;
        use Magento\Framework\Filesystem;
        use Magento\Framework\App\RequestInterface;

        /**
        * Webkul Marketplace Account EditprofilePost Controller.
        */
        class Saveareainfo extends Action
        {
            /**
            * @var \Magento\Customer\Model\Session
            */
            protected $_customerSession;

            /**
            * @var \Magento\Framework\Data\Form\FormKey\Validator
            */
            protected $_formKeyValidator;

            /**
            * @var \Magento\Framework\Stdlib\DateTime\DateTime
            */
            protected $_date;

            /**
            * @var \Magento\Framework\Filesystem\Directory\WriteInterface
            */
            protected $_mediaDirectory;

            /**
            * File Uploader factory.
            *
            * @var \Magento\MediaStorage\Model\File\UploaderFactory
            */
            protected $_fileUploaderFactory;

            /**
            * @param Context                                         $context
            * @param Session                                         $customerSession
            * @param FormKeyValidator                                $formKeyValidator
            * @param Magento\Framework\Stdlib\DateTime\DateTime      $date
            * @param Filesystem                                      $filesystem
            * @param Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
            */
            public function __construct(
                Context $context,
                \Magento\Customer\Model\Session $customerSession,
                FormKeyValidator $formKeyValidator,
                \Magento\Framework\Stdlib\DateTime\DateTime $date,
                Filesystem $filesystem,
                \Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
            ) {
                $this->_customerSession = $customerSession;
                $this->_formKeyValidator = $formKeyValidator;
                $this->_date = $date;
                $this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
                $this->_fileUploaderFactory = $fileUploaderFactory;
                parent::__construct(
                    $context
                );
            }

            /**
            * Retrieve customer session object.
            *
            * @return \Magento\Customer\Model\Session
            */
            protected function _getSession()
            {
                return $this->_customerSession;
            }

            /**
            * Check customer authentication.
            *
            * @param RequestInterface $request
            *
            * @return \Magento\Framework\App\ResponseInterface
            */
            public function dispatch(RequestInterface $request)
            {
                $loginUrl = $this->_objectManager->get(
                    'Magento\Customer\Model\Url'
                )->getLoginUrl();

                if (!$this->_customerSession->authenticate($loginUrl)) {
                    $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
                }

                return parent::dispatch($request);
            }

            /**
            * Update Seller Profile Informations.
            *
            * @return \Magento\Framework\Controller\Result\RedirectFactory
            */
            public function execute()
            {

                die("-----------------------");


                /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
                $resultRedirect = $this->resultRedirectFactory->create();

                if ($this->getRequest()->isPost()) {
                    try {
                        if (!$this->_formKeyValidator->validate($this->getRequest())) {
                            return $this->resultRedirectFactory->create()->setPath(
                                '*/*/editProfile',
                                ['_secure' => $this->getRequest()->isSecure()]
                            );
                        }
                        list($data, $errors) = $this->validateprofiledata();
                        $fields = $this->getRequest()->getParams();
                        $sellerId = $this->_getSession()->getCustomerId();
                        $img1 = '';
                        $img2 = '';
                        if (empty($errors)) {
                            $autoId = 0;
                            $collection = $this->_objectManager->create(
                                'Webkul\Marketplace\Model\Seller'
                            )
                            ->getCollection()
                            ->addFieldToFilter('seller_id', $sellerId);
                            foreach ($collection as $value) {
                                $autoId = $value->getId();
                            }
                            $fields = $this->getSellerProfileFields($fields);

                            $value = $this->_objectManager->create(
                                'Webkul\Marketplace\Model\Seller'
                            )->load($autoId);
                            $value->addData($fields);
                            $value->setUpdatedAt($this->_date->gmtDate());
                            $value->save();

                            if ($fields['company_description']) {
                                $fields['company_description'] = str_replace(
                                    'script',
                                    '',
                                    $fields['company_description']
                                );
                            }
                            $value->setCompanyDescription($fields['company_description']);

                            if (isset($fields['return_policy'])) {
                                $fields['return_policy'] = str_replace(
                                    'script',
                                    '',
                                    $fields['return_policy']
                                );
                                $value->setReturnPolicy($fields['return_policy']);
                            }

                            if (isset($fields['shipping_policy'])) {
                                $fields['shipping_policy'] = str_replace(
                                    'script',
                                    '',
                                    $fields['shipping_policy']
                                );
                                $value->setShippingPolicy($fields['shipping_policy']);
                            }

                            $value->setMetaDescription($fields['meta_description']);

                            $target = $this->_mediaDirectory->getAbsolutePath('avatar/');
                            try {
                                /** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
                                $uploader = $this->_fileUploaderFactory->create(
                                    ['fileId' => 'banner_pic']
                                );
                                $uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
                                $uploader->setAllowRenameFiles(true);
                                $result = $uploader->save($target);
                                if ($result['file']) {
                                    $value->setBannerPic($result['file']);
                                }
                            } catch (\Exception $e) {
                                $this->messageManager->addError($e->getMessage());
                            }
                            try {
                                /** @var $uploaderLogo \Magento\MediaStorage\Model\File\Uploader */
                                $uploaderLogo = $this->_fileUploaderFactory->create(
                                    ['fileId' => 'logo_pic']
                                );
                                $uploaderLogo->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
                                $uploaderLogo->setAllowRenameFiles(true);
                                $resultLogo = $uploaderLogo->save($target);
                                if ($resultLogo['file']) {
                                    $value->setLogoPic($resultLogo['file']);
                                }
                            } catch (\Exception $e) {
                                $this->messageManager->addError($e->getMessage());
                            }

                            if (array_key_exists('country_pic', $fields)) {
                                $value->setCountryPic($fields['country_pic']);
                            }
                            $value->save();

                            if (array_key_exists('country_pic', $fields)) {
                                $value->setCountryPic($fields['country_pic']);
                            }
                            $value->save();
                            try {
                                if (!empty($errors)) {
                                    foreach ($errors as $message) {
                                        $this->messageManager->addError($message);
                                    }
                                } else {
                                    $this->messageManager->addSuccess(
                                        __('Profile information was successfully saved')
                                    );
                                }

                                return $this->resultRedirectFactory->create()->setPath(
                                    '*/*/editProfile',
                                    ['_secure' => $this->getRequest()->isSecure()]
                                );
                            } catch (\Exception $e) {
                                $this->messageManager->addException($e, __('We can\'t save the customer.'));
                            }

                            return $this->resultRedirectFactory->create()->setPath(
                                '*/*/editProfile',
                                ['_secure' => $this->getRequest()->isSecure()]
                            );
                        } else {
                            foreach ($errors as $message) {
                                $this->messageManager->addError($message);
                            }

                            return $this->resultRedirectFactory->create()->setPath(
                                '*/*/editProfile',
                                ['_secure' => $this->getRequest()->isSecure()]
                            );
                        }
                    } catch (\Exception $e) {
                        $this->messageManager->addError($e->getMessage());

                        return $this->resultRedirectFactory->create()->setPath(
                            '*/*/editProfile',
                            ['_secure' => $this->getRequest()->isSecure()]
                        );
                    }
                } else {
                    return $this->resultRedirectFactory->create()->setPath(
                        '*/*/editProfile',
                        ['_secure' => $this->getRequest()->isSecure()]
                    );
                }
            }

            protected function validateprofiledata()
            {
                $errors = [];
                $data = [];
                foreach ($this->getRequest()->getParams() as $code => $value) {
                    switch ($code) :
                        case 'twitter_id':
                            if (trim($value) != '' &&
                                preg_match('/[\'^£$%&*()}{@#~?><>, |=_+¬-]/', $value)
                            ) {
                                $errors[] = __('Twitterid cannot contain space and special charecters');
                            } else {
                                $data[$code] = $value;
                            }
                            break;
                        case 'facebook_id':
                            if (trim($value) != '' &&
                                preg_match('/[\'^£$%&*()}{@#~?><>, |=_+¬-]/', $value)
                            ) {
                                $errors[] = __('Facebookid cannot contain space and special charecters');
                            } else {
                                $data[$code] = $value;
                            }
                            break;
                        case 'background_width':
                            if (trim($value) != '' &&
                                strlen($value) != 6 &&
                                substr($value, 0, 1) != '#'
                            ) {
                                $errors[] = __('Invalid Background Color');
                            } else {
                                $data[$code] = $value;
                            }
                    endswitch;
                }

                return [$data, $errors];
            }

            protected function getSellerProfileFields($fields = [])
            {
                if (!isset($fields['tw_active'])) {
                    $fields['tw_active'] = 0;
                }
                if (!isset($fields['fb_active'])) {
                    $fields['fb_active'] = 0;
                }
                if (!isset($fields['gplus_active'])) {
                    $fields['gplus_active'] = 0;
                }
                if (!isset($fields['youtube_active'])) {
                    $fields['youtube_active'] = 0;
                }
                if (!isset($fields['vimeo_active'])) {
                    $fields['vimeo_active'] = 0;
                }
                if (!isset($fields['instagram_active'])) {
                    $fields['instagram_active'] = 0;
                }
                if (!isset($fields['pinterest_active'])) {
                    $fields['pinterest_active'] = 0;
                }
                if (!isset($fields['moleskine_active'])) {
                    $fields['moleskine_active'] = 0;
                }
                return $fields;
            }
        }

Getting exception

                1 exception(s):
            Exception #0 (Exception): Recoverable Error: Argument 2 passed to Webkul\Marketplace\Controller\Account\Saveareainfo::__construct() must be an instance of Magento\Customer\Model\Session, none given, called in C:\wamp64\www\PG\var\generation\Webkul\Marketplace\Controller\Account\Saveareainfo\Interceptor.php on line 14 and defined in C:\wamp64\www\PG\app\code\Webkul\Marketplace\Controller\Account\Saveareainfo.php on line 64

            Exception #0 (Exception): Recoverable Error: Argument 2 passed to Webkul\Marketplace\Controller\Account\Saveareainfo::__construct() must be an instance of Magento\Customer\Model\Session, none given, called in C:\wamp64\www\PG\var\generation\Webkul\Marketplace\Controller\Account\Saveareainfo\Interceptor.php on line 14 and defined in C:\wamp64\www\PG\app\code\Webkul\Marketplace\Controller\Account\Saveareainfo.php on line 64
            #0 C:\wamp64\www\PG\app\code\Webkul\Marketplace\Controller\Account\Saveareainfo.php(64): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', 'C:\\wamp64\\www\\P...', 64, Array)
            #1 C:\wamp64\www\PG\var\generation\Webkul\Marketplace\Controller\Account\Saveareainfo\Interceptor.php(14): Webkul\Marketplace\Controller\Account\Saveareainfo->__construct(Object(Magento\Framework\App\Action\Context))
            #2 C:\wamp64\www\PG\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(93): Webkul\Marketplace\Controller\Account\Saveareainfo\Interceptor->__construct(Object(Magento\Framework\App\Action\Context))
            #3 C:\wamp64\www\PG\vendor\magento\framework\ObjectManager\Factory\Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Webkul\\Marketpl...', Array)
            #4 C:\wamp64\www\PG\vendor\magento\framework\ObjectManager\ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Compiled->create('Webkul\\Marketpl...', Array)
            #5 C:\wamp64\www\PG\vendor\magento\framework\App\ActionFactory.php(40): Magento\Framework\ObjectManager\ObjectManager->create('Webkul\\Marketpl...')
            #6 C:\wamp64\www\PG\vendor\magento\framework\App\Router\Base.php(300): Magento\Framework\App\ActionFactory->create('Webkul\\Marketpl...')
            #7 C:\wamp64\www\PG\vendor\magento\framework\App\Router\Base.php(161): Magento\Framework\App\Router\Base->matchAction(Object(Magento\Framework\App\Request\Http), Array)
            #8 C:\wamp64\www\PG\vendor\magento\framework\App\FrontController.php(50): Magento\Framework\App\Router\Base->match(Object(Magento\Framework\App\Request\Http))
            #9 C:\wamp64\www\PG\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
            #10 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
            #11 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')
            #12 C:\wamp64\www\PG\vendor\magento\module-store\App\FrontController\Plugin\RequestPreprocessor.php(94): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
            #13 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
            #14 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
            #15 C:\wamp64\www\PG\vendor\magento\framework\Module\Plugin\DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
            #16 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
            #17 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
            #18 C:\wamp64\www\PG\vendor\magento\module-page-cache\Model\App\FrontController\BuiltinPlugin.php(68): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
            #19 C:\wamp64\www\PG\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
            #20 C:\wamp64\www\PG\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
            #21 C:\wamp64\www\PG\vendor\magento\module-page-cache\Model\App\FrontController\VarnishPlugin.php(55): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
            #22 C:\wamp64\www\PG\vendor\magento\framework\Interception\Interceptor.php(142): Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
            #23 C:\wamp64\www\PG\var\generation\Magento\Framework\App\FrontController\Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
            #24 C:\wamp64\www\PG\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
            #25 C:\wamp64\www\PG\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
            #26 C:\wamp64\www\PG\index.php(40): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
            #27 {main}
1

1) Please clear the var/generation folder from Magento root folder.

2) Run the below command in your terminal.

rm -rf var/generation

3) Give full permission to var folder.

chmod -R 0777 var
  • Its on local machine ( localhost ) Do you think chmod will work locally ? – Peter Jul 13 '17 at 14:25
  • delete the folder Marketplace from the path var\generation\Webkul – Jjo Jul 13 '17 at 14:26
  • Okay now I removed the folder var/generation now what's next? – Peter Jul 13 '17 at 14:28
  • check folder permission for var folder having 0777. Then run the url. – Jjo Jul 13 '17 at 14:30
  • Is it working for you? – Jjo Jul 13 '17 at 14:35

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.