Since the availability of the parts list is based on the availability of the sub-items, the variable d.instock cannot be used in Shopware's shipping costs module (e.g. to calculate shipping costs). To use the correct availability of the product set item based on the sub-items, the following query can be used:
IF(
AT.viison_setarticle_active,
(
SELECT
MIN(sad.instock div savs.quantity) AS instock
FROM
s_articles_details AS sad
LEFT JOIN s_articles_viison_setarticles AS savs ON sad.id = savs.articledetailid
WHERE
savs.setid = d.id
),
IF(
v.instock IS NOT NULL, v.instock, d.instock
)
) AS instock