Resources

Magento Code Snippets

Magento is a very large eCommerce package and therefor you easily get lost in the code. We do Magento themes a lot and below you will find a few of our developers most-used code snippets.

Static blocks

Load a static block from the admin in your theme. First add this piece of XML to your cms.xml for example.

<block type="cms/block" name="static_block_name">
	<action method="setBlockId"><block_id>static_block_name</block_id></action>
</block>

If you have made the reference in the theme XML you are now able to get the output from the static block in your .phtml file like this.

$this->getChildHtml("static_block_name");

Price snippets

Format a price integer to a money format including currency symbol.

Mage::helper("checkout")->formatPrice(15.99);
 
// Use cart subtotal on cart.phtml
Mage::helper("checkout")->formatPrice($this->getSubtotal());

Get the price block including sales etc. on a catalog product page.

$this->getPriceHtml($_product);