Allow only one qty of item into cart in Magento 2

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I have created a custom controller in my module and calling via ajax to add the item to cart.



Below is my controller code.



<?php 

namespace VendorModuleControllerProduct;
class AddProduct extends MagentoFrameworkAppActionAction

protected $formKey;
protected $cart;
protected $product;
protected $checkoutSession;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkDataFormFormKey $formKey,
MagentoCheckoutModelCart $cart,
MagentoCatalogModelProductFactory $product,
MagentoCheckoutModelSession $checkoutSession,
array $data = )
$this->formKey = $formKey;
$this->cart = $cart;
$this->product = $product;
$this->checkoutSession = $checkoutSession;
parent::__construct($context);

public function execute()

$productId = 1;
$customPrice = 150;
$params = array(
'form_key' => $this->formKey->getFormKey(),
'product_id' => $productId, //product Id
'qty' => 1 //quantity of product
);
$_product = $this->product->create()->load($productId);
$this->cart->addProduct($_product, $params);

$productItem = $this->getProductQuote($_product);
$productItem->setCustomPrice($customPrice);
$productItem->setOriginalCustomPrice($customPrice);
//Enable super mode on the product.
$productItem->getProduct()->setIsSuperMode(true);
$this->cart->save();
echo "success";



public function getProductQuote($product)

$quote = $this->checkoutSession->getQuote();
$cartItems = $quote->getItemByProduct($product);
return $cartItems;




The above code adds the product of qty 1 to the cart with a custom price whenever it is called.



I want to add only 1 qty of product to the cart. suppose if its called two or three times, only one qty should be present in cart. Need to remove previously added qty from the cart.



Is something can be done programmatically? There is a product setting in backend "Maximum qty allowed in cart", we can set this value but I am looking for the code how it can be done programmatically.



Can anyone look into it and help me, please. Thanks










share|improve this question
























  • Try the below answer

    – Prathap Gunasekaran
    Mar 12 at 13:12

















3















I have created a custom controller in my module and calling via ajax to add the item to cart.



Below is my controller code.



<?php 

namespace VendorModuleControllerProduct;
class AddProduct extends MagentoFrameworkAppActionAction

protected $formKey;
protected $cart;
protected $product;
protected $checkoutSession;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkDataFormFormKey $formKey,
MagentoCheckoutModelCart $cart,
MagentoCatalogModelProductFactory $product,
MagentoCheckoutModelSession $checkoutSession,
array $data = )
$this->formKey = $formKey;
$this->cart = $cart;
$this->product = $product;
$this->checkoutSession = $checkoutSession;
parent::__construct($context);

public function execute()

$productId = 1;
$customPrice = 150;
$params = array(
'form_key' => $this->formKey->getFormKey(),
'product_id' => $productId, //product Id
'qty' => 1 //quantity of product
);
$_product = $this->product->create()->load($productId);
$this->cart->addProduct($_product, $params);

$productItem = $this->getProductQuote($_product);
$productItem->setCustomPrice($customPrice);
$productItem->setOriginalCustomPrice($customPrice);
//Enable super mode on the product.
$productItem->getProduct()->setIsSuperMode(true);
$this->cart->save();
echo "success";



public function getProductQuote($product)

$quote = $this->checkoutSession->getQuote();
$cartItems = $quote->getItemByProduct($product);
return $cartItems;




The above code adds the product of qty 1 to the cart with a custom price whenever it is called.



I want to add only 1 qty of product to the cart. suppose if its called two or three times, only one qty should be present in cart. Need to remove previously added qty from the cart.



Is something can be done programmatically? There is a product setting in backend "Maximum qty allowed in cart", we can set this value but I am looking for the code how it can be done programmatically.



Can anyone look into it and help me, please. Thanks










share|improve this question
























  • Try the below answer

    – Prathap Gunasekaran
    Mar 12 at 13:12













3












3








3








I have created a custom controller in my module and calling via ajax to add the item to cart.



Below is my controller code.



<?php 

