Friday 19 December 2014

Magento : Delete all Products of Particular category id

Create one file and paste following code:


<?php
require_once ("app/Mage.php");
Mage::app('admin');
$category_id = your_cat_id;
$products = Mage::getModel('catalog/product')->getCollection();
foreach($products as $product){
 $categories = $product->getCategoryIds();
 if(in_array($category_id, $categories)) {
  $product_load = Mage::getSingleton('catalog/product')->load($product->getId());
  Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product_load));
  $product_load->delete();
 }
}
?>


And upload file on root of server and run as:

www.example.com/file_name.php

3 comments:

  1. This post is all about the Deleting product list from the category Id. This post is so much needy and very useful for the magento developer. Thanks for this kind of posts and keep updating.
    KetoArt

    ReplyDelete