In this post, I will show how to display one product in magento store inside a CMS page with CMS block widget.Magento ‘ve already supported a widget “product_widget_link” and we only need to use and customize the template. Here is the way we display a product in magento CMS page.

widget-in-wysiwyg-mode-1

{{widget type="catalog/product_widget_link"
anchor_text="[Optional: CUSTOM LINK TEXT]"
template="catalog/product/widget/link/link_block.phtml"
id_path="product/223552"}}

Then customize the template file in app/design/frontend/base/default/template/catalog/product/widget/link/link_block.phtml.

You can do the customisation something like this:

<?php

$_product = $this->getProduct();
$_image = '';
$_price = '$' . money_format('%n', $_product->getFinalPrice());

if ($_product) {
    $_image = Mage::helper('catalog/image')->init($_product, 'thumbnail')
        ->keepAspectRatio(true)
        ->keepFrame(true)
        ->resize(115,115)
        ->__toString();
}
?>
<div class="item">
    <a <?php echo $this->getLinkAttributes() ?>>
        <img src="<?php echo $_image; ?>" alt="<?php echo $this->htmlEscape($this->getAnchorText()); ?>" style="border:0" />
        <?php echo nl2br($this->htmlEscape($this->getAnchorText())); ?><br />
        <b><?php echo $_price; ?></b>
    </a>
</div>

One thought on “CMS block widget for Product in Magento

Comments are closed.