删除所有类别产品
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了删除所有类别产品相关的知识,希望对你有一定的参考价值。
Change the category id and store id at the top of the script before running it. You can also remove the echo statements if you don’t want any output.
<?php $storeid = 1; $catid = 16; deleteAllCategoryProducts($storeid,$catid); function deleteAllCategoryProducts($storeid,$catid) { require_once 'app/Mage.php'; Mage::app( "default" )->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $_category = Mage::getModel('catalog/category')->setStoreId( $storeid ); $_category = $_category->load($catid); $subcats = $_category->getAllChildren(true); // true to get as array foreach ($subcats as $subcatid) { echo 'Deleting from Category ID: ' . $subcatid . " "; echo 'Deleting Product IDs: '; $pids = Mage::getResourceModel('catalog/product_collection')->setStoreId($storeid)->addCategoryFilter(Mage::getModel('catalog/category')->load($subcatid))->getAllIds(); { foreach ( $pids as $pid ) { echo $pid . ' '; $product = Mage::getSingleton('catalog/product')->load($pid)->delete(); } } echo " "; } } ?>
以上是关于删除所有类别产品的主要内容,如果未能解决你的问题,请参考以下文章
如何从数据库中删除属于特定类别的 woocommerce 产品