在Magento中的平面类别集合上调用getChildrenCategories时出现致命错误


Fatal Error when calling getChildrenCategories on a Flat Category Collection in Magento

基本上,我正在尝试在主页上的(核心/模板)块中显示Magento商店中顶级类别的URL,缩略图和名称的列表。我们正在使用Magento Enterprise 1.12.0.2,尽管我认为引用的代码也适用于社区版。

要加载类别,我正在使用以下内容:

/**
 * Parent Category of store
 * @var Mage_Catalog_Model_Category
 */
$_parent_category = Mage::getModel('catalog/category')->load(2);
/**
 * Resource Model that will allow us to load the Categories.
 * @var Mage_Catalog_Model_Resource_Category
 */
$_resource = Mage::getResourceModel('catalog/category');
/**
 * Collection of Child Categories
 * @var Mage_Catalog_Model_Resource_Category_Collection
 */
 $_categories = $_resource->getChildrenCategories($_parent_category);

一切正常,直到我切换到平板表(将系统 -> 配置 -> 目录 -> 前端 -> 美国平面目录类别)更改为"是"

一旦我这样做,我就会收到以下错误:

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Category_Flat_Collection::joinUrlRewrite() in /app/code/core/Mage/Catalog/Model/Resource/Category.php

我重新索引,刷新了所有缓存等。

这是核心代码库中的错误还是仅仅是我的执行错误?

提前感谢您的任何指导。

发生这种情况是因为类别模型 ( catalog/category ) 对不同的Use Flat Catalog Category设置使用不同的资源模型,并且您始终使用 Mage::getResourceModel('catalog/category'); 。 如果启用了平面类别,则应Mage::getResourceModel('catalog/category_flat');资源模型。
为了不被打扰,我建议使用

$_parent_category = Mage::getModel('catalog/category')->load(2);
$_categories = $_parent_category->getChildrenCategories();

并让Magento决定使用哪种资源模型。

相关文章:
  • 没有找到相关文章