namespace VendorModuleControllerProduct;
class AddProduct extends MagentoFrameworkAppActionAction

protected $formKey;
protected $cart;
protected $product;
protected $checkoutSession;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkDataFormFormKey $formKey,
MagentoCheckoutModelCart $cart,
MagentoCatalogModelProductFactory $product,
MagentoCheckoutModelSession $checkoutSession,
array $data = )
$this->formKey = $formKey;
$this->cart = $cart;
$this->product = $product;
$this->checkoutSession = $checkoutSession;
parent::__construct($context);

public function execute()

$productId = 1;
$customPrice = 150;
$params = array(
'form_key' => $this->formKey->getFormKey(),
'product_id' => $productId, //product Id
'qty' => 1 //quantity of product
);
$_product = $this->product->create()->load($productId);
$this->cart->addProduct($_product, $params);

$productItem = $this->getProductQuote($_product);
$productItem->setCustomPrice($customPrice);
$productItem->setOriginalCustomPrice($customPrice);
//Enable super mode on the product.
$productItem->getProduct()->setIsSuperMode(true);
$this->cart->save();
echo "success";



public function getProductQuote($product)

$quote = $this->checkoutSession->getQuote();
$cartItems = $quote->getItemByProduct($product);
return $cartItems;




The above code adds the product of qty 1 to the cart with a custom price whenever it is called.



I want to add only 1 qty of product to the cart. suppose if its called two or three times, only one qty should be present in cart. Need to remove previously added qty from the cart.



Is something can be done programmatically? There is a product setting in backend "Maximum qty allowed in cart", we can set this value but I am looking for the code how it can be done programmatically.



Can anyone look into it and help me, please. Thanks










share|improve this question
















I have created a custom controller in my module and calling via ajax to add the item to cart.



Below is my controller code.



<?php 

namespace VendorModuleControllerProduct;
class AddProduct extends MagentoFrameworkAppActionAction

protected $formKey;
protected $cart;
protected $product;
protected $checkoutSession;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkDataFormFormKey $formKey,
MagentoCheckoutModelCart $cart,
MagentoCatalogModelProductFactory $product,
MagentoCheckoutModelSession $checkoutSession,
array $data = )
$this->formKey = $formKey;
$this->cart = $cart;
$this->product = $product;
$this->checkoutSession = $checkoutSession;
parent::__construct($context);

public function execute()

$productId = 1;
$customPrice = 150;
$params = array(
'form_key' => $this->formKey->getFormKey(),
'product_id' => $productId, //product Id
'qty' => 1 //quantity of product
);
$_product = $this->product->create()->load($productId);
$this->cart->addProduct($_product, $params);

$productItem = $this->getProductQuote($_product);
$productItem->setCustomPrice($customPrice);
$productItem->setOriginalCustomPrice($customPrice);
//Enable super mode on the product.
$productItem->getProduct()->setIsSuperMode(true);
$this->cart->save();
echo "success";



public function getProductQuote($product)

$quote = $this->checkoutSession->getQuote();
$cartItems = $quote->getItemByProduct($product);
return $cartItems;




The above code adds the product of qty 1 to the cart with a custom price whenever it is called.



I want to add only 1 qty of product to the cart. suppose if its called two or three times, only one qty should be present in cart. Need to remove previously added qty from the cart.



Is something can be done programmatically? There is a product setting in backend "Maximum qty allowed in cart", we can set this value but I am looking for the code how it can be done programmatically.



Can anyone look into it and help me, please. Thanks







magento2 product addtocart controllers






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 12 at 6:39









magefms

2,5932526




2,5932526










asked Mar 12 at 6:23









jafar pinjarjafar pinjar

787415




787415












  • Try the below answer

    – Prathap Gunasekaran
    Mar 12 at 13:12

















  • Try the below answer

    – Prathap Gunasekaran
    Mar 12 at 13:12
















Try the below answer

– Prathap Gunasekaran
Mar 12 at 13:12





Try the below answer

