Currently we are having an issue where the product doesn't show the correct stock status (In Stock/Out of Stock) when the stock quantity changes on the first page load.
Firstly, we do use a few plugins and custom code to change the default behaviour:
- All stock is managed
qtyis updated on after an observer fires for
controller_action_predispatch_catalog_product_viewwhich performs an API call on our inventory management system
- The stock status message is controlled based on the product and stock item data/attributes, overriding Magento's default behaviour
As far as I have been able to diagnose, what happens is the observer fires and does the API calls and updates the table before the page is loaded, as intended. So any data that is based on the product attributes is reflected on the initial page load - I confirmed this by having the code store the quantity as an attribute of the product and this was reflected on the first page load.
However, the stock item data is somehow "cached" and doesn't reflect changes until the page is reloaded. Except, if I force the product model to be loaded again inside a child block and pull the stock item data again from this, which then does reflect the changes - but only within the block that has been modified to load the data independently of the main page.
I am at a loss for why there is inconsistent timings between the product table updates and stock item table updates, despite both being updated simultaneously.