Bagisto Forum

    Bagisto

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

    Inventory indices not auto updated

    General Discussion
    2
    2
    937
    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.
    • B
      beabay last edited by beabay

      Hello!
      I don't know why, but when I do migrate:fresh after editing some parts in OnepageController and try to add products, the inventory_indices are not automatically updated. I tried reindexing and restoring the code to its previous state, but it still doesn't work. Can you tell me how to fix this?

      7363efc0-1a38-41a0-8d93-5b634850f534-image.png
      i mean the 'product_inventories' table have 2 on it's qty

      4832eaad-facb-4408-9178-2f8ef7ef59af-image.png
      but 0 in product_inventory_indices

      Thank you in advance.

      A 1 Reply Last reply Reply Quote 0
      • A
        ashif.322 @beabay last edited by

        Hello @beabay

        Thanks for the details — the screenshots are very helpful. This is almost certainly NOT caused by your OnepageController edits. It's a side effect of running migrate:fresh, and here's why.

        What's happening

        product_inventory_indices is not filled directly from product_inventories. It's calculated by the inventory indexer, which sums a product's inventory ONLY for the inventory sources that are linked to your channel and are active. The relevant code is:

        // Webkul\Product\Helpers\Indexers\Inventory::getQuantity()
        $channelInventorySourceIds = $this->channel->inventory_sources->where('status', 1)->pluck('id');
        // qty is only added when the product's inventory_source_id is in that list
        

        migrate:fresh DROPS all tables and re-runs migrations only — it does NOT re-run the seeders. So the channel_inventory_sources link table (channel <-> inventory source) ends up empty. With no active source linked to the channel, the indexer correctly computes qty = 0 for every product, even though product_inventories still shows 2. That's also why re-indexing and reverting your code changed nothing — it's a data/seed problem, not a code problem.

        How to fix (short version)

        1. Re-seed the core data that migrate:fresh wiped:

          php artisan migrate:fresh --seed
          

          (or reinstall cleanly: php artisan bagisto:install)

        2. Confirm the link exists — the channel_inventory_sources table should have a row (channel_id = 1, inventory_source_id = 1), and in Admin -> Settings -> Inventory Sources the source must be Active (status = 1).

        3. Rebuild the indices:

          php artisan indexer:index --type=inventory
          

        After that, product_inventory_indices.qty will match your stock again.

        One extra note for the automatic update on save

        The index job runs on the catalog.product.update.after event and is dispatched as a QUEUED job. Make sure QUEUE_CONNECTION=sync in .env (for local/dev) OR that a queue worker is running (php artisan queue:work) — otherwise the index won't refresh when you edit products. Also note the index for a brand-new product is built on the first save/update, not on the initial create.

        Thanks
        Team Bagisto

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