June 26, 2015 9:17 pm
image_round

Magento send custom email

Magento send custom email

In Magento we have to follow below steps

Step 1: Define html template in your magento module config.xml

<template>
            <email>
                <custom_email_template translate="label" module="vendor">
                    <label>New account</label>
                    <file>custom_email_template.html</file>
                    <type>html</type>
                </custom_email_template>
             </email>   
     </template>

Step2: Add below  code to your magento observer or to controller

<?php 

$storeId=Mage::app()->getStore()->getId();

/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo((string)$Vendor->getEmail(),(string) $Vendor->getName());
$mailer->addEmailInfo($emailInfo);
// Set all required params and send emails
$mailer->setSender(array('email'=>(string) 'test@gmail.com','name'=> (string)'testing'));
$mailer->setStoreId($storeId);
$mailer->setTemplateId((string) 'custom_email_template');
$mailer->setTemplateParams(array('user'=>$user));
$mailer->send();

Step3: Create Html magento email template like below

<!--@subject Welcome, {{var user.name}}! @-->
<!--@vars
{"store url=""":"Store Url",
"var logo_url":"Email Logo Image Url",
"htmlescape var=vendor.name":"Customer Name",
"store url="customer/account/"":"Customer Account Url",
"var vendor.email":"Customer Email",
"htmlescape var=$customer.password":"Customer Password"}
@-->
 
<!--@styles
body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
@-->
 
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
        <tr>
            <td align="center" valign="top" style="padding:20px 0 20px 0">
                <!-- [ header starts here] -->
                <table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
                    <tr>
                        <td valign="top">
                            <a href="{{store url=""}}"><img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/></a></td>
                    </tr>
                <!-- [ middle starts here] -->
                    <tr>
                        <td valign="top">
                            <h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">Dear {{htmlescape var=$user.name}},</h1>
                            <p style="font-size:12px; line-height:16px; margin:0 0 16px 0;">Welcome to {{var store.getFrontendName()}}. To log in when visiting our site just click <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">Login</a> or <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">My Account</a> at the top of every page, and then enter your e-mail address and password.</p>
                            <p style="border:1px solid #E0E0E0; font-size:12px; line-height:16px; margin:0; padding:13px 18px; background:#f9f9f9;">
                                Use the following values when prompted to log in:<br/>
                                <strong>E-mail</strong>: {{var user.email}}<br/>
                                <strong>Password</strong>: {{htmlescape var=$user.password}}<p>
                            <p style="font-size:12px; line-height:16px; margin:0 0 8px 0;">When you log in to your account, you will be able to do the following:</p>
                            <ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Proceed through checkout faster when making a purchase</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Check the status of orders</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; View past orders</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Make changes to your account information</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Change your password</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Store alternative addresses (for shipping to multiple family members and friends!)</li>
                            </ul>
                            <p style="font-size:12px; line-height:16px; margin:0;">If you have any questions about your account or any other matter, please feel free to contact us at <a href="mailto:{{config path='trans_email/ident_support/email'}}" style="color:#1E7EC8;">{{config path='trans_email/ident_support/email'}}</a> or by phone at {{config path='general/store_information/phone'}}.</p>
                        </td>
                    </tr>
                    <tr>
                        <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you again, <strong>{{var store.getFrontendName()}}</strong></p></center></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>

Hope this will helps with your magento store

Regards

Magento send custom email

Magento send custom email

In Magento we have to follow below steps

Step 1: Define html template in your magento module config.xml

<template>
            <email>
                <custom_email_template translate="label" module="vendor">
                    <label>New account</label>
                    <file>custom_email_template.html</file>
                    <type>html</type>
                </custom_email_template>
             </email>   
     </template>

Step2: Add below  code to your magento observer or to controller

<?php 

$storeId=Mage::app()->getStore()->getId();

