Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Bagisto Marketplace: “The requested quantity is not available” on add-to-cart (seller flow) despite seller stock visible on channel

    Installing Bagisto
    1
    1
    34
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Radoje last edited by

      Symptom

      When adding a seller product to cart from PDP, we consistently get:
      The requested quantity is not available, please try again later.
      packages/Webkul/Marketplace/src/Cart.php:108
      The same happens if we call add-to-cart from a small diagnostic route (Product object + seller context).

      What we have verified

      1. Product / stock / channel mapping
      • product_flat (product_id=54) → price=60, status=1, visible_individually=1, weight=5.
      • Seller stock exists (vendor_id = 2) and channel sees source #5:
        -- seller-scoped stock in active channel (returns 7)
        SELECT SUM(pi.qty) AS salable_qty_seller
        FROM product_inventories pi
        JOIN channel_inventory_sources cis ON cis.inventory_source_id = pi.inventory_source_id
        WHERE pi.product_id = 54
        AND pi.vendor_id = 2
        AND cis.channel_id = 1;
      • Raw inventory row:
        SELECT * FROM product_inventories
        WHERE product_id=54 AND vendor_id=2;
        -- → (id=?, qty=7, product_id=54, vendor_id=2, inventory_source_id=5)
      • Channel “Balkan” inventory sources = 1, 2, 5 (vendor source #5 enabled).
      • Seller panel → Settings → Inventory Sources → source #5 Active.
      1. Marketplace tables
      • Marketplace product row exists & approved:
        SELECT * FROM marketplace_products WHERE product_id=54;
        /* → id=34, product_id=54, marketplace_seller_id=2, is_approved=1, is_owner=1 */
      1. Seller payload we submit
        We post a complete seller context (product object, not ID):
        {
        "product_id": 54,
        "quantity": 1,
        "seller_id": 2,
        "marketplace_seller_id": 2,
        "seller_product_id": 34,
        "inventory_source_id": 5,
        "vendor_id": 2
        }

      2. Route & middlewares
        We load a small proxy route under shop middlewares:
        // app/Providers/MpRouteServiceProvider.php
        Route::middleware(['web','channel','theme','locale','currency'])
        ->group(base_path('routes/mp.php'));

      // routes/mp.php (excerpt)
      Route::post('/mp-add-to-cart', function (Request $r, ProductRepository $products) {
      $p = $products->findOrFail((int) $r->input('product_id')); // Product OBJECT

      $data = $r->validate([
          'product_id'             => 'required|integer',
          'quantity'               => 'nullable|integer|min:1',
          'seller_id'              => 'nullable|integer',
          'seller_product_id'      => 'nullable|integer',
          'marketplace_seller_id'  => 'nullable|integer',
          'inventory_source_id'    => 'nullable|integer',
          'vendor_id'              => 'nullable|integer',
      ]);
      
      $payload = ['quantity' => (int)($data['quantity'] ?? 1)];
      foreach (['seller_id','seller_product_id','marketplace_seller_id','inventory_source_id','vendor_id'] as $k) {
          if (!empty($data[$k])) $payload[$k] = (int) $data[$k];
      }
      
      \Log::error('MP ADD payload', $payload); // we see it in logs
      
      // Marketplace Cart first:
      try {
          \Webkul\Checkout\Facades\Cart::addProduct($p, $payload);
      } catch (\Throwable $e) {
          // TEMP fallback so checkout doesn’t block (works):
          if (str_contains($e->getMessage(), 'requested quantity')) {
              app(\Webkul\Checkout\Cart::class)->addProduct($p, ['quantity' => $payload['quantity']]);
          } else {
              throw $e;
          }
      }
      return redirect('/checkout/cart');
      

      });

      1. PDP seller CTA
        On PDP we render seller info and post to /mp-add-to-cart with the payload fields above.

      The problem

      Even with the complete seller payload (and channel seeing source #5), Marketplace Cart still throws “requested quantity is not available …” from Marketplace/src/Cart.php:108.
      If we enable the core fallback in our route, item is added to cart and checkout works; but we’d like to keep the pure Marketplace flow.

      Question

      For this Bagisto Marketplace build, what exact parameter(s) or flag does Marketplace Cart need at addProduct($product, $data) to pick the seller stock in the active channel?

      We already include: seller_product_id, marketplace_seller_id, vendor_id, inventory_source_id, and the route runs with web, channel, theme, locale, currency.

      Seller stock (vendor_id=2 on source_id=5) is present and visible to the channel (salable_qty_seller = 7).

      Is there any additional switch or internal lookup (e.g., a specific field in seller profile) our minor version expects so that the Cart sums the seller stock instead of returning 0?

      Any pointer/snippet would be highly appreciated. Thanks a lot!

      Notes

      We’re currently using the core fallback so store can sell normally; looking to remove it once we align the Marketplace Cart expectations.

      Thanks!

      1 Reply Last reply Reply Quote 0
      • First post
        Last post