Skip to content

Instantly share code, notes, and snippets.

@Crease29
Last active January 14, 2021 18:07
Show Gist options
  • Save Crease29/93216af9f0c34fe56c2595f37350bb85 to your computer and use it in GitHub Desktop.
Save Crease29/93216af9f0c34fe56c2595f37350bb85 to your computer and use it in GitHub Desktop.
Shopware 6: Set smallest active product.main_variant_id (ordered by variant product_number)
UPDATE product AS mainProduct
SET main_variant_id = (
SELECT p.id
FROM product AS p
INNER JOIN product_option AS po
ON p.id = po.product_id
INNER JOIN property_group_option AS pgo
ON po.property_group_option_id = pgo.id
WHERE p.parent_id = mainProduct.id
AND (p.active IS NULL OR p.active = 1)
GROUP BY p.product_number
ORDER BY p.product_number
LIMIT 1
)
WHERE mainProduct.parentId IS NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment