Magento:如何覆盖Review / Model / Resource / Collection.php

时间:2012-10-29 22:07:35

标签: magento

我尝试重写/app/code/core/Mage/Review/Model/Resource/Review/Collection.php和/app/code/core/Mage/Review/Model/Resource/Review.php

第1步:/app/etc/modules/Lbb_Review.xml

<?xml version="1.0"?>

<config>
     <modules>
        <Lbb_Review>
            <active>true</active>
            <codePool>local</codePool>
        </Lbb_Review>
     </modules>
</config>

第2步:/app/code/local/Lbb/Review/etc/config.xml

<?xml version="1.0"?>

    <config>  
        <modules>  
            <Lbb_Review>  
                <version>0.1.0</version>  
            </Lbb_Review>  
        </modules>  
        <global>  
            <models>  
                <review_resource>  
                    <rewrite>  
                            <review>Lbb_Review_Model_Resource_Review</review>  
                    </rewrite>  
                </review_resource>  

                <review_resource_review>  
                    <rewrite>  
                            <collection>Lbb_Review_Model_Resource_Review_Collection</collection> 
                    </rewrite>
                </review_resource_review>  
            </models>  
        </global>  
    </config>  

第3步:

/app/code/local/Lbb/Review/Model/Resource/Review.php

<?php

class Lbb_Review_Model_Resource_Review extends Mage_Review_Model_Resource_Review
{
    protected function _afterSave(Mage_Core_Model_Abstract $object)
    {
        echo 'test';
    }
}

/app/code/local/Lbb/Review/Model/Resource/Review/Collection.php

<?php

class Lbb_Review_Model_Resource_Review_Collection extends Mage_Review_Model_Resource_Review_Collection
{
    /**
     * init select
     *
     * @return Mage_Review_Model_Resource_Review_Product_Collection
     */
    protected function _initSelect()
    {
        parent::_initSelect();
        $this->getSelect()
            ->join(array('detail' => $this->_reviewDetailTable),
                'main_table.review_id = detail.review_id',
                array('detail_id', 'title', 'detail', 'nickname', 'size', 'customer_id'));
        return $this;
    }
}

我不知道问题是什么!

2 个答案:

答案 0 :(得分:5)

关闭。集合重写有点过时了:

第2步:/app/code/local/Lbb/Review/etc/config.xml

<?xml version="1.0"?>
<config>  
    <global>  
        <models>  
            <review_resource>  
                <rewrite>  
                    <review_collection>Lbb_Review_Model_Resource_Review_Collection</review_collection> 
                </rewrite_resource>
            </review>  
        </models>  
    </global>  
</config>

这适用于Magento CE1.6 + / EE1.11 +,BTW。

答案 1 :(得分:4)

    <?xml version="1.0"?> 
      <config>  
        <global>  
            <models>  
                <review_resource>
                    <rewrite>
                      <review>Namespace_ModuleName_Model_Resource_Review</review>
                    </rewrite>
                    <rewrite>  
                      <review_collection>
                          Namespace_ModuleName_Model_Resource_Review_Collection
                      </review_collection>
                    </rewrite>
                </review_resource>
            </models>  
        </global>   
      </config>
P.S:benmarks答案有错误,所以加上这个,信用就归他了:)