Bulk Deleting Products via Import/Export in Magento
Magento provides robust import/export functionality for managing your product catalog efficiently. While the primary use is to bulk update or add products, it can also be used strategically for removing specific items from your store. Let’s explore how you can leverage this feature to delete multiple products at once.
Understanding the Limitations
Before we proceed with the steps, let’s clarify a few points:
-
Deleting via “status” column: As you mentioned, setting the “status” to “disabled” won’t work if your CSV already contains disabled products. Magento will only update the status of the existing enabled products.
-
Magento version compatibility: Your version (1.4.2.0) is quite old and lacks some features available in later versions, such as the direct ‘delete’ option. However, we can still achieve this through a workaround.
The Workaround: Using “update_time” for Deletion
The key to deleting products via import/export lies in utilizing the update_time column. When you update any field (even if it remains the same), Magento will consider it as an updated record and save changes.
Here’s how we can apply this:
-
Create a new CSV file: Start by creating a new CSV file with only the necessary columnsâat least include
sku,entity_id(product ID), andupdate_time. -
Find product IDs: You need to identify the entity_ids of the products you want to delete. You can do this manually or use the following SQL query:
SELECT entity_id, sku FROM catalog_product_entity WHERE status = 1;
-
Prepare your CSV rows: For every product you want to delete, create a row in your new CSV. The
entity_idshould match the actual ID of the product. -
Leave other fields empty or unchanged: All other data (like name, description, price) should remain empty or keep their current values as per your existing CSV records.
-
Update the “update_time” field: This is crucial. The
update_timevalue should be in the format Y-m-d H:i:s. You can use a simple PHP script to generate these timestamps:
$products = [['entity_id' => 1, 'sku' => 'SKU001'], ['entity_id' => 2, 'sku' => 'SKU002']];
foreach ($products as $product) {
$newTime = date('Y-m-d H:i:s');
echo "{$product['entity_id']},,,,$newTime\n";
}
- Import the CSV: Finally, use Magento’s Import functionality to upload this CSV file. Ensure you select the correct profile and mapping.
Conclusion
While it requires a bit of manual effort, using the update_time column allows you to delete multiple products via import/export in older versions of Magento. Remember, this method works by essentially flagging the products for deletion rather than directly removing them from your database.
If you’re looking for more advanced catalog management solutions or need expert assistance with Magento development, feel free to explore our services at LaravelCompany. We specialize in helping businesses optimize their e-commerce platforms using the latest techniques and best practices.