删除类别属性的存储级别值
-
13-12-2019 - |
题
在我们的商店中,我们有一个针对每个商店设置的客户类别属性。现在我们要删除存储级别值,并将其替换为一个全局级别。现在我知道如何通过管理员来做到这一点,但是有没有一种方法可以通过设置脚本对此进行排序。
解决方案
我想你可以从管理员类别控制器复制行为, saveAction
.
if ($useDefaults = $this->getRequest()->getPost('use_default')) {
foreach ($useDefaults as $attributeCode) {
$category->setData($attributeCode, false);
}
}
但这需要一个 load
在一个循环中。实际上是2个循环。
像这样的东西(未经测试的代码)
$attributeCode = 'attribute_code_here';
$collection = Mage::getModel('catalog/category')->getCollection()->addLevelFilter(2); //exclude the root of all roots and the root catalog.
$stores = Mage::getModel('core/store')->getCollection()->setWithoutDefaultFilter();
foreach ($collection as $category) {
foreach ($stores as $store) {
$_category = Mage::getModel('catalog/category')->setStoreId($store->getId())->load($category->getId());
$_category->setData($attributeCode, false);
$_category->save();
}
}
我知道这不是最好的解决方案,但因为这只会运行一次,它不应该那么麻烦。
我仍然说你应该使用查询。快得多。