2015-07-13 125 views
0

在我的Magento網站中,我想刪除(刪除)中止(不再)產品。 但我不知道如何找到哪個產品停產產品以及如何刪除(刪除)它們。刪除Magento中的停產產品

請有人有腳本。

+0

wt您的意思是discountinue product qty = 0或status = disable? –

回答

1

在magento的根文件夾中創建一個delete_products.php文件。

<?php 
ini_set('error_reporting', E_ALL); 
ini_set('display_errors', TRUE); 
ini_set('log_errors', TRUE); 

//Include the Mage package 
require_once './app/Mage.php'; 

//Set Developer mode to true, allows for more verbose errors 
Mage::setIsDeveloperMode(true); 

//Initialize the app. 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(array('sku','status'))->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_DISABLED); 

foreach ($products as $product) { 
    try { 
     echo "<pre>Deleting ".$product->getSku().", status: ".$product->getStatus()."</pre>"; 
     $product->delete(); 
     echo '<pre>OK</pre>'; 

    } catch(Exception $e) { 
     echo "<pre>ERROR: ".$e->getMessage()."</pre>"; 
    } 
} 

運行[Magento站點URL] /delete_products.php

這是不一樣快,直接在SQL中刪除,但它的工作原理。

Reindex腳本完成後。