Shops with many products with variants often face the problem that the removal of products can be quite cumbersome and time-consuming.

Before removing the main products all variants have to be deleted. Only then you'll be able to remove the main product as well. If you try to delete a product with variants directly, you'll get an error message ...

For some of our customers we therefore patched the Virtuemart source code in order to delete main products directly. With this patch if you select a product and click on "remove", the main product an all its variants will be removed immediately.

Here's the patch:

Open file <root>/administrator/components/com_virtuemart/models/product.php and look for the following code:

         $childIds = $this->getProductChildIds ($id);
            if (!empty($childIds)) {
                vmError (vmText::_ ('COM_VIRTUEMART_PRODUCT_CANT_DELETE_CHILD'));
                $ok = FALSE;
                continue;
            }

Replace it by the following code:

         $childIds = $this->getProductChildIds ($id);
            if (!empty($childIds)) {
                $this->remove ($childIds);          
            }

 

Instead of throwing an error, all variants of the product are removed recursively, afterwards the main product itself is deleted.

 

Important: This is a patch of the Virtemart core and can be used at your own risk (backup the original file). If you include the patch, remember that you may have to re-apply it each time you update your Virtuemart system.