/** @var $mailer Mage_Core_Model_Email_Template_Mailer */
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
$emailInfo->addTo((string)$Vendor->getEmail(),(string) $Vendor->getName());
$mailer->addEmailInfo($emailInfo);
// Set all required params and send emails
$mailer->setSender(array('email'=>(string) 'test@gmail.com','name'=> (string)'testing'));
$mailer->setStoreId($storeId);
$mailer->setTemplateId((string) 'custom_email_template');
$mailer->setTemplateParams(array('user'=>$user));
$mailer->send();

Step3: Create Html magento email template like below

<!--@subject Welcome, {{var user.name}}! @-->
<!--@vars
{"store url=""":"Store Url",
"var logo_url":"Email Logo Image Url",
"htmlescape var=vendor.name":"Customer Name",
"store url="customer/account/"":"Customer Account Url",
"var vendor.email":"Customer Email",
"htmlescape var=$customer.password":"Customer Password"}
@-->
 
<!--@styles
body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
@-->
 
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
        <tr>
            <td align="center" valign="top" style="padding:20px 0 20px 0">
                <!-- [ header starts here] -->
                <table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
                    <tr>
                        <td valign="top">
                            <a href="{{store url=""}}"><img src="{{var logo_url}}" alt="{{var logo_alt}}" style="margin-bottom:10px;" border="0"/></a></td>
                    </tr>
                <!-- [ middle starts here] -->
                    <tr>
                        <td valign="top">
                            <h1 style="font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;"">Dear {{htmlescape var=$user.name}},</h1>
                            <p style="font-size:12px; line-height:16px; margin:0 0 16px 0;">Welcome to {{var store.getFrontendName()}}. To log in when visiting our site just click <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">Login</a> or <a href="{{store url="customer/account/"}}" style="color:#1E7EC8;">My Account</a> at the top of every page, and then enter your e-mail address and password.</p>
                            <p style="border:1px solid #E0E0E0; font-size:12px; line-height:16px; margin:0; padding:13px 18px; background:#f9f9f9;">
                                Use the following values when prompted to log in:<br/>
                                <strong>E-mail</strong>: {{var user.email}}<br/>
                                <strong>Password</strong>: {{htmlescape var=$user.password}}<p>
                            <p style="font-size:12px; line-height:16px; margin:0 0 8px 0;">When you log in to your account, you will be able to do the following:</p>
                            <ul style="font-size:12px; line-height:16px; margin:0 0 16px 0; padding:0;">
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Proceed through checkout faster when making a purchase</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Check the status of orders</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; View past orders</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Make changes to your account information</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Change your password</li>
                                <li style="list-style:none inside; padding:0 0 0 10px;">&ndash; Store alternative addresses (for shipping to multiple family members and friends!)</li>
                            </ul>
                            <p style="font-size:12px; line-height:16px; margin:0;">If you have any questions about your account or any other matter, please feel free to contact us at <a href="mailto:{{config path='trans_email/ident_support/email'}}" style="color:#1E7EC8;">{{config path='trans_email/ident_support/email'}}</a> or by phone at {{config path='general/store_information/phone'}}.</p>
                        </td>
                    </tr>
                    <tr>
                        <td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA; text-align:center;"><center><p style="font-size:12px; margin:0;">Thank you again, <strong>{{var store.getFrontendName()}}</strong></p></center></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>

Hope this will helps with your magento store

Regards

June 26, 2015 8:50 pm
image_round

Magento update currency rates

Magento update currency rates from base currency to current currency

Magento: here is code to fetch current currency code and to get default(base) currency code in magento

<?php 

Mage::app()->getStore()->getDefaultCurrencyCode();

Mage::app()->getStore()->getCurrentCurrencyCode();
?>

Update price based from base currency to current currency in magento

<?php

$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode(); 
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode(); 

$price = Mage::helper('directory')->currencyConvert($pricetoconvert, $baseCurrencyCode, $currentCurrencyCode); 

?>

