Skip to content

Run Dolibarr product hooks through the webservice (init hook context) - #24

Open
Pichinov-Jose wants to merge 1 commit into
SplashSync:2.0from
Pichinov-Jose:fix/webservice-init-product-hooks
Open

Pichinov-Jose wants to merge 1 commit into
SplashSync:2.0from
Pichinov-Jose:fix/webservice-init-product-hooks

Conversation

@Pichinov-Jose

@Pichinov-Jose Pichinov-Jose commented Sep 3, 2026

Copy link
Copy Markdown

Problem

Dolibarr modules can adjust the virtual stock through the loadvirtualstock hook, fired inside Product::load_virtual_stock(). But hooks only execute for classes registered with initHooks() — 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 and initHooks(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.

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
Pichinov-Jose marked this pull request as ready for review September 3, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant