Remove magento products within product id range script

<?php require_once ‘../app/Mage.php’; Mage::app()->setCurrentStore(Mage::getModel(‘core/store’)->load(Mage_Core_Model_App::ADMIN_STORE_ID)); $fromStart = 577; $toEnd = 771 ; removeAllProducts($fromStart,$toEnd); echo ‘DONE’.PHP_EOL; exit(); function removeAllProducts( $fromStart ,$toEnd ){ $products = Mage::getModel(‘catalog/product’)->getCollection() ->addAttributeToSelect(‘*’) ->addAttributeToFilter(‘entity_id’, array( ‘from’ => $fromStart, ‘to’ => $toEnd )) ->load(); foreach ($products as $product) { try { Mage::getModel(‘catalog/product’)->load($product->getId())->delete(); echo ‘Product Removed ‘.$product->getId() .PHP_EOL; } catch (Exception $e) { echo ‘Failed to… Read more »

<?php
require_once '../app/Mage.php';
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));

$fromStart = 577;
$toEnd = 771 ;

removeAllProducts($fromStart,$toEnd);

echo 'DONE'.PHP_EOL;
exit();

function removeAllProducts( $fromStart ,$toEnd ){

    $products = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('entity_id', array(
            'from' => $fromStart,
            'to' => $toEnd
        ))
        ->load();

        foreach ($products as $product)
        {

            try
            {
                Mage::getModel('catalog/product')->load($product->getId())->delete();
                echo 'Product Removed '.$product->getId() .PHP_EOL;

            }
            catch (Exception $e)
            {
                echo 'Failed to Remove product '.$product->getId() .PHP_EOL;
            }
        }
}

Share this Tutorial