HI i am building a module in which i am adding a product to cart through controller .But is throwing the below error
Recoverable Error: Argument 2 passed to Eecom\Atc\Controller\Atc\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, instance of Magento\Framework\App\Cache\TypeList given, called in C:\wamp\www\productzoom\var\generation\Eecom\Atc\Controller\Atc\Index\Interceptor.php on line 14 and defined in C:\wamp\www\productzoom\app\code\Eecom\Atc\Controller\Atc\Index.php on line 21
Below is my code
namespace Eecom\Atc\Controller\Atc;
class Index extends \Magento\Framework\App\Action\Action {
/**
* @var \Magento\Checkout\Model\Cart
*/
protected $cart;
/**
* @var \Magento\Catalog\Model\Product
*/
protected $product;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Catalog\Model\Product $product,
\Magento\Checkout\Model\Cart $cart
) {
$this->resultPageFactory = $resultPageFactory;
$this->_customerSession = $customerSession;
$this->cart = $cart;
$this->product = $product;
parent::__construct($context);
}
public function execute()
{
try {
$params = array();
$params['qty'] = '1';//product quantity
/*get product id*/
$pId = '1';//productId
$_product = $this->product->load($pId);
if ($_product) {
$this->cart->addProduct($_product, $params);
$this->cart->save();
}
$this->messageManager->addSuccess(__('Add to cart successfully.'));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addException(
$e,
__('%1', $e->getMessage())
);
} catch (\Exception $e) {
$this->messageManager->addException($e, __('error.'));
}
/*cart page*/
//$this->getResponse()->setRedirect('/checkout/cart/index');
}
}
Please suggest where i am doing mistake