How to create a module that will check if there is an item in the basket? Verification is needed on the product page.
1 Answer
Try to use this below code :
public function __construct(
\Magento\Checkout\Model\Cart $cart
) {
$this->_cart = $cart;
}
public function getProductData()
{
$productInfo = $this->_cart->getQuote()->getItemsCollection();
foreach ($productInfo as $item){
$item->getProductId();
if($item->getProductId() == 'your_product_id')
{
echo "Item available in cart";
}
else
{
echo "Item not available in cart";
}
}
}
-
-
-
What structure should be? I just do not understand what should be in the model and what should be in the block, etc. Commented Apr 8, 2019 at 10:23
-
-