Magento update currency rates

Magento update currency rates from base currency to current currency

Magento: here is code to fetch current currency code and to get default(base) currency code in magento

<?php 

Mage::app()->getStore()->getDefaultCurrencyCode();

Mage::app()->getStore()->getCurrentCurrencyCode();
?>

Update price based from base currency to current currency in magento

<?php

$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode(); 
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode(); 

$price = Mage::helper('directory')->currencyConvert($pricetoconvert, $baseCurrencyCode, $currentCurrencyCode); 

?>
June 26, 2015 8:25 pm
image_round

Magento Apply Custom theme

Magento Apply Custom theme

Magento Apply Custom theme to your site bu two way, just upload custom theme and set save theme name to admin that’s it

#1 system -> design -> add new

just set there theme package and it will change theme of site

here you can setup timer untill what time site will have this design

#2 system -> Configuration -> Design -> Package / themes

just change main folder name (package) and change theme name and it will apply it automatically

Magento Apply Custom theme

Magento Apply Custom theme

Magento Apply Custom theme to your site bu two way, just upload custom theme and set save theme name to admin that’s it

#1 system -> design -> add new

just set there theme package and it will change theme of site

here you can setup timer untill what time site will have this design

#2 system -> Configuration -> Design -> Package / themes

just change main folder name (package) and change theme name and it will apply it automatically

June 26, 2015 8:20 pm
image_round

Magento get system Configuration value

Magento get system Configuration value

In magento if we need to fetch any data from system -> Configuration section then we just need to use below code

<?php 
echo Mage::getStoreConfig('design/footer/copyright') 
?>

here is explanation what each section indicates

<?php 

echo Mage::getStoreConfig('section/group/field')

// section indicates section on left sidebar
// group indicates name of fieldset
// field indicates fieldname

 ?>

 

Magento get system Configuration value

Magento get system Configuration value

In magento if we need to fetch any data from system -> Configuration section then we just need to use below code

<?php 
echo Mage::getStoreConfig('design/footer/copyright') 
?>

here is explanation what each section indicates

<?php 

echo Mage::getStoreConfig('section/group/field')

// section indicates section on left sidebar
// group indicates name of fieldset
// field indicates fieldname

 ?>

 

June 26, 2015 8:14 pm
image_round

Magento Fetch category products to custom page

Magento Fetch category products to custom page

sometimes with Magento Fetch category products to custom page / custom block .. so here is simple code we can use and can have category’s products with ease

<?php 

$categoryId = (int category number);
$category = Mage::getModel('catalog/category')->load($categoryId);
 
$productcollection = Mage::getResourceModel('catalog/product_collection')
      ->addCategoryFilter($category)
      ->addAttributeToSelect('*');
 
/***************************************************
  Applying status and visibility filter to the product collection
  i.e. only fetching visible and enabled products
****************************************************/
Mage::getSingleton('catalog/product_status')
  ->addVisibleFilterToCollection($productcollection);	
  
Mage::getSingleton('catalog/product_visibility')
  ->addVisibleInCatalogFilterToCollection($productcollection); 
 
/** 
 * Printing category and products name
 */ 
echo '<h1><strong>'.$category->getName().'</strong></h1>';
foreach ($productcollection as $val) {
  echo $val->getName() . '<br />';
}

?>

Here you may have noticed one code that filter product based on its availability or visibility

<?php 

Mage::getSingleton('catalog/product_status')
  ->addVisibleFilterToCollection($productcollection);	
  
Mage::getSingleton('catalog/product_visibility')
  ->addVisibleInCatalogFilterToCollection($productcollection); 

?>

Magento Fetch category products to custom page

Magento Fetch category products to custom page

sometimes with Magento Fetch category products to custom page / custom block .. so here is simple code we can use and can have category’s products with ease

<?php 

$categoryId = (int category number);
$category = Mage::getModel('catalog/category')->load($categoryId);
 
