I have tried the following controller file to add product to cart in my custom extension.
<?php namespace MS\Recommendeditems\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { protected $productRepository; protected $cart; public function __construct( \Magento\Catalog\Model\ProductRepository $productRepository, \Magento\Checkout\Model\Cart $cart ) { $this->productRepository = $productRepository; $this->cart = $cart; } public function execute() { $this->_view->loadLayout(); $this->_view->getLayout()->initMessages(); $params = $this->getRequest()->getParams(); $options = $params['options']; $superAttribute = $params['super_attribute']; $product = $this->productRepository->getById($params['product']); $paramater = array('product' => $params['product'], 'qty' => $params['qty'], 'options' => $options, 'super_attribute' => $superAttribute ); $this->cart->addProduct($product, $request); $this->cart->save(); $this->_view->renderLayout(); } } but this code is not working and it shows the blank page.
Please help me to fix this issue.
Thanks