我想清除所有测试类别以从干净的数据库开始。我使用以下代码删除了所有类别
Mage::app()->setCurrentStore(Mage::getModel('core/store')>load(Mage_Core_Model_App::ADMIN_STORE_ID));
// 1 is default store_id
$rootCategoryId = Mage::app()->getStore(1)->getRootCategoryId();
$resource = Mage::getSingleton('core/resource');
$db_read = $resource->getConnection('core_read');
$categories = $db_read->fetchCol("SELECT entity_id FROM " . $resource->getTableName("catalog_category_entity") . " WHERE entity_id>1 ORDER BY entity_id DESC");
foreach ($categories as $category_id) {
if ($category_id == $rootCategoryId)
continue;
try {
Mage::getModel("catalog/category")->load($category_id)->delete();
} catch (Exception $e) {
return $e->getMessage() . "\n";
}
}
它删除了除根类别之外的所有内容。完成后,我通过 API 添加了类别,效果非常好。现在问题来了:当我尝试在 Magento Admin 中编辑其中一个类别时,他只显示了创建新根类别的表单。
这可能是什么原因?我在 SO 上发现了另一个看起来相似的问题,但是那里提到的解决方案(禁用 mod_security)并没有为我完成这项工作。所以我想还有其他事情发生。我很可能没有很好地删除类别。
我很确定它不可能是 API,因为我之前已经添加了类别,之后我可以在管理员中编辑它们。
等不及你的帮助了。