1

I have a custom xml file which has the block which i am targeting and it is productalert.xml as fallow:

<catalog_product_view>
    <reference name="content">
        <reference name="product.info">
            <reference name="alert.urls">
                <block type="productalert/product_view" name="productalert.price" as="productalert_price" template="productalert/product/view.phtml">
                    <action method="preparePriceAlertData"/>
                    <action method="setHtmlClass"><value>alert-price link-price-alert</value></action>
                    <action method="setSignupLabel" translate="value"><value>Sign up for price alert</value></action>
                </block>
                <block type="productalert/product_view" name="productalert.stock" as="productalert_stock" template="productalert/product/view.phtml">
                    <action method="prepareStockAlertData"/>
                    <action method="setHtmlClass"><value>alert-stock link-stock-alert</value></action>
                    <action method="setSignupLabel" translate="value"><value>Sign up to get notified when this product is back in stock</value></action>
                </block>
            </reference>
        </reference>
    </reference>
</catalog_product_view>

I want to include this two blocks in catalog.xml in product view so I am doing it here:

<reference name="content">
            <block type="scosche_catalog/product_view" name="product.info" template="catalog/product/view.phtml">
      <block type="productalert/product_view" name="productalert.price" as="productalert_price" template="productalert/product/view.phtml">
                        <action method="preparePriceAlertData"/>
                        <action method="setHtmlClass"><value>alert-price link-price-alert</value></action>
                        <action method="setSignupLabel" translate="value"><value>Sign up for price alert</value></action>
                    </block>
                    <block type="productalert/product_view" name="productalert.stock" as="productalert_stock" template="productalert/product/view.phtml">
                        <action method="prepareStockAlertData"/>
                        <action method="setHtmlClass"><value>alert-stock link-stock-alert</value></action>
                        <action method="setSignupLabel" translate="value"><value>Sign up to get notified when this product is back in stock</value></action>
                    </block>     
      </block>
    </reference>

then in catalog/product/view.phtml I called one of these two blocks as fallow:

<?php $this->getChildHtml('productalert_stock');?>

It is not working seems that I updated the catalog.xml wrong. how should i do it?

  • The layout file name does not matter, as long as the file is loaded. You can put your XML markup in whatever file you want. All you need is the correct update handle. In your case, it's <catalog_product_view>. – Dan Jun 11 '15 at 6:54
1

I would simply add this way

<catalog_product_view>
            <reference name="alert.urls">
                <block type="productalert/product_view" name="productalert.price" as="productalert_price" template="productalert/product/view.phtml">
                    <action method="preparePriceAlertData"/>
                    <action method="setHtmlClass"><value>alert-price link-price-alert</value></action>
                    <action method="setSignupLabel" translate="value"><value>Sign up for price alert</value></action>
                </block>
                <block type="productalert/product_view" name="productalert.stock" as="productalert_stock" template="productalert/product/view.phtml">
                    <action method="prepareStockAlertData"/>
                    <action method="setHtmlClass"><value>alert-stock link-stock-alert</value></action>
                    <action method="setSignupLabel" translate="value"><value>Sign up to get notified when this product is back in stock</value></action>
                </block>
            </reference>
</catalog_product_view>

This will find the alert.urls block and append these blocks inside it.

Hope this helps.

1

The line below will not work in the catalog_product_view handle.

<action method="prepareStockAlertData"/>

Once you remove that action from above block it will call that file. but I believe it is not the proper way to call product stock alert file in this handle.

  • Why not? In fact, that line is available by default in Magento in productalert.xml. – Dan Jun 11 '15 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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