Tuesday, February 14, 2012

Most Frequently Used Functions in Magento

1)Magento: How to call static block from template file?
We can Easily call a static block directly from template.
Let us suppose, you created a static block with the identifier aforankur_link.
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(‘aforankur_link’)->toHTML();?>

2)Magento: How to call block directly from phtml file without defining in layout?
<?php echo $this->getLayout()->createBlock(‘newmodule/newblock’)->setTemplate(‘newmodule/newblock.phtml’)->toHtml(); ?>

3)Magento: Add Static Block to CMS Page
{{block type=”cms/block” block_id=”home-page-promo”}}

4)Magento :How to call a phtml file in magento cms page
{{block type=”core/template” name=”a-name” template=”cms/home.phtml”}}


5) Magento Store – Get Base URL in Static Block
Try adding this to your static block:
<a href=”{{store url=”"}}”>Link to Base URL</a>

6) Mageto  : Skin URL
<a href=”#”><img src=”{{skin url=’images/home/dog-playing.jpg’}}” alt=”"/></a>

7) Magento: get Url
<a href=”<?php echo $this->getUrl(‘about-us’)?>”>

Thursday, February 9, 2012

Magento - Display total weight of Products in Cart

Here is some code snippet need to put -

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$weight = 0;
foreach($items as $item) {
    $weight += ($item->getWeight() * $item->getQty()) ;
}
echo $weight;

Custom Code for Sending Email to Customer



$order = new Mage_Sales_Model_Order();
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();

$order->loadByIncrementId($incrementId);

try
{
$order->sendNewOrderEmail();
} catch (Exception $ex) {  }

Wednesday, February 8, 2012

Magento | Use Mini-Login in Header or anywhere you want!

Add Mini-login at Header

Reach to following path and open the given xml file - 

app/design/frontend/default/default/layout/page.xml
  <block type="customer/form_login" name="mini_login" template="customer/form/mini.login.phtml" />
Then, you just have to call the module :
 <?php echo $this->getChildHtml('mini_login'?>

Thursday, February 2, 2012

Magento: Upgrading mysql setup of a module

MyModule. Its version is 0.1.0. Now, you want to do some database changes for the module. You have the mysql setup file (mysql install file) mysql4-install-0.1.0.php inMyModule/sql/mymodule_setup folder of your module.
You don’t need to make direct changes to database. You can upgrade your module to make your necessary database changes. To do so,
---------------------------------------------------------

1) You need to create a new mysql upgrade file inside MyModule/sql/mymodule_setupfolder.
Let us suppose that you are going to change the version of your module from 0.1.0 to 0.1.1.
The mysql upgrade file name should be mysql4-upgrade-0.1.0-0.1.1.php
The upgrade format is like mysql4-upgrade-CURRENT_VERSION-UPGRADED_VERSION.php
2) Write necessary sql statements in the newly added mysql upgrade file.
3) You have to change the version in MyModule/etc/config.xml as well.
Change the version like 0.1.1. 0.1.1 is the new version for our module.
4) Reload your site. And you are done!