I am not sure its happening with me because i am a newbie in magento2. Every time i try to override a constructor i end with an error. Tried to find out a lot but nothing helps. So at last decided to post here.
I want to override the execute
method of Magento\Catalog\Controller\Category\View
file. Basically category view page.
What i am doing is
namespace namespace\module\Controller\Magento\Catalog\Category;
class View extends \Magento\Catalog\Controller\Category\View
{
protected $_coreRegistry = null;
protected $_catalogSession;
protected $_catalogDesign;
protected $_storeManager;
protected $categoryUrlPathGenerator;
protected $resultPageFactory;
protected $resultForwardFactory;
private $layerResolver;
protected $categoryRepository;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Catalog\Model\Design $catalogDesign,
\Magento\Catalog\Model\Session $catalogSession,
\Magento\Framework\Registry $coreRegistry,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory,
Resolver $layerResolver,
CategoryRepositoryInterface $categoryRepository
) {
$this->_storeManager = $storeManager;
$this->_catalogDesign = $catalogDesign;
$this->_catalogSession = $catalogSession;
$this->_coreRegistry = $coreRegistry;
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
$this->resultPageFactory = $resultPageFactory;
$this->resultForwardFactory = $resultForwardFactory;
$this->layerResolver = $layerResolver;
$this->categoryRepository = $categoryRepository;
parent::__construct($context,$storeManager,$catalogDesign,$coreRegistry,$categoryUrlPathGenerator,$resultPageFactory,$resultForwardFactory,$layerResolver,$categoryRepository);
}
public function execute()
{
// DO your code here.
}
}
Now i am getting an error. Which says
Fatal error: Uncaught TypeError: Argument 7 passed to namespace\module\Controller\Magento\Catalog\Category\View::__construct() must be an instance of namespace\module\Controller\Magento\Catalog\Category\PageFactory, instance of Magento\Framework\View\Result\PageFactory given
I think this happens each time if its a factory class.
Not sure though. Do you guys have any idea why it shows.
Any help will be appreciated.