安全地覆盖Magento核心资源方法

时间:2011-11-02 12:23:38

标签: php zend-framework magento

我必须更改Magento的Mage_Catalog_Model_Resource_Eav_Mysql4_Category类的方法。我改变了:

public function getChildrenCategories($category)
{
        $collection = $category->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        $collection->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('all_children')
            ->addAttributeToSelect('is_anchor')
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren())
            ->setOrder('position', 'ASC')
            ->joinUrlRewrite()
            ->load();
        return $collection;
}

要:

public function getChildrenCategories($category)
{
            $collection = $category->getCollection();
            /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
            $collection->addAttributeToSelect('url_key')
                ->addAttributeToSelect('name')
                ->addAttributeToSelect('all_children')
                ->addAttributeToSelect('thumbnail')
                ->addAttributeToSelect('is_anchor')
                ->addAttributeToFilter('is_active', 1)
                ->addIdFilter($category->getChildren())
                ->setOrder('position', 'ASC')
                ->joinUrlRewrite()
                ->load();
            return $collection;
}

基本上添加->addAttributeToSelect('thumbnail'),因为我需要获取该属性。

我现在陷入了如何安全地覆盖这个功能的问题。我已将整个班级复制到local > Mage > Catalog > Model > Resouce > Eav > Mysql4 > Category.php,但实际上我只需要覆盖那一个函数。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

您必须覆盖模块中的整个资源集合。您可以阅读如何在此forum thread中覆盖资源集合。