– Prathap Gunasekaran
Mar 12 at 13:12










2 Answers
2






active

oldest

votes


















1














You can use getItemByProduct




If Item is exist -> use addProduct function -> else -> use updateItem function




$item = $this->cart->getQuote()->getItemByProduct($_product);
if ($item)
$this->cart->addProduct($_product, $params);
else
$this->cart->updateItem($item->getId(), 1);






share|improve this answer

























  • hi, Thank you, but you are doing reversely I think,

    – jafar pinjar
    Mar 12 at 7:41












  • hi, this code doesn't work for me

    – jafar pinjar
    Mar 12 at 8:11











  • Does it work for you?

    – jafar pinjar
    Mar 13 at 7:00











  • Yes, it works. Item qty always = 1

    – bang.nguyen47
    Mar 13 at 7:02











  • what about custom price? for me it didn't work,

    – jafar pinjar
    Mar 13 at 7:08


















0














Why you do that programmatically ? You can set it by Magento 2 configuration :




Store -> Configuration -> Catalog -> Inventory -> Product Stock Options -> Maximum Qty Allowed in Shopping Cart




Set 1 here. It will working.



EDIT :



events.xml :



<event name="controller_action_predispatch_checkout_cart_add">
<observer name="vendor_model_cart_add_before" instance="VendorModuleObserverCartAddBefore" />
</event>


CartAddBefore.php :



<?php
namespace VendorModuleObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;

class CartAddBefore implements ObserverInterface

protected $_cart;
protected $_messageManager;
protected $_request;


public function __construct(
MagentoCheckoutModelCart $cart,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoFrameworkAppRequestInterface $request,
)
$this->_cart = $cart;
$this->_messageManager = $messageManager;
$this->_request = $request;


public function execute(MagentoFrameworkEventObserver $observer)

$postValues = $this->_request->getPostValue();
$cartItemsCount = $this->_cart->getQuote()->getItemsCount();

if($cartItemsCount > 1)

...... your logic .......
$this->_messageManager->addError(__('Sorry, Only 1 product is allowed'));








share|improve this answer

























  • yes this option is there, but we are not using admin feature as per the requirement, trying to handle programmatically, that's why i mentioned in question

    – jafar pinjar
    Mar 12 at 11:15











  • so, trying to delete old quote from id and update with new one. If enabled the above setting the error message will be shown to the user, we are avoiding that one

    – jafar pinjar
    Mar 12 at 11:17











  • Check updated answer.

    – Rohan Hapani
    Mar 12 at 11:24











  • I am calling the controller from ajax request, so can you please help me in giving answer for removing old quote of the product, and add new one, because i don't want to show any error message to the customer, @Rohan, The requirement is like that pls

    – jafar pinjar
    Mar 12 at 11:27












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f265396%2fallow-only-one-qty-of-item-into-cart-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can use getItemByProduct




If Item is exist -> use addProduct function -> else -> use updateItem function




$item = $this->cart->getQuote()->getItemByProduct($_product);
if ($item)
$this->cart->addProduct($_product, $params);
else
$this->cart->updateItem($item->getId(), 1);






share|improve this answer

























  • hi, Thank you, but you are doing reversely I think,

    – jafar pinjar
    Mar 12 at 7:41












  • hi, this code doesn't work for me

    – jafar pinjar
    Mar 12 at 8:11











  • Does it work for you?

    – jafar pinjar
    Mar 13 at 7:00











  • Yes, it works. Item qty always = 1

    – bang.nguyen47
    Mar 13 at 7:02











  • what about custom price? for me it didn't work,

    – jafar pinjar
    Mar 13 at 7:08















1














You can use getItemByProduct




If Item is exist -> use addProduct function -> else -> use updateItem function




$item = $this->cart->getQuote()->getItemByProduct($_product);
if ($item)
$this->cart->addProduct($_product, $params);
else
$this->cart->updateItem($item->getId(), 1);






