1

I have an attribute which is called manufacturer (attribute code: manufacturer) and I want to delete all sku's that are from a specific manufacturer.

However I am not sure how to write the SQL (I want to do this via Mysql) I know the basic query to delete a product would be like

  SELECT * FROM magento.catalog_product_entity where sku='abc';

any suggestions? thank you!

3
  • Thank you Sander Mangel do I just need to put include('app/Mage.php'); on the top of the file I would have your code in?
    – Jayreis
    Nov 3, 2015 at 21:44
  • I get a 500 server error when I try to load your code
    – Jayreis
    Nov 3, 2015 at 22:15
  • When you add comments here I don't get notified. A 500 error means the error is not shown. Please check your Apache logs what the error is
    – Sander Mangel
    Nov 10, 2015 at 14:17

2 Answers 2

3

Since Magento works with an EAV structure deleting data from the catalog_product_entity table is not enough. You'll also need to delete the data from other tables.

Using Magento objects might be easier and ensures a cleaner database.

A script like the following would do the trick

$collection = Mage::getModel('catalog/product')->getCollection()
 ->addAttributeToFilter('manufacturer', [id]);

foreach ($collection as $product) {
   $product->delete();
}
0

You can use this query for delete one or multple products from mysql in magento.

DELETE FROM `catalog_product_entity` WHERE `sku` IN ('SKU1', 'SKU2', ...., 'SKU1000');
1

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.