4

我尝试重写 /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>  

第三步:

/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;
    }
}

我不知道是什么问题!

4

2 回答 2

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+,顺便说一句。

于 2012-10-30T02:35:26.877 回答
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>

PS: Benmarks 的答案有错别字,所以添加这个,归功于他 :)

于 2014-09-30T14:21:53.240 回答