Inventory indices not auto updated
-
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?
i mean the 'product_inventories' table have 2 on it's qty
but 0 in product_inventory_indicesThank you in advance.
-
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 listmigrate: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)
-
Re-seed the core data that migrate:fresh wiped:
php artisan migrate:fresh --seed(or reinstall cleanly: php artisan bagisto:install)
-
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).
-
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 -