When having a commerce setup with 2 sites and 2 stores and the product propagation is set to save product to other sites in the same site group (the 2 sites are in different groups) and you try to set the inventory level of a product that is propagated to the non-primary site, you get a TypeError TypeError: craft\commerce\models\InventoryLevel::getPurchasable(): Return value must be of type craft\commerce\base\Purchasable, null returned in /var/www/html/vendor/craftcms/commerce/src/models/InventoryLevel.php:135
Digging deeper into the query that is getting executed when trying to get the purchasable, there is no specific site passed to the query (https://github.com/craftcms/commerce/blob/5.x/src/models/InventoryItem.php#L66), but the query that is getting executed does have a siteId = {primarySiteId} parameter, which lead to no purchasable is being found.
Steps to reproduce
commerce setup with 2 sites/stores with propagation method per site
try to change inventory level of non primary site
TypeError and unable to set stock levels
Expected behavior
The correct purchasable for the site is returned and you are able to change the inventory levels
What happened?
Description
When having a commerce setup with 2 sites and 2 stores and the product propagation is set to
save product to other sites in the same site group
(the 2 sites are in different groups) and you try to set the inventory level of a product that is propagated to the non-primary site, you get a TypeErrorTypeError: craft\commerce\models\InventoryLevel::getPurchasable(): Return value must be of type craft\commerce\base\Purchasable, null returned in /var/www/html/vendor/craftcms/commerce/src/models/InventoryLevel.php:135
Digging deeper into the query that is getting executed when trying to get the purchasable, there is no specific site passed to the query (https://github.com/craftcms/commerce/blob/5.x/src/models/InventoryItem.php#L66), but the query that is getting executed does have a
siteId = {primarySiteId}
parameter, which lead to no purchasable is being found.Steps to reproduce
Expected behavior
The correct purchasable for the site is returned and you are able to change the inventory levels
Craft CMS version
5.5.3
Craft Commerce version
5.2.6
PHP version
8.3.12
Operating system and version
Ubuntu 24.04
Database type and version
mysql 8.0.37
Image driver and version
No response
Installed plugins and versions
No response