批量删除Magento 1.4的产品+

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量删除Magento 1.4的产品+相关的知识,希望对你有一定的参考价值。

The easiest way to pull this off is by means of a quick script. The key to this script is that the indexing functionality is disabled entirely for the process, then enabled again at the end – requiring a manual update at the end.

In our case, we filtered the type of products by its “Data Set” – an attribute assigned to that batch of products, but you can change this to suit any means of filtering.
  1. <?php
  2.  
  3. echo "Started ".date("d/m/y h:i:s")."
  4. ";
  5. define('MAGENTO', "/domains/example.com/http");
  6.  
  7. require_once MAGENTO . '/app/Mage.php';
  8. umask(0);
  9. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  10.  
  11. $products = Mage::getModel('catalog/product')
  12. ->getCollection()
  13. ->addFieldToFilter('data_set', 1544);
  14.  
  15. $sql = ""; $undoSql = "";
  16. for ($i=0; $i<=8; $i++) {
  17. $sql .= "UPDATE index_process SET mode = 'manual' WHERE index_process.process_id =$i LIMIT 1;";
  18. $undoSql .= "UPDATE index_process SET mode = 'real_time' WHERE index_process.process_id =$i LIMIT 1;";
  19. }
  20.  
  21. $mysqli = Mage::getSingleton('core/resource')->getConnection('core_write');
  22. $mysqli->query($sql);
  23.  
  24. $total_products = count($products);
  25. $count = 0;
  26. foreach($products as $product){
  27. $product->delete();
  28.  
  29. if($count++%100 == 0) {
  30. $cur = strtotime(date("d/m/y h:i:s")) - $time;
  31. $time = strtotime(date("d/m/y h:i:s"));
  32. echo round((($count/$total_products)*100),2)."% deleted ($count/$total_products) ".round(100/$cur)." p/s ".date("h:i:s")."
  33. ";
  34. }
  35. }
  36.  
  37. echo "Ended ".date("d/m/y h:i:s")."
  38. ";
  39. $mysqli->query($undoSql);
  40. exit();
  41.  
  42. ?>

以上是关于批量删除Magento 1.4的产品+的主要内容,如果未能解决你的问题,请参考以下文章

Magento 将产品批量分配到类别

批量产品在Magento中编辑

如何实现Magento产品批量导入

Magento 删除愿望清单中的产品

通过Magento API批量更新产品和税类

架构丰富的代码片段也应该用于产品列表吗?