I am adding products by code in particular one attributeset named "Diamond".

I had programmed a cron job to add the csv data as products in "Diamond" attribute set. The new csv uploaded on daily bases.

So, I want to remove the previously added products from "Diamond" atribute set.

Any idea to delete those products which attribute set is "Diamond" by code?


Take a look at Magento get all products by attribute set

//Fetch attribute set id by attribute set name
$attrSetName = 'Diamond';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
    ->load($attrSetName, 'attribute_set_name')

//Load product model collection filtered by attribute set id
$products = Mage::getModel('catalog/product')
    ->addFieldToFilter('attribute_set_id', $attributeSetId);

//process your product collection as per your business logic
$productsName = array();
foreach($products as $p){
    $productsName[] = $p->getData('name');
    //uncomment $p->delete(); after verifying these are the correct products  

  • Did this code work for you? – Renon Stewart Oct 14 '14 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.