/ Published in: PHP

Change the category id and store id at the top of the script before running it. You can also remove the echo statements if you don’t want any output.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $storeid = 1; $catid = 16; deleteAllCategoryProducts($storeid,$catid); function deleteAllCategoryProducts($storeid,$catid) { require_once 'app/Mage.php'; Mage::app( "default" )->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $_category = Mage::getModel('catalog/category')->setStoreId( $storeid ); $_category = $_category->load($catid); $subcats = $_category->getAllChildren(true); // true to get as array foreach ($subcats as $subcatid) { echo 'Deleting from Category ID: ' . $subcatid . "\n"; echo 'Deleting Product IDs: '; $pids = Mage::getResourceModel('catalog/product_collection')->setStoreId($storeid)->addCategoryFilter(Mage::getModel('catalog/category')->load($subcatid))->getAllIds(); { foreach ( $pids as $pid ) { echo $pid . ' '; $product = Mage::getSingleton('catalog/product')->load($pid)->delete(); } } echo "\n"; } } ?>
Comments
