I have a store which contains only downloadable products.
I'd like to prevent the same product from being added in quantities greater than 1 and remove the quantity field from everywhere (cart, minicart, etc).
I tried to use a Plugin in my module but it doesn't work.
app/code/Vendor/Module/etc/di.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <!-- Frontend --> <type name="Magento\Checkout\Model\Cart"> <plugin disabled="false" name="Vendor_Module_Plugin_Magento_Checkout_Cart_BeforeAddToCart" type="Vendor\Module\Plugin\Magento\Checkout\Cart\BeforeAddToCart"/> </type> </config> app/code/Vendor/Module/Plugin/Magento/Checkout/Cart/BeforeAddToCart.php
<?php declare(strict_types=1); namespace Vendor\Module\Plugin\Magento\Checkout\Cart; use Magento\Checkout\Model\Cart; use Magento\Checkout\Helper\Cart as CartHelper; use Magento\Catalog\Model\Product; use Magento\Checkout\Model\Session\Proxy as SessionProxy; use Magento\Framework\Message\ManagerInterface; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Store\Model\StoreManagerInterface; use Magento\Checkout\Model\Session; use Magento\Framework\UrlInterface; class BeforeAddToCart { public function beforeAddProduct(\Magento\Checkout\Model\Cart $subject, $productInfo, $requestInfo=null){ $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $session = $objectManager->create('\Magento\Checkout\Model\Session'); $product_id = $requestInfo['product']; $quote = $session->getQuote()->hasProductId($product_id); if($quote){ // redirect to cart $this->session->setRedirectUrl($this->url->getUrl('checkout/cart/index')); throw new \Magento\Framework\Exception\LocalizedException( __("[x] This product is already in the cart. Testing, testing : ". $product->getSku()) ); } return [$productInfo, $requestInfo]; } } 
$requestInfo['qty'] = 1;, it doesn't work.