share|improve this answer

























  • hi, Thank you, but you are doing reversely I think,

    – jafar pinjar
    Mar 12 at 7:41












  • hi, this code doesn't work for me

    – jafar pinjar
    Mar 12 at 8:11











  • Does it work for you?

    – jafar pinjar
    Mar 13 at 7:00











  • Yes, it works. Item qty always = 1

    – bang.nguyen47
    Mar 13 at 7:02











  • what about custom price? for me it didn't work,

    – jafar pinjar
    Mar 13 at 7:08













1












1








1







You can use getItemByProduct




If Item is exist -> use addProduct function -> else -> use updateItem function




$item = $this->cart->getQuote()->getItemByProduct($_product);
if ($item)
$this->cart->addProduct($_product, $params);
else
$this->cart->updateItem($item->getId(), 1);






share|improve this answer















You can use getItemByProduct




If Item is exist -> use addProduct function -> else -> use updateItem function




$item = $this->cart->getQuote()->getItemByProduct($_product);
if ($item)
$this->cart->addProduct($_product, $params);
else
$this->cart->updateItem($item->getId(), 1);







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 12 at 7:05









magefms

2,5932526




2,5932526










answered Mar 12 at 6:51









bang.nguyen47bang.nguyen47

1115




1115












  • hi, Thank you, but you are doing reversely I think,

    – jafar pinjar
    Mar 12 at 7:41












  • hi, this code doesn't work for me

    – jafar pinjar
    Mar 12 at 8:11











  • Does it work for you?

    – jafar pinjar
    Mar 13 at 7:00











  • Yes, it works. Item qty always = 1

    – bang.nguyen47
    Mar 13 at 7:02











  • what about custom price? for me it didn't work,

    – jafar pinjar
    Mar 13 at 7:08

















  • hi, Thank you, but you are doing reversely I think,

    – jafar pinjar
    Mar 12 at 7:41












  • hi, this code doesn't work for me

    – jafar pinjar
    Mar 12 at 8:11











  • Does it work for you?

    – jafar pinjar
    Mar 13 at 7:00











  • Yes, it works. Item qty always = 1

    – bang.nguyen47
    Mar 13 at 7:02











  • what about custom price? for me it didn't work,

    – jafar pinjar
    Mar 13 at 7:08
















hi, Thank you, but you are doing reversely I think,

– jafar pinjar
Mar 12 at 7:41






hi, Thank you, but you are doing reversely I think,

– jafar pinjar
Mar 12 at 7:41














hi, this code doesn't work for me

– jafar pinjar
Mar 12 at 8:11





hi, this code doesn't work for me

– jafar pinjar
Mar 12 at 8:11













Does it work for you?

– jafar pinjar
Mar 13 at 7:00





Does it work for you?

– jafar pinjar
Mar 13 at 7:00













Yes, it works. Item qty always = 1

– bang.nguyen47
Mar 13 at 7:02





Yes, it works. Item qty always = 1

– bang.nguyen47
Mar 13 at 7:02













what about custom price? for me it didn't work,

– jafar pinjar
Mar 13 at 7:08





what about custom price? for me it didn't work,

– jafar pinjar
Mar 13 at 7:08













0














Why you do that programmatically ? You can set it by Magento 2 configuration :




Store -> Configuration -> Catalog -> Inventory -> Product Stock Options -> Maximum Qty Allowed in Shopping Cart




Set 1 here. It will working.



EDIT :



events.xml :



<event name="controller_action_predispatch_checkout_cart_add">
<observer name="vendor_model_cart_add_before" instance="VendorModuleObserverCartAddBefore" />
</event>


CartAddBefore.php :



<?php
namespace VendorModuleObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;

class CartAddBefore implements ObserverInterface

protected $_cart;
protected $_messageManager;
protected $_request;


public function __construct(
MagentoCheckoutModelCart $cart,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoFrameworkAppRequestInterface $request,
)
$this->_cart = $cart;
$this->_messageManager = $messageManager;
$this->_request = $request;


public function execute(MagentoFrameworkEventObserver $observer)

