Hello,
I have installed Prince Pincode Checker from https://github.com/mageprince/Magento2-PincodeChecker.
After installation, when I used command php bin/magento setup:di:compile It gives following error.
Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker\Save Extra parameters passed to parent construct: $coreRegistry. File : C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker/ Controller/Adminhtml/Pincodechecker/Save.php Prince\PincodeChecker\Helper\Data Incorrect dependency in class Prince\PincodeChecker\Helper\Data in C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker /Helper/Data.php \Magento\Framework\App\Config\ScopeConfigInterface already exists in context obj ect Total Errors Count: 2 Errors during compilation: Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker\Save Extra parameters passed to parent construct: $coreRegistry. File : C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker/ Controller/Adminhtml/Pincodechecker/Save.php Prince\PincodeChecker\Helper\Data Incorrect dependency in class Prince\PincodeChecker\Helper\Data in C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker /Helper/Data.php \Magento\Framework\App\Config\ScopeConfigInterface already exists in context obj ect Total Errors Count: 2 Errors during compilation: Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker\Save Extra parameters passed to parent construct: $coreRegistry. File : C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker/ Controller/Adminhtml/Pincodechecker/Save.php Prince\PincodeChecker\Helper\Data Incorrect dependency in class Prince\PincodeChecker\Helper\Data in C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker /Helper/Data.php \Magento\Framework\App\Config\ScopeConfigInterface already exists in context obj ect Total Errors Count: 2 Errors during compilation: Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker\Save Extra parameters passed to parent construct: $coreRegistry. File : C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker/ Controller/Adminhtml/Pincodechecker/Save.php Prince\PincodeChecker\Helper\Data Incorrect dependency in class Prince\PincodeChecker\Helper\Data in C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker /Helper/Data.php \Magento\Framework\App\Config\ScopeConfigInterface already exists in context obj ect Total Errors Count: 2 Errors during compilation: Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker\Save Extra parameters passed to parent construct: $coreRegistry. File : C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker/ Controller/Adminhtml/Pincodechecker/Save.php Prince\PincodeChecker\Helper\Data Incorrect dependency in class Prince\PincodeChecker\Helper\Data in C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker /Helper/Data.php \Magento\Framework\App\Config\ScopeConfigInterface already exists in context obj ect Total Errors Count: 2 Errors during compilation: Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker\Save Extra parameters passed to parent construct: $coreRegistry. File : C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker/ Controller/Adminhtml/Pincodechecker/Save.php Prince\PincodeChecker\Helper\Data Incorrect dependency in class Prince\PincodeChecker\Helper\Data in C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/app/code/Prince/PincodeChecker /Helper/Data.php \Magento\Framework\App\Config\ScopeConfigInterface already exists in context obj ect Total Errors Count: 2 Interception cache generation... 7/7 [============================] 100% 3 mins 136.0 MiB Generated code and dependency injection configuration successfully.
Magento Version: 2.1.9
Any help ?
Thanks.
Solved! Go to Solution.
Seems like there are un-necessary dependency added in Below two files
1) Save.php and 2) Data.php
In Save.php file - coreRegistery added in construct function which is actually not needed.
Below is the Re-factor code for Save.php , Copy this code and paste in Save.php
File location - Prince/PincodeChecker/Controller/Adminhtml/Pincodechecker/Save.php
<?php namespace Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker; use Magento\Framework\Exception\LocalizedException; class Save extends \Magento\Backend\App\Action { protected $dataPersistor; /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor ) { $this->dataPersistor = $dataPersistor; parent::__construct($context); } /** * Save action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); if ($data) { $id = $this->getRequest()->getParam('pincode_id'); $model = $this->_objectManager->create('Prince\PincodeChecker\Model\Pincodechecker')->load($id); if (!$model->getId() && $id) { $this->messageManager->addError(__('This Pincode no longer exists.')); return $resultRedirect->setPath('*/*/'); } $model->setData($data); try { $model->save(); $this->messageManager->addSuccess(__('You saved the Pincode.')); $this->dataPersistor->clear('prince_pincodechecker_pincodechecker'); if ($this->getRequest()->getParam('back')) { return $resultRedirect->setPath('*/*/edit', ['pincode_id' => $model->getId()]); } return $resultRedirect->setPath('*/*/'); } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the Pincode.')); } $this->dataPersistor->set('prince_pincodechecker_pincodechecker', $data); return $resultRedirect->setPath('*/*/edit', ['pincode_id' => $this->getRequest()->getParam('pincode_id')]); } return $resultRedirect->setPath('*/*/'); } }
2) In Data.php file - ScopConfig is there in construct function which is not needed.
Below is the Re-factor code for Data.php , Copy this code and paste in Data.php.
File location - Prince/PincodeChecker/Helper/Data.php
<?php namespace Prince\PincodeChecker\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { /** * @var \Prince\PincodeChecker\Model\ResourceModel\Pincodechecker\CollectionFactory */ protected $pincodeCollection; /** * @var \Magento\Catalog\Model\Product */ protected $product; /** * @var \Magento\Framework\Controller\ResultFactory */ protected $resultFactory; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $scopeConfig; /** * Constructor * * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Catalog\Model\Product $product * @param \Prince\PincodeChecker\Model\ResourceModel\Pincodechecker\CollectionFactory $pincodeCollection * @param \Magento\Framework\Controller\ResultFactory $resultFactory */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product $product, \Prince\PincodeChecker\Model\ResourceModel\Pincodechecker\CollectionFactory $pincodeCollection, \Magento\Framework\Controller\ResultFactory $resultFactory ) { $this->pincodeCollection = $pincodeCollection; $this->product = $product; $this->resultFactory = $resultFactory; parent::__construct($context); } /** * Get collection of pincode */ public function getCollection() { return $this->pincodeCollection->create(); } /** * Get pincode status */ public function getPincodeStatus($pincode) { $collection = $this->getCollection(); $collection->addFieldToFilter('pincode', array('eq' => $pincode)); if($collection->getData()){ return true; }else{ return false; } } /** * Get pincode status by product */ public function getProductPincodeStatus($id, $pincode) { $product = $this->product->load($id); $pincodes = $product->getData('pincode'); $pincodeArr = explode(',', $pincodes); if(in_array($pincode, $pincodeArr)) { return true; }else{ return false; } } /** * Get pincode status message */ public function getMessage($status, $pincode) { if($status){ $message = "<h3>".$this->getSuccessMessage()."</h3>"; }else{ $message = "<h3 style='color:red'>".$this->getFailMessage()."</h3>"; } return $message; } /** * Get redirect url */ public function getRedirect() { $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($this->_redirect->getRefererUrl()); return $resultRedirect; } /** * Check module enable */ public function getIsEnable() { return $this->scopeConfig->getValue('pincode/general/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } /** * Get check on addtocart config value */ public function getIsCheckonAddtoCart() { return $this->scopeConfig->getValue('pincode/general/checkaddtocart', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } /** * Get success message config value */ public function getSuccessMessage() { return $this->scopeConfig->getValue('pincode/general/successmessage', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } /** * Get fail message config value */ public function getFailMessage() { return $this->scopeConfig->getValue('pincode/general/failmessage', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } }
Seems like there are un-necessary dependency added in Below two files
1) Save.php and 2) Data.php
In Save.php file - coreRegistery added in construct function which is actually not needed.
Below is the Re-factor code for Save.php , Copy this code and paste in Save.php
File location - Prince/PincodeChecker/Controller/Adminhtml/Pincodechecker/Save.php
<?php namespace Prince\PincodeChecker\Controller\Adminhtml\Pincodechecker; use Magento\Framework\Exception\LocalizedException; class Save extends \Magento\Backend\App\Action { protected $dataPersistor; /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor */ public function __construct( \Magento\Backend\App\Action\Context $context, \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor ) { $this->dataPersistor = $dataPersistor; parent::__construct($context); } /** * Save action * * @return \Magento\Framework\Controller\ResultInterface */ public function execute() { /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); if ($data) { $id = $this->getRequest()->getParam('pincode_id'); $model = $this->_objectManager->create('Prince\PincodeChecker\Model\Pincodechecker')->load($id); if (!$model->getId() && $id) { $this->messageManager->addError(__('This Pincode no longer exists.')); return $resultRedirect->setPath('*/*/'); } $model->setData($data); try { $model->save(); $this->messageManager->addSuccess(__('You saved the Pincode.')); $this->dataPersistor->clear('prince_pincodechecker_pincodechecker'); if ($this->getRequest()->getParam('back')) { return $resultRedirect->setPath('*/*/edit', ['pincode_id' => $model->getId()]); } return $resultRedirect->setPath('*/*/'); } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the Pincode.')); } $this->dataPersistor->set('prince_pincodechecker_pincodechecker', $data); return $resultRedirect->setPath('*/*/edit', ['pincode_id' => $this->getRequest()->getParam('pincode_id')]); } return $resultRedirect->setPath('*/*/'); } }
2) In Data.php file - ScopConfig is there in construct function which is not needed.
Below is the Re-factor code for Data.php , Copy this code and paste in Data.php.
File location - Prince/PincodeChecker/Helper/Data.php
<?php namespace Prince\PincodeChecker\Helper; class Data extends \Magento\Framework\App\Helper\AbstractHelper { /** * @var \Prince\PincodeChecker\Model\ResourceModel\Pincodechecker\CollectionFactory */ protected $pincodeCollection; /** * @var \Magento\Catalog\Model\Product */ protected $product; /** * @var \Magento\Framework\Controller\ResultFactory */ protected $resultFactory; /** * @var \Magento\Framework\App\Config\ScopeConfigInterface */ protected $scopeConfig; /** * Constructor * * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Catalog\Model\Product $product * @param \Prince\PincodeChecker\Model\ResourceModel\Pincodechecker\CollectionFactory $pincodeCollection * @param \Magento\Framework\Controller\ResultFactory $resultFactory */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product $product, \Prince\PincodeChecker\Model\ResourceModel\Pincodechecker\CollectionFactory $pincodeCollection, \Magento\Framework\Controller\ResultFactory $resultFactory ) { $this->pincodeCollection = $pincodeCollection; $this->product = $product; $this->resultFactory = $resultFactory; parent::__construct($context); } /** * Get collection of pincode */ public function getCollection() { return $this->pincodeCollection->create(); } /** * Get pincode status */ public function getPincodeStatus($pincode) { $collection = $this->getCollection(); $collection->addFieldToFilter('pincode', array('eq' => $pincode)); if($collection->getData()){ return true; }else{ return false; } } /** * Get pincode status by product */ public function getProductPincodeStatus($id, $pincode) { $product = $this->product->load($id); $pincodes = $product->getData('pincode'); $pincodeArr = explode(',', $pincodes); if(in_array($pincode, $pincodeArr)) { return true; }else{ return false; } } /** * Get pincode status message */ public function getMessage($status, $pincode) { if($status){ $message = "<h3>".$this->getSuccessMessage()."</h3>"; }else{ $message = "<h3 style='color:red'>".$this->getFailMessage()."</h3>"; } return $message; } /** * Get redirect url */ public function getRedirect() { $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($this->_redirect->getRefererUrl()); return $resultRedirect; } /** * Check module enable */ public function getIsEnable() { return $this->scopeConfig->getValue('pincode/general/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } /** * Get check on addtocart config value */ public function getIsCheckonAddtoCart() { return $this->scopeConfig->getValue('pincode/general/checkaddtocart', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } /** * Get success message config value */ public function getSuccessMessage() { return $this->scopeConfig->getValue('pincode/general/successmessage', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } /** * Get fail message config value */ public function getFailMessage() { return $this->scopeConfig->getValue('pincode/general/failmessage', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } }
Thanks for reply.
I have replaced the code in files by your code, both in Save.php and Data.php
Then I ran following commands again
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento setup:di:compile
This gives following error.
C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs>php bin/magento setup:di:compile The directory "C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/var/generation/Mag ento/Newsletter/Controller/Adminhtml/Subscriber" cannot be deleted Warning!rmdir (C:/Bitnami/magento-2.1.9-0/apps/magento/htdocs/var/generation/Magento/Newslette r/Controller/Adminhtml/Subscriber): Directory not empty#0 C:\Bitnami\magento-2.1 .9-0\apps\magento\htdocs\vendor\magento\framework\Filesystem\Driver\File.php(403 ): Magento\Framework\Filesystem\Driver\File->deleteDirectory('C:/Bitnami/mage... ') #1 C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\vendor\magento\framework\Files ystem\Driver\File.php(403): Magento\Framework\Filesystem\Driver\File->deleteDire ctory('C:/Bitnami/mage...') #2 C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\vendor\magento\framework\Files ystem\Driver\File.php(403): Magento\Framework\Filesystem\Driver\File->deleteDire ctory('C:/Bitnami/mage...') #3 C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\vendor\magento\framework\Files ystem\Driver\File.php(403): Magento\Framework\Filesystem\Driver\File->deleteDire ctory('C:/Bitnami/mage...') #4 C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\vendor\magento\framework\Files ystem\Driver\File.php(403): Magento\Framework\Filesystem\Driver\File->deleteDire ctory('C:/Bitnami/mage...') #5 C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\setup\src\Magento\Setup\Consol e\CompilerPreparation.php(68): Magento\Framework\Filesystem\Driver\File->deleteD irectory('C:/Bitnami/mage...') #6 C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\vendor\magento\framework\Conso le\Cli.php(74): Magento\Setup\Console\CompilerPreparation->handleCompilerEnviron ment() #7 C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\bin\magento(22): Magento\Frame work\Console\Cli->__construct('Magento CLI') #8 {main} PHP Fatal error: Uncaught Error: Class 'Cli' not found in C:\Bitnami\magento-2. 1.9-0\apps\magento\htdocs\bin\magento:31 Stack trace: #0 {main} thrown in C:\Bitnami\magento-2.1.9-0\apps\magento\htdocs\bin\magento on line 3 1
Thanks
The error comes from var/generation directory.
You just need to remove your var/generation directory from your root directory.
Also remove var/cache and var/page_cache directory from your root directory.
you can remove those directories by running below commands.
Then run following commands again
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento setup:di:compile
Fantastic !!
Thanks Manthan.
It is working and ended with no errors. I am very happy, as I needed this extension very much.
You guys are very helpful.
Thanks again.
Glad to know that you have resolved your issue , Happy to help and keep helping !!
i am getting this error . I followed all instruction that you have showed here but when i click on add ton cart i get this error .
Error: Class 'Prince\PincodeChecker\Helper\ResultFactory' not found in C:\xampp\htdocs\magento2.4\app\code\Prince\PincodeChecker\Helper\Data.php:109 Stack trace: #0