Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: how to overwrite Review/Model/Resource/Collection.php

Tags:

magento

i try to rewrite /app/code/core/Mage/Review/Model/Resource/Review/Collection.php and /app/code/core/Mage/Review/Model/Resource/Review.php

step 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>

step 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>  

step3:

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

i do not know what the problem is !

like image 285
Fresh Lover Avatar asked Jan 15 '23 04:01

Fresh Lover


1 Answers

Close. The collection rewrite is a bit off:

step 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>

This will work for Magento CE1.6+ / EE1.11+, BTW.

like image 173
benmarks Avatar answered Jan 31 '23 06:01

benmarks