Run Dolibarr product hooks through the webservice (init hook context) - #24
Open
Pichinov-Jose wants to merge 1 commit into
Open
Pichinov-Jose wants to merge 1 commit into
Pichinov-Jose wants to merge 1 commit into
Conversation
Dolibarr modules can adjust the virtual stock through the 'loadvirtualstock' hook, fired inside Product::load_virtual_stock(). Hooks only run for classes registered with initHooks(), which every Dolibarr page calls but the Splash webservice never does: the global HookManager carries no context, the modules stay silent, and the stock pushed to the e-commerce side differs from what Dolibarr displays on the product card (observed in production: total stock of all warehouses synced instead of the sellable virtual stock). Initialize the 'productdao' context at the end of Local::includes() so core product computations behave the same through the webservice as they do in the back office. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pichinov-Jose
marked this pull request as ready for review
September 3, 2026 11:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Dolibarr modules can adjust the virtual stock through the
loadvirtualstockhook, fired insideProduct::load_virtual_stock(). But hooks only execute for classes registered withinitHooks()— which every Dolibarr page calls, and the Splash webservice never does. The global HookManager carries no context on that path, so any module hooking the product stays silent during a sync.Observed in production (Dolibarr 24.0, module 2.0.10): a module restricts the virtual stock to sellable warehouses; the product card shows the right value, but Splash reads and pushes the total stock of all warehouses to WooCommerce — e.g. 1869 synced where Dolibarr displays 375, or 816 synced for a product whose sellable stock is 0. Any installation using a virtual-stock module (quarantine, assembly warehouses, repairs…) silently oversells.
Fix
At the end of
Local::includes(), create the global HookManager if absent andinitHooks(array('productdao')), so core product computations behave the same through the webservice as they do in the back office. No behaviour change for installations without product hooks.Verified end-to-end on the production installation above: after the change, the webservice path returns exactly the values shown on the product cards.