$productcollection = Mage::getResourceModel('catalog/product_collection')
      ->addCategoryFilter($category)
      ->addAttributeToSelect('*');
 
/***************************************************
  Applying status and visibility filter to the product collection
  i.e. only fetching visible and enabled products
****************************************************/
Mage::getSingleton('catalog/product_status')
  ->addVisibleFilterToCollection($productcollection);	
  
Mage::getSingleton('catalog/product_visibility')
  ->addVisibleInCatalogFilterToCollection($productcollection); 
 
/** 
 * Printing category and products name
 */ 
echo '<h1><strong>'.$category->getName().'</strong></h1>';
foreach ($productcollection as $val) {
  echo $val->getName() . '<br />';
}

?>

Here you may have noticed one code that filter product based on its availability or visibility

<?php 

Mage::getSingleton('catalog/product_status')
  ->addVisibleFilterToCollection($productcollection);	
  
Mage::getSingleton('catalog/product_visibility')
  ->addVisibleInCatalogFilterToCollection($productcollection); 

?>
June 26, 2015 8:05 pm
image_round

Magento Add all states of India

Magento Add all states of India

Magento Add all states of India : Simply run below sql query and you will have all states of india on register / checkout / customer address form

<?php 
INSERT INTO `directory_country_region` VALUES
(NULL , "IN", "Andaman and Nicobar","Andaman and Nicobar"),
(NULL , "IN", "Andhra Pradesh","Andhra Pradesh"),
(NULL , "IN", "Arunachal Pradesh","Arunachal Pradesh"),
(NULL , "IN", "Assam","Assam"),
(NULL , "IN", "Bihar","Bihar"),
(NULL , "IN", "Chandigarh","Chandigarh"),
(NULL , "IN", "Chhattisgarh","Chhattisgarh"),
(NULL , "IN", "Dadra and Nagar Haveli","Dadra and Nagar Haveli"),
(NULL , "IN", "Daman and Diu","Daman and Diu"),
(NULL , "IN", "Delhi","Delhi"),
(NULL , "IN", "Goa","Goa"),
(NULL , "IN", "Gujarat","Gujarat"),
(NULL , "IN", "Haryana","Haryana"),
(NULL , "IN", "Himachal Pradesh","Himachal Pradesh"),
(NULL , "IN", "Jammu and Kashmir","Jammu and Kashmir"),
(NULL , "IN", "Jharkhand","Jharkhand"),
(NULL , "IN", "Karnataka","Karnataka"),
(NULL , "IN", "Kerala","Kerala"),
(NULL , "IN", "Lakshadweep","Lakshadweep"),
(NULL , "IN", "Madhya Pradesh","Madhya Pradesh"),
(NULL , "IN", "Maharashtra","Maharashtra"),
(NULL , "IN", "Manipur","Manipur"),
(NULL , "IN", "Meghalaya","Meghalaya"),
(NULL , "IN", "Mizoram","Mizoram"),
(NULL , "IN", "Nagaland","Nagaland"),
(NULL , "IN", "Orissa","Orissa"),
(NULL , "IN", "Pondicherry","Pondicherry"),
(NULL , "IN", "Punjab","Punjab"),
(NULL , "IN", "Rajasthan","Rajasthan"),
(NULL , "IN", "Sikkim","Sikkim"),
(NULL , "IN", "Tamil Nadu","Tamil Nadu"),
(NULL , "IN", "Tripura","Tripura"),
(NULL , "IN", "Uttar Pradesh","Uttar Pradesh"),
(NULL , "IN", "Uttaranchal","Uttaranchal"),
(NULL , "IN", "West Bengal","West Bengal");
 
INSERT INTO `directory_country_region_name` (`locale` ,`region_id` ,`name` )
SELECT 'en_US', tmp.region_id, tmp.default_name FROM `directory_country_region`
AS tmp WHERE tmp.country_id='IN';

