fix: enforce stock limits on basket quantities

No stock validation existed in the ordering flow, allowing customers
to order more items than available.

Cap quantity to ``stock_current`` in ``Baskets::getBasketData()`` when
adding to cart. Add ``min=1`` and ``max=stock`` attributes on the
basket quantity input, with JS clamping in the change handler.
Verify stock again in ``Shop\OrderController::store()`` before saving
the order as a race-condition safeguard.
This commit is contained in:
Valentin Lab
2026-02-20 12:17:22 +01:00
parent ef52addc7d
commit 63673117b3
6 changed files with 65 additions and 3 deletions

View File

@@ -116,6 +116,7 @@ class Baskets
'variation' => $offer->variation->name,
'image' => Articles::getPreviewSrc(ArticleImages::getFullImageByArticle($offer->article)),
'latin' => $offer->article->product->specie->latin ?? false,
'stock' => $offer->stock_current !== null ? (int) $offer->stock_current : null,
];
}
@@ -144,6 +145,13 @@ class Baskets
{
$offer = Offers::get($id, ['article', 'variation']);
if ($offer && $offer->stock_current !== null) {
$quantity = min($quantity, max(0, (int) $offer->stock_current));
if ($quantity <= 0) {
return false;
}
}
return [
'id' => $id,
'name' => self::getArticleName($offer),