719-286-0751 [email protected]

Fixing “Not enough items for sale” at Place Order in Hyvä Checkout When the Product Is in Stock (Magento 2)

A shopper adds a configurable product to the cart, the cart accepts it, and the checkout loads normally. At Place Order the answer is:

Not enough items for sale

The product is in stock. The quantity in the cart is within what is available. The pattern only becomes clear when you line up a few cases: the order fails whenever the shopper wants more than half of what is left of that option. Five of the last eight fails. Two of the last two fails. The very last unit, one of one, fails. Stores that sell down to the last unit of a size or color lose exactly the orders that would have cleared the shelf.

We found this on a Magento 2.4.8 store with Hyvä Checkout 1.3.11 during a walkthrough on staging. The production logs then showed it had been happening to customers for weeks.

Need help with your Hyvä store?
If this problem is costing you orders or staff time, our senior Magento and Hyvä team can help you debug it and deploy a fix safely.
Contact us →

Why it happens

Three pieces of ordinary code combine into the wrong result.

  • Hyvä Checkout’s cart summary loads the cart through the cart item repository. Magento\Quote\Model\Quote\Item\Repository::getList() attaches product options to every quote item it returns. For a configurable product that is the chosen size, color and so on.
  • Any later quote save in the same request re-adds each line that carries product options. The quote repository’s save handler passes every item to CartItemPersister::save(). When the item has product options, the persister builds a buy request from them and calls Quote::updateItem(). Saving the guest’s details at Place Order is one such save.
  • The buy request has no item id. updateItem() marks the request with reset_count and calls addProduct(). The item processor only resets the line’s quantity to zero when the id on the request matches the item ($item->getId() == $request->getId()). The persister’s request carries no id, so the quantity is added on top of the line instead of replacing it.

For a moment the line holds twice its quantity, and that is when the stock check runs. The cart never shows the doubled number, because updateItem() puts the right quantity back afterwards. The shopper sees a correct cart and an error that makes no sense.

1. Reproduce it

Take a configurable product and set one of its options to a salable quantity of 2. Add 2 of that option to the cart and go through Hyvä Checkout as a guest. Place Order should fail with the message above. Repeat with a quantity of 1 of 1.

One warning from our own experience: orders created through the REST API do not take this path. Our earlier automated checks placed test orders that way and passed, while the real checkout was failing for customers. Test this in the browser, through the checkout your customers use.

2. Give the re-added line its own id

The fix is a before-plugin on Quote::updateItem(). It puts the line’s id on the buy request, which is what the cart’s own “update item” action sends. The item processor then replaces the quantity instead of adding to it.

<?php
declare(strict_types=1);

namespace Cadence\CartStockLimit\Plugin;

use Magento\Framework\DataObject;
use Magento\Quote\Model\Quote;

class ReplaceQtyWhenResavingItem
{
    public function beforeUpdateItem(Quote $subject, $itemId, $buyRequest, $params = null): array
    {
        if ($buyRequest instanceof DataObject && !$buyRequest->getData('id')) {
            $buyRequest->setData('id', $itemId);
        }

        return [$itemId, $buyRequest, $params];
    }
}

Declare it in the module’s global etc/di.xml, not in etc/frontend/di.xml. The REST cart item update goes through the same re-add, so the plugin should apply there as well.

<type name="Magento\Quote\Model\Quote">
    <plugin name="cadence_cartstocklimit_replace_qty_when_resaving_item"
            type="Cadence\CartStockLimit\Plugin\ReplaceQtyWhenResavingItem"/>
</type>

A request that already carries an id is left alone, so the cart page’s own quantity updates behave exactly as before.

Need help with your Hyvä store?
If this problem is costing you orders or staff time, our senior Magento and Hyvä team can help you debug it and deploy a fix safely.
Contact us →

3. Verify

Run the cases that failed before, through the real checkout:

  • 5 of the last 8 units of one option.
  • 2 of the last 2.
  • A cart holding three different options of the same product.

On our staging site each of these failed before the plugin and placed an order after it. Then check that a request for more than is available is still refused: add the last unit, lower the stock in the admin, and confirm the cart and checkout still say no.

A unit test for the plugin is short and worth having: one case where the request has no id and receives the item’s id, and one where an existing id is kept.

Notes before you ship this

  • Upgrading does not make this go away yet. As of December 2026 the cart summary in Hyvä Checkout 1.3.16 and 3.0.2 still loads its items through the cart item repository, and the persister and item processor code is the same in Magento 2.4.9.
  • The plugin changes no vendor file, so it does not need to be re-cut when Magento or Hyvä Checkout is upgraded. Keep the reproduction steps, and run them after an upgrade to learn whether the plugin is still needed.
  • If your logs or support inbox show “Not enough items for sale” for products that were in stock, count how often. On the store where we found this it had happened dozens of times in three weeks, mostly on the busiest sale day, without anyone connecting the reports.
  • Low stock makes this visible. A store with hundreds of units behind every option will rarely see it, and a store that sells limited batches will see it daily.
Install our webapp on your iPhone! Tap and then Add to homescreen.
Share This