Remove associated products in magento
In magento it is very difficult to remove numbers of simple products which are associated with one configurable manually. So here i show programmatically how to remove and save your valuable time. If you are familiar with magento programming then it good to go else don’t do it.
<?php require_once 'app/Mage.php'; Mage::app(); Mage::setIsDeveloperMode(true); umask(0); $file_handle = fopen("associated-products.csv", "r"); while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle, 1024); $simpleSku = $line_of_text[0]; $configurableSku = $line_of_text[1]; echo $simpleSku." = ".$configurableSku."<br/>"; $simpleProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$simpleSku); $configurableProduct = Mage::getModel('catalog/product')->loadByAttribute('sku',$configurableSku); $simpleId = $simpleProduct->getId(); $configurableProductId = $configurableProduct->getId(); echo $simpleId." = ".$configurableProductId."<br/>"; $ids = $configurableProduct->getTypeInstance()->getUsedProductIds(); $resource = Mage::getSingleton('core/resource'); $read = Mage::getSingleton('core/resource')->getConnection('core_read'); $write = $resource->getConnection('core_write'); $write->query("delete from catalog_product_super_link where parent_id=".$configurableProductId." AND product_id='".$simpleId."'"); } fclose($file_handle); ?>
Steps:
1. Create an excel file and save as “associated-products.csv” or any you wish.
2. IMP: Not necessary to provide column name in sheet as shown, you can place direct skus & configurable sku. Pl note first column is simple skus & on second column it is configurable sku from which you want to remove.
3. Upload csv file to root path of magento on server.
4. Create a file “config-associated.php” and add code as shown above and upload to root of magento.
5. Run the url www.yourdomain.com/config-associated.php.
Make sure all the listed simple skus will be removed from the config product. here as e.g.: 1234 is config product and on first column all are simple products will be removed.