1

I'm trying to extend Mage_Review_Block_Product_View but my new class is not called... I think it could be a typo, but I can't find it.

It is not a issue related to the code inside my class, but to the calling of class rewrite. If I make an override placing the modified class in app/code/local/Mage/Review/Block/Product/View.php it does it job.

If I try to integrate the rewrite in a module it is not called. Here me code:

module config.xml:

[...]
<global>
  <blocks>
    [...]
    <review>
      <rewrite>
        <form>Bbox_ExtendReview_Block_Review_Form</form>
        <product_view>Bbox_ExtendReview_Block_Review_Product_View</product_view>
      </rewrite>
    </review>
    [...]
  </blocks>
  [...]
</global>

Than in app/code/local/Bbox/ExtendReview/Block/Review I have:

  • Form.php that is correctly called
  • Product/View.php that is not called

The View.php contain the class extension:

<?php

class Bbox_ExtendReview_Block_Review_Product_View extends Mage_Review_Block_Product_View
{

public function getReviewsCollection()
{
    //some code...
}

Everything looks fine to me.. and the rewrite in Form.php is correctly working, so I don't understand way the Product/View.php is not...

I'll really appreciate any advice.

4 Answers 4

3

After days of debug I've found out the solution just after I post the question here...

As Alan Storm stated here it is an issue related to the order of the inheritance chain:
Mage_Review_Block_Product_View is extend by Mage_Review_Block_Product_View_List and this one doesn't know anything about my new Bbox_ExtendReview_Block_Product_View that correctly extends Mage_Review_Block_Product_View but it is never used.

I just change my code to extend Mage_Review_Block_Product_View_List and now everything work fine:

confing.xml:

<review>
    <rewrite>
      [...]           
        <product_view_list>CJM_ColorSelectorPlus_Block_Review_Product_View_List</product_view_list>
    </rewrite>
  </review>

than I move the code to app/code/local/Bbox/ExtendReview/Block/Review/Product/View/List.php:

class CJM_ColorSelectorPlus_Block_Review_Product_View_List extends Mage_Review_Block_Product_View_List
{
  //my code
}

I hope this could be useful to someone else.

2

The class is not instantiated itself, instead Mage_Review_Block_Product_View_List which extends Mage_Review_Block_Product_View.

Rewrites do not affect child classes, so you need to add this:

    <product_view_list>Bbox_ExtendReview_Block_Review_Product_View_List</product_view_list>

and a class Bbox_ExtendReview_Block_Review_Product_View_List just like Mage_Review_Block_Product_View_List but extending your rewritten class.

2
  • Thanks for answering. The white space is not present in my config.xml I edited my question to remove that.
    – danipen
    Jan 7, 2016 at 10:42
  • I updated the answer and just then found out that you already found the answer on your own. Jan 7, 2016 at 11:03
1

I have also the same issue I want to rewrite getReviewsCollection function from Mage_Review_Block_Product_View class So the process i follow is below.

Firt create My module file class like Test_Coreoverride_Block_Review_Product_View_List and write my function to this file class.

<?php
class Test_Coreoverride_Block_Review_Product_View_List extends Mage_Review_Block_Product_View
{
    public function getReviewsCollection()
    {
        if (null === $this->_reviewsCollection) {
            $this->_reviewsCollection = Mage::getModel('review/review')->getCollection()
                ->addStoreFilter(Mage::app()->getStore()->getId())
                ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
                ->addEntityFilter('product', $this->getProduct()->getId())
                ->setDateOrder();
        }
        return $this->_reviewsCollection;
    }
}

and the config.xml

<blocks>
        <coreoverride>
            <class>Test_Coreoverride_Block</class>
        </coreoverride>

        <review>
            <rewrite>
                <product_view_list>Test_Coreoverride_Block_Review_Product_View_List</product_view_list>
            </rewrite>
        </review>
    </blocks>
0

Try below code in config.xml.

[...]
<global>
    <blocks>
        <review>
            <rewrite>
                <product_view>Bbox_ExtendReview_Block_Product_View</product_view>
            </rewrite>
        </review>
    </blocks>
</global>

and

<?php
class Bbox_ExtendReview_Block_Product_View extends Mage_Review_Block_Product_View {
// some code
}

I hope it will help.

1
  • Thanks for answering. The white space is not present in my config.xml I edited my question to remove that.
    – danipen
    Jan 7, 2016 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.