Created
May 18, 2016 07:41
-
-
Save timgaunt/21f3da4b954776ec5e78a8f66975bb33 to your computer and use it in GitHub Desktop.
Delete the variants (child products) from uCommerce where they don't have a price but the parent is active
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN TRAN | |
SELECT TOP 100 | |
* | |
FROM | |
uCommerce_Product p | |
LEFT JOIN uCommerce_PriceGroupPrice pgp ON p.ProductId = pgp.ProductId | |
LEFT JOIN uCommerce_Product pp ON p.ParentProductId = pp.ProductId | |
WHERE | |
p.ParentProductId IS NOT NULL | |
AND pp.AllowOrdering = 1 | |
AND pp.DisplayOnSite = 1 | |
AND pgp.Price <= 0 | |
SELECT | |
p.ProductId | |
INTO #VariantsToDelete | |
FROM | |
uCommerce_Product p | |
LEFT JOIN uCommerce_PriceGroupPrice pgp ON p.ProductId = pgp.ProductId | |
LEFT JOIN uCommerce_Product pp ON p.ParentProductId = pp.ProductId | |
WHERE | |
p.ParentProductId IS NOT NULL | |
AND pp.AllowOrdering = 1 | |
AND pp.DisplayOnSite = 1 | |
AND pgp.Price <= 0 | |
DELETE FROM uCommerce_ProductProperty WHERE ProductId IN (SELECT ProductId FROM #VariantsToDelete vtd) | |
DELETE FROM uCommerce_PriceGroupPrice WHERE ProductId IN (SELECT ProductId FROM #VariantsToDelete vtd) | |
DELETE FROM uCommerce_Product WHERE ProductId IN (SELECT ProductId FROM #VariantsToDelete vtd) | |
DROP TABLE #VariantsToDelete | |
SELECT TOP 100 | |
* | |
FROM | |
uCommerce_Product p | |
LEFT JOIN uCommerce_PriceGroupPrice pgp ON p.ProductId = pgp.ProductId | |
LEFT JOIN uCommerce_Product pp ON p.ParentProductId = pp.ProductId | |
WHERE | |
p.ParentProductId IS NOT NULL | |
AND pp.AllowOrdering = 1 | |
AND pp.DisplayOnSite = 1 | |
AND ISNULL(pgp.Price, 0) <= 0 | |
ROLLBACK TRAN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment