Magento – Clone configurable product with related simple products

configurable-productmagento-1.9productproductsproducts-management

I am trying to clone (duplicate) configurable product with all associated simple products and option prices.

Does anyone have any idea how to do it or where to start?

Best Answer

You can write an observer for catalog_model_product_duplicate, check if the duplicated product is a configurable product, then duplicate all associated products as well. How to start with the observer:

public function duplicateConfigurableProduct(Varien_Event_Observer $observer)
{
    $originalProduct = $observer->getCurrentProduct();
    if ($originalProduct->getTypeId() === Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {

        // duplicate associated products:
        foreach ($originalProduct->getTypeInstance()->getUsedProducts() as $simpleProduct) {
            $simpleProduct->duplicate();
        }

    }
}

Copying the associations and option prices would be too much for the scope of this answer but this should already point you in the right direction. You have access to the duplicated configurable product with $observer->getNewProduct()

You should know that a duplicated product normally has to be edited manually immediately after duplication because its SKU is empty otherwise. If you duplicate the associated products automatically you still need to edit those as well.