$postValues = $this->_request->getPostValue();
$cartItemsCount = $this->_cart->getQuote()->getItemsCount();

if($cartItemsCount > 1)

...... your logic .......
$this->_messageManager->addError(__('Sorry, Only 1 product is allowed'));








share|improve this answer

























  • yes this option is there, but we are not using admin feature as per the requirement, trying to handle programmatically, that's why i mentioned in question

    – jafar pinjar
    Mar 12 at 11:15











  • so, trying to delete old quote from id and update with new one. If enabled the above setting the error message will be shown to the user, we are avoiding that one

    – jafar pinjar
    Mar 12 at 11:17











  • Check updated answer.

    – Rohan Hapani
    Mar 12 at 11:24











  • I am calling the controller from ajax request, so can you please help me in giving answer for removing old quote of the product, and add new one, because i don't want to show any error message to the customer, @Rohan, The requirement is like that pls

    – jafar pinjar
    Mar 12 at 11:27
















0














Why you do that programmatically ? You can set it by Magento 2 configuration :




Store -> Configuration -> Catalog -> Inventory -> Product Stock Options -> Maximum Qty Allowed in Shopping Cart




Set 1 here. It will working.



EDIT :



events.xml :



<event name="controller_action_predispatch_checkout_cart_add">
<observer name="vendor_model_cart_add_before" instance="VendorModuleObserverCartAddBefore" />
</event>


CartAddBefore.php :



<?php
namespace VendorModuleObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;

class CartAddBefore implements ObserverInterface

protected $_cart;
protected $_messageManager;
protected $_request;


public function __construct(
MagentoCheckoutModelCart $cart,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoFrameworkAppRequestInterface $request,
)
$this->_cart = $cart;
$this->_messageManager = $messageManager;
$this->_request = $request;


public function execute(MagentoFrameworkEventObserver $observer)

$postValues = $this->_request->getPostValue();
$cartItemsCount = $this->_cart->getQuote()->getItemsCount();

if($cartItemsCount > 1)

...... your logic .......
$this->_messageManager->addError(__('Sorry, Only 1 product is allowed'));








share|improve this answer

























  • yes this option is there, but we are not using admin feature as per the requirement, trying to handle programmatically, that's why i mentioned in question

    – jafar pinjar
    Mar 12 at 11:15











  • so, trying to delete old quote from id and update with new one. If enabled the above setting the error message will be shown to the user, we are avoiding that one

    – jafar pinjar
    Mar 12 at 11:17











  • Check updated answer.

    – Rohan Hapani
    Mar 12 at 11:24











  • I am calling the controller from ajax request, so can you please help me in giving answer for removing old quote of the product, and add new one, because i don't want to show any error message to the customer, @Rohan, The requirement is like that pls

    – jafar pinjar
    Mar 12 at 11:27














0












0








0







Why you do that programmatically ? You can set it by Magento 2 configuration :




Store -> Configuration -> Catalog -> Inventory -> Product Stock Options -> Maximum Qty Allowed in Shopping Cart




Set 1 here. It will working.



EDIT :



events.xml :



<event name="controller_action_predispatch_checkout_cart_add">
<observer name="vendor_model_cart_add_before" instance="VendorModuleObserverCartAddBefore" />
</event>


CartAddBefore.php :



<?php
namespace VendorModuleObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;

class CartAddBefore implements ObserverInterface

protected $_cart;
protected $_messageManager;
protected $_request;


public function __construct(
MagentoCheckoutModelCart $cart,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoFrameworkAppRequestInterface $request,
)
$this->_cart = $cart;
$this->_messageManager = $messageManager;
$this->_request = $request;


public function execute(MagentoFrameworkEventObserver $observer)

$postValues = $this->_request->getPostValue();
$cartItemsCount = $this->_cart->getQuote()->getItemsCount();

if($cartItemsCount > 1)

...... your logic .......
$this->_messageManager->addError(__('Sorry, Only 1 product is allowed'));








share|improve this answer















