{"record":{"id":"b8d0056200c80063","repo":"bagisto/bagisto","slug":"product-app-checkout-cart-inventory-warning","errorCode":null,"errorMessage":"product::app.checkout.cart.inventory-warning","messagePattern":"product::app\\.checkout\\.cart\\.inventory-warning","errorType":"exception","errorClass":"InsufficientProductInventoryException","httpStatus":null,"severity":"error","filePath":"packages/Webkul/Product/src/Type/AbstractType.php","lineNumber":817,"sourceCode":"        return core()->getTaxCategoryById($taxCategoryId);\n    }\n\n    /**\n     * Add product. Returns error message if can't prepare product.\n     *\n     * @param  array  $data\n     * @return array\n     *\n     * @throws InsufficientProductInventoryException\n     */\n    public function prepareForCart($data)\n    {\n        $data['quantity'] = $this->handleQuantity((int) $data['quantity']);\n\n        $data = $this->getQtyRequest($data);\n\n        if (! $this->haveSufficientQuantity($data['quantity'])) {\n            throw new InsufficientProductInventoryException(trans('product::app.checkout.cart.inventory-warning'));\n        }\n\n        $price = $this->getFinalPrice();\n\n        $products = [\n            [\n                'product_id' => $this->product->id,\n                'sku' => $this->product->sku,\n                'quantity' => $data['quantity'],\n                'name' => $this->product->name,\n                'price' => $convertedPrice = core()->convertPrice($price),\n                'price_incl_tax' => $convertedPrice,\n                'base_price' => $price,\n                'base_price_incl_tax' => $price,\n                'total' => $convertedPrice * $data['quantity'],\n                'total_incl_tax' => $convertedPrice * $data['quantity'],\n                'base_total' => $price * $data['quantity'],\n                'base_total_incl_tax' => $price * $data['quantity'],","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/bagisto/bagisto/blob/326bc45f17cd66d2835a934d21c264d3ee12d935/packages/Webkul/Product/src/Type/AbstractType.php#L799-L835","documentation":"Webkul\\Product\\Exceptions\\InsufficientProductInventoryException thrown by the base product type's prepareForCart() (AbstractType). Before building the cart line it normalizes the requested qty (handleQuantity, getQtyRequest) and calls haveSufficientQuantity(qty); when saleable stock (inventory sources on hand minus allocated/reserved quantity) cannot cover the request it throws this translated message. Every product type inherits this gate, so both storefront add-to-cart and API/HEADLESS cart operations funnel through it.","triggerScenarios":"POST add-to-cart (shop CartController::store or REST cart add) with a quantity greater than the product's current saleable qty; or checkout/order re-validation when stock dropped between adding to cart and placing the order.","commonSituations":"Stock consumed by concurrent orders after the product page was loaded; product has inventory sources assigned but zero on hand (or no source assigned so total qty is 0); pending orders reserving/allocating qty; customer typing a qty larger than allowed without the storefront pre-checking.","solutions":["Retry with a quantity within available stock, or raise the product's inventory in Admin > Inventory (per-source qty) and ensure at least one source is assigned","Enable backorders (globally or per product) so haveSufficientQuantity() passes when intentional","If the product is intentionally always available, disable stock management for it","In custom add-to-cart code, catch InsufficientProductInventoryException and surface getMessage() as the cart error"],"exampleFix":"// before\n$result = $product->getTypeInstance()->prepareForCart($data);\n\n// after - validate stock first, then still guard with the exception\n$type = $product->getTypeInstance();\n\nif (! $type->haveSufficientQuantity((int) $data['quantity'])) {\n    return back()->withErrors(trans('product::app.checkout.cart.inventory-warning'));\n}\n\ntry {\n    $result = $type->prepareForCart($data);\n} catch (\\Webkul\\Product\\Exceptions\\InsufficientProductInventoryException $e) {\n    return back()->withErrors($e->getMessage());\n}","handlingStrategy":"validation","validationCode":"// Before Cart::addProduct / prepareForCart\n$type = $product->getTypeInstance();\n\nif (! $type->haveSufficientQuantity((int) $data['quantity'])) {\n    return back()->withErrors(trans('product::app.checkout.cart.inventory-warning'));\n}","typeGuard":null,"tryCatchPattern":"try {\n    $result = $product->getTypeInstance()->prepareForCart($data);\n} catch (\\Webkul\\Product\\Exceptions\\InsufficientProductInventoryException $e) {\n    // $e->getMessage() is already locale-translated\n    session()->flash('error', $e->getMessage());\n\n    return redirect()->back();\n}","preventionTips":["Call haveSufficientQuantity() with the exact qty right before add-to-cart","Show remaining stock on the product page and clamp the qty input to it","Account for reserved/allocated qty, not just on-hand, when forecasting availability","Catch InsufficientProductInventoryException separately from generic exceptions in cart flows"],"tags":["bagisto","php","inventory","cart","product","stock"],"backgroundTag":"insufficient-inventory","analyzedSha":"326bc45f17cd66d2835a934d21c264d3ee12d935","analyzedAt":"2026-08-17T00:51:54.202Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}