1

I'm using Magento v2.3, I want to add out of stock products to cart without changing any configuration from backend.

I'm using following function to add product to cart

addProduct($productInfo, $requestInfo)

from following class

Magento\Checkout\Model\Cart

But it checks for saleable quantity.

Is there any way to ignore saleable check and add out of stock products to cart?

  • any specific reason instead of using default feature you want to create an extra feature which will slow down checkout? – Rahul Anand Sep 10 at 13:20
  • yes, one of my feature strictly depends on default functionality of decreasing the quantity when order is placed and no add to cart when quantity is zero, so can't change that. Feature mentioned in question will work for restricted users, so it doesn't make difference if it slow down a little. – Nausif Sep 10 at 13:28
  • I think better to look into these settings once: Set System->Configuration->Catalog->Inventory->Backorders=Allow Qty Below 0. Set System->Configuration->Catalog->Inventory->Stock Options->Display Out of Stock Products=Yes. These settings will though decrease an item on sale, but will show add to cart button even an item is 0 or <0. – Rahul Anand Sep 10 at 13:45
  • share full code please – Amit Bera Sep 10 at 14:41
0

Just an idea, I didn't test yet. I hope it helps.

  1. We can set session variable skip_is_saleable==true before your add product logic
  2. Then override the public function isSaleable() function by di.xml and check the above session variable
  3. If you found skip_is_saleable==true, always return true in isSaleable function. Otherwise, leave it as a core step in isSaleable so that it does not affect the default flow.
  4. Finally, clear the session variable skip_is_saleable
0

If you want to add out of stock products to cart without changing any configuration from the backend then you have added enable super mode of the product during add to card

    $productInfo->setIsSuperMode(true) ; 

...->addProduct($productInfo, $requestInfo);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.