Why you do that programmatically ? You can set it by Magento 2 configuration :




Store -> Configuration -> Catalog -> Inventory -> Product Stock Options -> Maximum Qty Allowed in Shopping Cart




Set 1 here. It will working.



EDIT :



events.xml :



<event name="controller_action_predispatch_checkout_cart_add">
<observer name="vendor_model_cart_add_before" instance="VendorModuleObserverCartAddBefore" />
</event>


CartAddBefore.php :



<?php
namespace VendorModuleObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkAppObjectManager;

class CartAddBefore implements ObserverInterface

protected $_cart;
protected $_messageManager;
protected $_request;


public function __construct(
MagentoCheckoutModelCart $cart,
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoFrameworkAppRequestInterface $request,
)
$this->_cart = $cart;
$this->_messageManager = $messageManager;
$this->_request = $request;


public function execute(MagentoFrameworkEventObserver $observer)

$postValues = $this->_request->getPostValue();
$cartItemsCount = $this->_cart->getQuote()->getItemsCount();

if($cartItemsCount > 1)

...... your logic .......
$this->_messageManager->addError(__('Sorry, Only 1 product is allowed'));









share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 12 at 11:24

























answered Mar 12 at 11:11









Rohan HapaniRohan Hapani

6,87931865




6,87931865












  • yes this option is there, but we are not using admin feature as per the requirement, trying to handle programmatically, that's why i mentioned in question

    – jafar pinjar
    Mar 12 at 11:15











  • so, trying to delete old quote from id and update with new one. If enabled the above setting the error message will be shown to the user, we are avoiding that one

    – jafar pinjar
    Mar 12 at 11:17











  • Check updated answer.

    – Rohan Hapani
    Mar 12 at 11:24











  • I am calling the controller from ajax request, so can you please help me in giving answer for removing old quote of the product, and add new one, because i don't want to show any error message to the customer, @Rohan, The requirement is like that pls

    – jafar pinjar
    Mar 12 at 11:27


















  • yes this option is there, but we are not using admin feature as per the requirement, trying to handle programmatically, that's why i mentioned in question

    – jafar pinjar
    Mar 12 at 11:15











  • so, trying to delete old quote from id and update with new one. If enabled the above setting the error message will be shown to the user, we are avoiding that one

    – jafar pinjar
    Mar 12 at 11:17











  • Check updated answer.

    – Rohan Hapani
    Mar 12 at 11:24











  • I am calling the controller from ajax request, so can you please help me in giving answer for removing old quote of the product, and add new one, because i don't want to show any error message to the customer, @Rohan, The requirement is like that pls

    – jafar pinjar
    Mar 12 at 11:27

















yes this option is there, but we are not using admin feature as per the requirement, trying to handle programmatically, that's why i mentioned in question

– jafar pinjar
Mar 12 at 11:15





yes this option is there, but we are not using admin feature as per the requirement, trying to handle programmatically, that's why i mentioned in question

– jafar pinjar
Mar 12 at 11:15













so, trying to delete old quote from id and update with new one. If enabled the above setting the error message will be shown to the user, we are avoiding that one

– jafar pinjar
Mar 12 at 11:17





so, trying to delete old quote from id and update with new one. If enabled the above setting the error message will be shown to the user, we are avoiding that one

– jafar pinjar
Mar 12 at 11:17













Check updated answer.

– Rohan Hapani
Mar 12 at 11:24





Check updated answer.

– Rohan Hapani
Mar 12 at 11:24













I am calling the controller from ajax request, so can you please help me in giving answer for removing old quote of the product, and add new one, because i don't want to show any error message to the customer, @Rohan, The requirement is like that pls

– jafar pinjar
Mar 12 at 11:27






I am calling the controller from ajax request, so can you please help me in giving answer for removing old quote of the product, and add new one, because i don't want to show any error message to the customer, @Rohan, The requirement is like that pls

– jafar pinjar
Mar 12 at 11:27


















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f265396%2fallow-only-one-qty-of-item-into-cart-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?