?>

Magento Add all states of India

Magento Add all states of India

Magento Add all states of India : Simply run below sql query and you will have all states of india on register / checkout / customer address form

<?php 
INSERT INTO `directory_country_region` VALUES
(NULL , "IN", "Andaman and Nicobar","Andaman and Nicobar"),
(NULL , "IN", "Andhra Pradesh","Andhra Pradesh"),
(NULL , "IN", "Arunachal Pradesh","Arunachal Pradesh"),
(NULL , "IN", "Assam","Assam"),
(NULL , "IN", "Bihar","Bihar"),
(NULL , "IN", "Chandigarh","Chandigarh"),
(NULL , "IN", "Chhattisgarh","Chhattisgarh"),
(NULL , "IN", "Dadra and Nagar Haveli","Dadra and Nagar Haveli"),
(NULL , "IN", "Daman and Diu","Daman and Diu"),
(NULL , "IN", "Delhi","Delhi"),
(NULL , "IN", "Goa","Goa"),
(NULL , "IN", "Gujarat","Gujarat"),
(NULL , "IN", "Haryana","Haryana"),
(NULL , "IN", "Himachal Pradesh","Himachal Pradesh"),
(NULL , "IN", "Jammu and Kashmir","Jammu and Kashmir"),
(NULL , "IN", "Jharkhand","Jharkhand"),
(NULL , "IN", "Karnataka","Karnataka"),
(NULL , "IN", "Kerala","Kerala"),
(NULL , "IN", "Lakshadweep","Lakshadweep"),
(NULL , "IN", "Madhya Pradesh","Madhya Pradesh"),
(NULL , "IN", "Maharashtra","Maharashtra"),
(NULL , "IN", "Manipur","Manipur"),
(NULL , "IN", "Meghalaya","Meghalaya"),
(NULL , "IN", "Mizoram","Mizoram"),
(NULL , "IN", "Nagaland","Nagaland"),
(NULL , "IN", "Orissa","Orissa"),
(NULL , "IN", "Pondicherry","Pondicherry"),
(NULL , "IN", "Punjab","Punjab"),
(NULL , "IN", "Rajasthan","Rajasthan"),
(NULL , "IN", "Sikkim","Sikkim"),
(NULL , "IN", "Tamil Nadu","Tamil Nadu"),
(NULL , "IN", "Tripura","Tripura"),
(NULL , "IN", "Uttar Pradesh","Uttar Pradesh"),
(NULL , "IN", "Uttaranchal","Uttaranchal"),
(NULL , "IN", "West Bengal","West Bengal");
 
INSERT INTO `directory_country_region_name` (`locale` ,`region_id` ,`name` )
SELECT 'en_US', tmp.region_id, tmp.default_name FROM `directory_country_region`
AS tmp WHERE tmp.country_id='IN';

?>
June 26, 2015 8:03 pm
image_round

Magento create custom page layout

Magento create custom page layout

Magento create custom page layout :Use setTemplate code to apply custom template to any page / category /product view /etc..
Template of Any page on site can be changed with just below code

<reference name="root">
 <action method="setTemplate"><template>page/empty.phtml</template></action>
</reference>
<checkout_cart_index translate="label"> 
  <reference name="root"> 
     <action method="setTemplate">
        <template>page/2columns-left.phtml</template>
     </action> 
  </reference> 
</checkout_cart_index>

Magento create custom page layout

Magento create custom page layout

Magento create custom page layout :Use setTemplate code to apply custom template to any page / category /product view /etc..
Template of Any page on site can be changed with just below code

<reference name="root">
 <action method="setTemplate"><template>page/empty.phtml</template></action>
</reference>
<checkout_cart_index translate="label"> 
  <reference name="root"> 
     <action method="setTemplate">
        <template>page/2columns-left.phtml</template>
     </action> 
  </reference> 
</checkout_cart_index>