0

When I use this code in layout Everything is good

<PRODUCT_TYPE_bundle>
    <reference name="head">
        <action method="addItem"><type>skin_js</type><name>js/chocolatebox/chocolatebox.js</name></action>
        <action method="addItem"><type>js_css</type><stylesheet>chocolatebox/css/style.css</stylesheet></action>
    </reference>
    <reference name="product.info">
    <action method="setTemplate">
        <template>chocolatebox/chocolatebox.phtml</template>
    </action>
</reference>
</PRODUCT_TYPE_bundle>

But I want to apply to my template using blocks. When i doing this my template is destroying

<?php
class Chocolate_Box_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{

    public function _beforeToHtml(){
//       /die();
       $this->setTemplate("chocolatebox/chocolatebox.phtml");
    }
}

config

<blocks>
        <chocolatebox>
            <class>Chocolate_Box_Block</class>
        </chocolatebox>
        <bundle>
            <rewrite>
                <catalog_product_view_type_bundle_option_radio>Chocolate_Box_Block_Catalog_Product_View_Type_Bundle_Option_Radio</catalog_product_view_type_bundle_option_radio>
            </rewrite>
        </bundle>
        <catalog>
            <rewrite>
                <product_view>Chocolate_Box_Block_Catalog_Product_View</product_view>
            </rewrite>
        </catalog>
    </blocks>
4
  • could you please look for error messages, increase the error output and activate dev mode? Also could you look at which line the html output stops and show this line of the template/php class?
    – Flyingmana
    Commented Nov 24, 2014 at 13:36
  • I'd be surprised if the chocolatebox/chocolatebox.phtml template is being set correctly by this layout XML - the <action /> tag needs to either be a child of a block or <reference /> tag OR it needs to have a block="" attribute declaration.
    – benmarks
    Commented Nov 24, 2014 at 14:38
  • Also, minor points (not the issue): _beforeToHtml() should be protected not public scope, and it should return either the parent or $this.
    – benmarks
    Commented Nov 24, 2014 at 14:51
  • And in conclusion, try instantiating your class directly in a workbench script to see if there are unrelated issues.
    – benmarks
    Commented Nov 24, 2014 at 14:52

1 Answer 1

1

The setTemplate should be called from the _construct function. As Ben Marks commented it should work from _beforeHtml tho. refactor the block class to look something like this:

<?php
class Chocolate_Box_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View
{

    public function _construct(){
       parent::_construct();
       $this->setTemplate("chocolatebox/chocolatebox.phtml");
    }
}
6
  • No it doesn`t help
    – Sergey
    Commented Nov 24, 2014 at 13:16
  • Maybe problem in layout??
    – Sergey
    Commented Nov 24, 2014 at 13:25
  • Could be but without any further info I won't be able to help you find the issue Commented Nov 24, 2014 at 13:48
  • "..._beforeToHtml will be to late to manipulate the template" No it's not ;-)
    – benmarks
    Commented Nov 24, 2014 at 14:25
  • 2
    Sitting in Damian's docker presentation at the moment. They pay me to multitask.
    – benmarks
    Commented Nov 24, 2014 at 14:41

Your Answer

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

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