Reputation: 163
I would like to replace the normal label "stock available" with the value of an attribute that the customer can set for each product through control panel. Easy like this and only for simple products.
Now, i would like to do it building a specific module, with which "turn off" this feature when and if needed. Why a module?
So, i want a total lazy load extension. The only think i can't succed to do is: within the layout file of my module, how can i do something like:
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="product.info.availability">
<block type="disponibilita/catalog_product_view_type_semplice" name="product.info.disponibilita" as="product_disponibilita" template="itserv/disponibilita/catalog/product/view/type/default.phtml"/>
</reference>
</catalog_product_view>
</layout>
I know it can't output anything by itself, but, as i've said, i don't want to edit or replace the product/view.phtml file with a getChildHtml call.
So: i know it's possible to remove via xml the product.info.availability block, but how can i replace it with my custom template (and block) without editing any core or original package/theme file?
Note: if i use output="toHtml" within the block declaration it seems to don't recognize the reference product.info.availability
Upvotes: 2
Views: 989
Reputation: 1621
I am assuming you are extending the class for block catalog/product_view_type_simple
in the usual way, which means your class now handles the existing calls in the layout and you don’t have to replace them. You can then just redefine the template for that block:
<reference name="product.info.availability">
<action method="setTemplate"><template>itserv/disponibilita/catalog/product/view/type/default.phtml</template></action>
</reference>
Upvotes: 2
Reputation: 1917
You should be able to remove the original block by its name, then insert your new block with the same name and alias. Since the default template file uses the block's alias to output it (<?php echo $this->getChildHtml('product_type_availability'); ?>
), it'll simply output your block in place of the original.
Something like:
<reference name="product.info">
<!-- remove original availability block -->
<remove name="product.info.availability" />
<!-- replace with your own availability block, keeping the same name and alias -->
<block type="disponibilita/catalog_product_view_type_semplice" name="product.info.availability" as="product_type_availability" template="itserv/disponibilita/catalog/product/view/type/default.phtml" />
</reference>
Upvotes: 1