Nov 7, 2011
Custom Email Templates in Magento
Hello,
I am explaining here the method for sending custom emails using the custom email templates with variables.
1) Create an email template from Admin-end > System > Transactional Emails, for example lets put this as Template Content
<!--@vars
{
"htmlescape var=$customer.name":"Customer Name",
"var customer.email":"Customer Email"
}
@-->
Dear {{htmlescape...
read more
Oct 3, 2010
Useful code in Magento
I am listing here the codes useful in Magento
Magento Home URL
- Mage::getBaseUrl();
Magento Home Directory
- Mage::getBaseDir();
URL of a file in the skin directory
- $this->getSkinUrl(‘images/myfile.png’); // in a template or Block
- Mage::getDesign()->getSkinUrl(‘images/myfile.png’); // from anywhere
Format a price value
- Mage::helper(‘core’)->formatPrice($amount);
Get...
read more
Apr 10, 2010
Passing by Reference
I am listing here a simple example to explain ‘passing by reference’ in PHP.
I hope it is helpful.
<?php
$a = 5;
echo 'A1->'.$a.'<br/>';
$b = 6;
$a =& $b;
echo 'A2->'.$a.'<br/>B1->'.$b.'<br/>';
global $var;
function foo(&$var)
{
$var++;
}
$a=5;
echo 'A3->'.$a.'<br/>';
foo($a);
echo 'A4->'.$a.'<br/>Var->'.$var;
?>
For...
read more
Feb 26, 2010
Reading XML
I am listing here method for reading XML file or XML string with the help of PHP.
<?php
$xml =<<<EOT
<?xml version="1.0"?>
<root>
<section name="Section1">
<category id="Category1" name="google">
<article name="article1">value1</article>
</category>
<category id="Category2"...
read more
Feb 24, 2010
Get Product ID and Product Name in Magento
In Magento eCommerce while working with catalog model, There arise the need to fetch product details from product id.
We can get all product details if we have product id.
But sometimes we only have product name, so we need to get product id for getting product details.
I am listing here both the method.
1) Product details from Product ID.
<?php
$model = Mage::getModel('catalog/product') //getting...
read more
Feb 10, 2010
Extracting String
This is small but very useful script.
I have shown example for extracting only ‘src’ value from the ‘img’ tag, but you can modify and use as per your requirement using ‘preg_match_all’ function.
<?php
$src= '<img height="120" width="120" border="0" src="http://www.somesite.com/abc.jpg" class="image"/>';
preg_match_all('/(src)=("[^"]*")/i',$src,...
read more
Feb 10, 2010
Page Redirect
I have written a script for getting the files list from directory and redirecting the page on selecting option from the select box.
So you will get the script for fetching all the files from current directory and redirecting page on selection.
<h>Please select option</h>
<?php
$path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']; //current directory physical path
$dir_handle =...
read more
Jan 22, 2010
Get IP Address in PHP
Many times we need the IP Address of the User visiting our website in our Application.
I am listing here the method to get the User IP Address, hope it might be useful to many of you.
//function for getting IP
//start
function getuserip()
{
if (isset($_SERVER))
{
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
return $_SERVER["HTTP_X_FORWARDED_FOR"];
...
read more
Jan 14, 2010
Joomla essentials
Joomla is a very great CMS.
I am listing below important variable used in joomla.
JPath is used to get the directory path.
DS — is used as a directory separator.
JPATH_ADMINISTRATOR– Sets the path to /Joomla/administrator
JPATH_BASE — sets the entry to joomla /Joomla
JPATH_CACHE –Sets the cache path /Joomla/cache
JPATH_COMPONENT — Sets the component path /Joomla/components/com_example
JPATH_COMPONENT_ADMINISTRATOR...
read more
Jan 14, 2010
Magento Essentials
I am listing below important variable used in Magento.
<?php
echo Mage::app()->getFrontController()->getRequest()->getHttpHost();
//displays host name
echo Mage::getBaseDir(); //gives physical path of the sites root directory
echo $this->getSkinURL(); //gives relative path of the sites default skin folder
echo Mage::getBaseURL(); //gives relative path of the site
echo Mage::getURL();...
read more
