Remove Orphaned Sub-Products and Fix Other Database Issues

Overview

You can use the following script to fix database issues related to Apparel products. These issues are often the result of using the Product Import Wizard (some fields might have been setup incorrectly). They could also be due to flaws in the software that have not yet been found. The script performs 3 tasks, but can be safely executed even if you aren't certain that your database needs to be “fixed”:

FIRST Task: Fix storefront errors due to option groups order not set
The script updates option groups order at the parent product level. Option groups must be ordered, otherwise there is a problem in the storefront.

SECOND Task: Remove incorrectly setup sub-products from the Control Panel (orphaned sub-products)
It loads all the products that are setup as Parent Products and then removes from the Control Panel sub-products whose parent is not in that list. Those records remain in the database, but with the removed field turn on (set to -1).

THIRD task: Hide sub-products from the storefront
If the active field is set to YES (-1), then some queries could mistake sub-products as stand-alone products in the storefront. Instead, sub-products should only be displayed within a Parent Product page. So the script sets the active field to 0 for sub-products.