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

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

September 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: how to overwrite Review/Model/Resource/Collection.php

Magento: Overwriting Review/Model/Resource/Collection.php

Overriding core Magento files is a common practice for extending or modifying functionality without touching the original code directly. This allows you to maintain upgrades more easily. In this post, we’ll guide you through how to correctly overwrite Review/Model/Resource/Collection.php and Review/Model/Resource/Review.php.

Understanding the Rewrite Process

The process involves creating a local copy of the core file in your custom theme or module and then rewriting the references to point to your new implementation. This way, when Magento loads the resource model or collection, it will use your modified version instead of the original one.

Step-by-Step Rewrite Guide

1. Enable Your Custom Module

First, you need to enable your custom module in 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. Configure Your Module’s Configuration

Next, in app/code/local/Lbb/Review/etc/config.xml, you need to define the rewrite:

<?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. Create and Modify the Resource Model

Now, create your custom resource model files:

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

Troubleshooting Common Issues

If you’re still facing issues, double-check the following:

  • Ensure your module is enabled and configured correctly.
  • The rewrite paths in config.xml must match exactly with your local file names.
  • Magento caches configuration files. Clear your cache (System > Cache Management) after making changes.
  • If using a development environment, make sure you’re running in developer mode (php -d app_ENV=developer index.php).

Best Practices for Overrides

Remember to follow these best practices:

  1. Avoid direct modifications: Override the core files instead of modifying them directly.

  2. Keep it simple: Only override what’s necessary for your customization.

  3. Use version control: Track changes in a Git repository to easily revert or merge.

  4. Test thoroughly: Ensure your overrides don’t break other functionalities.

Conclusion

Overriding core Magento files allows you to extend and modify the platform while keeping upgrades manageable. By following this guide, you should now be able to successfully rewrite Review/Model/Resource/Collection.php and Review/Model/Resource/Review.php.

If you’re looking for more advanced customization techniques or need professional help with your Magento implementation, don’t hesitate to reach out at https://laravelcompany.com. Our expert team is ready to assist you with any Magento-related challenges.

Extensions Themes Configuration Deployment

Our network