Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to extend a Review helper.php [UNsolved]
 
Christian_Norway
Sr. Member
 
Total Posts:  135
Joined:  2008-06-18
 

Hi guys,

Magento: 1.1.1-1.1.3
Update: - The file I am trying to overwrite is: app/code/core/Mage/Review/Block/Helper.php

I’m trying to expand the Mage_Review_Block_Helper.php, so to accept a new template file “short_one_line”. This works fine if I change the code directly. But as we all know this is not good as it will be overwritten in future updates of Magento.

So I am now trying to create my first module, that will overwrite or rewrite the Mage code.  As you can see from the first piece of code below, the only thing this module does is to add a third array option “‘short_one_line’ => ‘review/helper/summary_short_one_line.phtml’”.

My problem is that I can’t get it to work. I hope someone can help.

private $_availableTemplates = array(
        
'default' => 'review/helper/summary.phtml',
        
'short'   => 'review/helper/summary_short.phtml',
        
'short_one_line' => 'review/helper/summary_short_one_line.phtml'
 
    
);

app/code/local/Ctech/RatingFix/Block/Helper.php

<?php

class Ctech_RatingFix_Block_Helper extends Mage_Review_Block_Helper
{
    
private $_availableTemplates = array(
        
'default' => 'review/helper/summary.phtml',
        
'short'   => 'review/helper/summary_short.phtml',
        
'short_one_line' => 'review/helper/summary_short_one_line.phtml'
 
    
);
    
}
?>

app/code/local/Ctech/RatingFix/ect/config.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Ctech_RatingFix>
            <
version>0.1</version>
        </
Ctech_RatingFix>
    </
modules>
    
    <global>        
        <
blocks>
            <
review>
                <
rewrite>
                    <
helper>Ctech_RatingFix_Block_Helper</helper>
                </
rewrite>
            </
review>
        </
blocks>
    </global>
</
config>

app/etc/modules/Ctech_RatingFix.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Ctech_RatingFix>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Ctech_RatingFix>
    </
modules>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Christian_Norway
Sr. Member
 
Total Posts:  135
Joined:  2008-06-18
 

bump, sorry

 
Magento Community Magento Community
Magento Community
Magento Community
 
somesid
Sr. Member
 
Total Posts:  83
Joined:  2008-06-20
 

From I’ve seen in Magento I think the problem is somewhere here :

<global>        
        <
blocks>
            <
review>
                <
rewrite>
                    <
helper>Ctech_RatingFix_Block_Helper</helper>
                </
rewrite>
            </
review>
        </
blocks>
    </global>

You try to use the tutorial for overriding blocks, but you’ve got something different here. So you could try replacing blocks by helpers.

Then another thing dunno where your helper is called (view, controller or model) but if it’s in a view you can call directly your new helper instead of the old one.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Christian_Norway
Sr. Member
 
Total Posts:  135
Joined:  2008-06-18
 

Hei,

I am not trying to overwrite a helper, but a helper.php file within the block folder

- The file I am trying to overwrite is: Mage/Review/Block/Helper.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
somesid
Sr. Member
 
Total Posts:  83
Joined:  2008-06-20
 

Ok my mistake, so it seems ok to me, only thing I would be carefull about is using module names like that : RatingFix, Ratingfix would be a better way to go.
I had bad surprises using such case.
I just tried overriding another block I had done directly on the core, using the same way you did it and cross-checking with other threads and it worked fine. So it’s probably stupid like the module name case, or something like that.

Oh and another thing you should try adding a new method to your overriding block, something stupid like :

public function getStuff()
{
    
return 'It works';
}

and then check if you’re able to get the return value in your template. This way you will now if the overriding works or not.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Christian_Norway
Sr. Member
 
Total Posts:  135
Joined:  2008-06-18
 

somesid:

That is a good idea. 

Trying that returns no value. So it is evident that my module is not working. I will try to rename the module as you said with no capital letters in the middle of the name.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Christian_Norway
Sr. Member
 
Total Posts:  135
Joined:  2008-06-18
 

I’ve gone through and nothing changes. Can it have something to do with that I am trying to overwrite a “private” rather than “public” code set? See below:

Overwrite this:

private $_availableTemplates = array(
        
'default' => 'review/helper/summary.phtml',
        
'short'   => 'review/helper/summary_short.phtml'
 
    
);

With this:

private $_availableTemplates = array(
        
'default' => 'review/helper/summary.phtml',
        
'short'   => 'review/helper/summary_short.phtml',
        
'short_one_line' => 'review/helper/summary_short_one_line.phtml'
 
    
);
 
Magento Community Magento Community
Magento Community
Magento Community
 
somesid
Sr. Member
 
Total Posts:  83
Joined:  2008-06-20
 

Yeah, that’s what I’ve been wondering, I think when a class inherit another that you can’t override a private variable (would have to be protected to do so).
I think the right way, programmatically speaking, would be to use a public function to set again this variable like :

public function setAvailableTemplatesnewValue = array() ){
     $this
->availableTemplates newValue;
}

But I’m not sure that what you need smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Christian_Norway
Sr. Member
 
Total Posts:  135
Joined:  2008-06-18
 

somesid:

What I have to be careful about is taking away the possibility of other pages in Magento using the other templates.

So whatever I do. There have to be 3 templates available for the function (getSummaryHtml()) to use.

somesid:

Not sure how I can use your function above. How would getSummaryHtml() get hold of the template you set in this function?

 
Magento Community Magento Community
Magento Community
Magento Community
 
somesid
Sr. Member
 
Total Posts:  83
Joined:  2008-06-20
 

Yes I think you’re stuck unless you hack the core.
I was just pointing the “right way” in general, but I don’t think you can apply this solution here, or in would be in a way dirtier than hacking the core.
Well, sorry I haven’t been really helpful.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Christian_Norway
Sr. Member
 
Total Posts:  135
Joined:  2008-06-18
 

I guess I will have to do with hacking the core then… as I did earlier grin

Thanks anyway

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top