Email Variables for Magento

Email Templates

When setting up a store you will need to either copy all the existing ones into new transactional emails, alter them to match your store then associate them with email events or edit the templates in your Magento installation files.

There are approximately 35 default email templates that need to be updated. Unfortunately you really do need to update them as these default emails are filled with ‘Demo Store’ comments and other phrases that you will not want on your live store.

You can find suggestions on the various ways to manage this process in the this forum thread

Email Variables

Following is a compiled list of variables you can use in e-mail templates. NOT VERIFIED; TEST FIRST!

Please add or edit as necessary.

- For registration:

{{var customer}} Will print out all customer information

{{var customer.ID}}

{{var customer.email}}

{{var customer.firstname}}

{{var customer.lastname}}

{{var customer.name}}

{{var customer.password}}

{{var customer.created_in}} Store Name

{{var customer.dob}} Date of Birth

{{var customer.password_hash}}

{{var customer.prefix}}

{{var customer.middlename}} Initial

{{var customer.suffix}}

{{var customer.group_id}}

{{var customer.taxvat}}

{{var customer.store.name}} What store they registered with (On Demo store this will display as ‘English’

{{var customer.store.group.name}} The actual Store’s name (not the Store View’s)

- To subscribe/unsubscribe newsletter:

{{var subscriber.getConfirmationLink()}}

{{var subscriber.getUnsubscriptionLink()}}

{{var subscriber.email}}

- Send to a friend:

{{var product_image}}

{{var name}} Recipient’s Name

{{var email}} Recipient’s Email

{{var product_name}} Product Name

{{var product_url}} Product Url

{{var message}} Message Text

{{var sender_name}} Sender’s Name

{{var sender_email}} Sender’s Email

{{var product_image}} Product Image

- Block

{{block type='core/template' area='frontend' template='email/order/shipment/track.phtml' shipment=$shipment order=$order}}

- Depend Condition

{{depend order.getIsNotVirtual()}}

{{/depend}}

{{depend salable}}

{{/depend}}

- If Condition

{{if order.getIsNotVirtual()}}

{{else}}

{{/if}}

(else is optional)

- Layout

Layout “handles” contain small code blocks for reuse. Handles are stored in a different location than regular templates. This location is found in the layout configuration file for the specific module you are working on. For example, the “sales_email_order_invoice_items” handle would be found in the sales.xml configuration file found in:

/app/design/frontend/default/layout/sales.xml

You will find the element:

  <sales_email_order_items>
      <block type="sales/order_email_items" name="items" template="email/order/items.phtml">
          <action method="addItemRender"><type>default</type><block>sales/order_email_items_order_default</block><template>email/order/items/order/default.phtml</template></action>
          <action method="addItemRender"><type>grouped</type><block>sales/order_email_items_order_grouped</block><template>email/order/items/order/default.phtml</template></action>
      </block>
  </sales_email_order_items>

From there we can find where the template is being pulled from, and how it is being constructed. In this case:

/app/design/frontend/default/{your_theme}/template/email/order/items.phtml

is the parent template with the default template being used:

/app/design/frontend/default/{your_theme}/template/email/order/items/order/default.phtml

{{layout area="frontend" handle="sales_email_order_invoice_items" invoice=$invoice order=$order}}

{{layout handle="sales_email_order_items" order=$order}}

{{layout handle="sales_email_order_creditmemo_items" creditmemo=$creditmemo order=$order}}

{{layout handle="sales_email_order_shipment_items" shipment=$shipment order=$order}}

- Skin

{{skin url="'}}

- Store

{{store url=""}}

name

- New order : Shipping Address

{{var order.getShippingAddress().format('html')}}

Items of the shipping address :

{{var order.getShippingAddress().getName()}} Get the first and last name

{{var order.getShippingAddress().getPrefix()}}

{{var order.getShippingAddress().getFirstName()}}

{{var order.getShippingAddress().getMiddleName()}}

{{var order.getShippingAddress().getLastName()}}

{{var order.getShippingAddress().getSuffix()}}

{{var order.getShippingAddress().getStreet1()}}

{{var order.getShippingAddress().getStreet2()}}

{{var order.getShippingAddress().getCity()}}

{{var order.getShippingAddress().getRegion()}}

{{var order.getShippingAddress().getPostcode()}}

{{var order.getShippingAddress().getCountry()}} Get the country’s ID

{{var order.getShippingAddress().getCountryModel().getName()}} Get the country’s full name

{{var order.getShippingAddress().getRegion()}}

{{var order.getShippingAddress().getTelephone()}}

- Other

{{var addAllLink}}

{{var alertGrid}}

{{var billingAddress.format('html')}}

{{var checkoutType}}

{{var comment}}

{{var creditmemo.id}}

{{var creditmemo.increment_id}}

{{var data.comment}}

{{var data.email}}

{{var data.name}}

{{var data.telephone}}

{{var dateAndTime}}

{{var invoice.id}}

{{var invoice.increment_id}}

{{var invoice.created_at}}

{{var items}}

{{var items_html}}

{{var message}}

{{var name}}

{{var order.customer_email}}

{{var order.getBillingAddress().format('html')}}

{{var order.getBillingAddress().getName()}}

{{var order.getCreatedAtFormated('long')}}

{{var order.getCustomerName()}}

{{var order.getCustomerFirstname()}}

{{var order.getCustomerLastname()}}

{{var order.getEmailCustomerNote()}} Currently unknwon how to test this variable for being set/empty

{{var order.getShippingDescription()}}

{{var order.getStatusLabel()}}

{{var order.getStoreGroupName()}}

{{var order.id}}

{{var order.increment_id}}

{{var password}}

{{var payment_html}}

{{var paymentMethod}}

{{var product_name}}

{{var product_url}}

{{var reason}} Reason for payment failure

{{var shipment.increment_id}}

{{var shippingAddress.format('html')}}

{{var shippingMethod}}

{{var total}}

{{var user.name}}

{{var viewOnSiteLink}}

{{var warnings}}

{{var billing.name}} Uses the fullname from billing information (to prevent e-mail being sent to ‘Dear Guest, etc’.

Email Templates

When setting up a store you will need to either copy all the existing ones into new transactional emails, alter them to match your store then associate them with email events or edit the templates in your Magento installation files.

There are approximately 35 default email templates that need to be updated. Unfortunately you really do need to update them as these default emails are filled with ‘Demo Store’ comments and other phrases that you will not want on your live store.

You can find suggestions on the various ways to manage this process in the this forum thread

Email Variables

Following is a compiled list of variables you can use in e-mail templates. NOT VERIFIED; TEST FIRST!

Please add or edit as necessary.

- For registration:

{{var customer}} Will print out all customer information

{{var customer.ID}}

{{var customer.email}}

{{var customer.firstname}}

{{var customer.lastname}}

{{var customer.name}}

{{var customer.password}}

{{var customer.created_in}} Store Name

{{var customer.dob}} Date of Birth

{{var customer.password_hash}}

{{var customer.prefix}}

{{var customer.middlename}} Initial

{{var customer.suffix}}

{{var customer.group_id}}

{{var customer.taxvat}}

{{var customer.store.name}} What store they registered with (On Demo store this will display as ‘English’

{{var customer.store.group.name}} The actual Store’s name (not the Store View’s)

- To subscribe/unsubscribe newsletter:

{{var subscriber.getConfirmationLink()}}

{{var subscriber.getUnsubscriptionLink()}}

{{var subscriber.email}}

- Send to a friend:

{{var product_image}}

{{var name}} Recipient’s Name

{{var email}} Recipient’s Email

{{var product_name}} Product Name

{{var product_url}} Product Url

{{var message}} Message Text

{{var sender_name}} Sender’s Name

{{var sender_email}} Sender’s Email

{{var product_image}} Product Image

- Block

{{block type='core/template' area='frontend' template='email/order/shipment/track.phtml' shipment=$shipment order=$order}}

- Depend Condition

{{depend order.getIsNotVirtual()}}

{{/depend}}

{{depend salable}}

{{/depend}}

- If Condition

{{if order.getIsNotVirtual()}}

{{else}}

{{/if}}

(else is optional)

- Layout

Layout “handles” contain small code blocks for reuse. Handles are stored in a different location than regular templates. This location is found in the layout configuration file for the specific module you are working on. For example, the “sales_email_order_invoice_items” handle would be found in the sales.xml configuration file found in:

/app/design/frontend/default/layout/sales.xml

You will find the element:

  <sales_email_order_items>
      <block type="sales/order_email_items" name="items" template="email/order/items.phtml">
          <action method="addItemRender"><type>default</type><block>sales/order_email_items_order_default</block><template>email/order/items/order/default.phtml</template></action>
          <action method="addItemRender"><type>grouped</type><block>sales/order_email_items_order_grouped</block><template>email/order/items/order/default.phtml</template></action>
      </block>
  </sales_email_order_items>

From there we can find where the template is being pulled from, and how it is being constructed. In this case:

/app/design/frontend/default/{your_theme}/template/email/order/items.phtml

is the parent template with the default template being used:

/app/design/frontend/default/{your_theme}/template/email/order/items/order/default.phtml

{{layout area="frontend" handle="sales_email_order_invoice_items" invoice=$invoice order=$order}}

{{layout handle="sales_email_order_items" order=$order}}

{{layout handle="sales_email_order_creditmemo_items" creditmemo=$creditmemo order=$order}}

{{layout handle="sales_email_order_shipment_items" shipment=$shipment order=$order}}

- Skin

{{skin url="'}}

- Store

{{store url=""}}

name

- New order : Shipping Address

{{var order.getShippingAddress().format('html')}}

Items of the shipping address :

{{var order.getShippingAddress().getName()}} Get the first and last name

{{var order.getShippingAddress().getPrefix()}}

{{var order.getShippingAddress().getFirstName()}}

{{var order.getShippingAddress().getMiddleName()}}

{{var order.getShippingAddress().getLastName()}}

{{var order.getShippingAddress().getSuffix()}}

{{var order.getShippingAddress().getStreet1()}}

{{var order.getShippingAddress().getStreet2()}}

{{var order.getShippingAddress().getCity()}}

{{var order.getShippingAddress().getRegion()}}

{{var order.getShippingAddress().getPostcode()}}

{{var order.getShippingAddress().getCountry()}} Get the country’s ID

{{var order.getShippingAddress().getCountryModel().getName()}} Get the country’s full name

{{var order.getShippingAddress().getRegion()}}

{{var order.getShippingAddress().getTelephone()}}

- Other

{{var addAllLink}}

{{var alertGrid}}

{{var billingAddress.format('html')}}

{{var checkoutType}}

{{var comment}}

{{var creditmemo.id}}

{{var creditmemo.increment_id}}

{{var data.comment}}

{{var data.email}}

{{var data.name}}

{{var data.telephone}}

{{var dateAndTime}}

{{var invoice.id}}

{{var invoice.increment_id}}

{{var invoice.created_at}}

{{var items}}

{{var items_html}}

{{var message}}

{{var name}}

{{var order.customer_email}}

{{var order.getBillingAddress().format('html')}}

{{var order.getBillingAddress().getName()}}

{{var order.getCreatedAtFormated('long')}}

{{var order.getCustomerName()}}

{{var order.getCustomerFirstname()}}

{{var order.getCustomerLastname()}}

{{var order.getEmailCustomerNote()}} Currently unknwon how to test this variable for being set/empty

{{var order.getShippingDescription()}}

{{var order.getStatusLabel()}}

{{var order.getStoreGroupName()}}

{{var order.id}}

{{var order.increment_id}}

{{var password}}

{{var payment_html}}

{{var paymentMethod}}

{{var product_name}}

{{var product_url}}

{{var reason}} Reason for payment failure

{{var shipment.increment_id}}

{{var shippingAddress.format('html')}}

{{var shippingMethod}}

{{var total}}

{{var user.name}}

{{var viewOnSiteLink}}

{{var warnings}}

{{var billing.name}} Uses the fullname from billing information (to prevent e-mail being sent to ‘Dear Guest, etc’.

Deep links to add your Magento products straight to cart

I was asked recently how do you add a product straight to your Magento cart from a link that is external to your Magento store. It turns out the answer is quite straight forward BUT there are some things you need to consider.

To add a simple product to your cart use this link http://parenttechnology.com/checkout/cart/add?product=85&qty=1

  • obviously yourwebsite.co.uk is the URL to your Magento store
  • product=85 replace 85 with the Magento ID of the product you want to be placed in the cart. You can find this id in the admin – > Catalog > Manage Products the ID is contained in the far left column.
  • qty=1 the 1 represents the quantity of products you want added to the basket. If you want more than 1 increase the number here.

This allow you to directly add simple products to a shopping basket. You may want to do this from a blog, an email or even an advert campaign.

Something to consider

1. If the person adding this to the basket has never been to your website before then they will be presented with the ‘Cookies’ page. You may not spot this error as the chances are you have a cookie on your machine for past test orders you have created but first time visitors will see this using the link created. You need to turn off the ‘Redirect to Cookies Page’ if a cookie is not detected. To do that go to > Configuration > Web > Browser Capabilty Detection > and select  ’No’ in the option ‘Redirect to CMS-page if Cookies are Disabled’

Add Sample Product on Magento Product Pages

There are many old tutorials which are out of date and simply do not work. We have tested this solution with Magento version 1.5 and 1.7. Free sample products or free tester products are ideal for e-commerce websites that require giving their customers for example tester materials or sample perfumes for instance. You can restrict the amount of free sample products you want give out to your clients because you do not want people to have let’s just say a 100 free sample products. instead this tutorial will restrict the sample product to 5 but you can edit the code you change it to whatever you feel is the right amount. 1. Firstly you will need to create a file called getSample.php in the root of your Magento installation folder and populate it with the following code.   001 <?php 002 003 ini_set('display_errors', 1); 004 error_reporting(E_ALL); 005 006 //print_r($_POST); 007 008 require_once 'app/Mage.php'; 009 Mage::app(); 010 011 012 013 Mage::getSingleton("core/session", array("name" => "frontend")); 014 Mage::getSingleton('core/session')->setSampleError(""); 015 // Store users session 016 $session = Mage::getSingleton("customer/session"); 017 018 //Store cart items 019 $totalNumOfCartItem = Mage::getModel('checkout/cart')->getItemsQty(); 020 021 //Store cart items 022 $theitems = Mage::getModel('checkout/cart')->getItems(); 023 024 $thecount = 0; 025 026 foreach($theitems as $ti){ 027 028 $thename = $ti['name']; 029 030 $test = strpos($thename,'Free Sample'); 031 032 if($test !== false){ 033 $thecount = $thecount+1; 034 } 035 036 } 037 038 if(isset($_POST['name'])){ 039 $name = $_POST['name']; 040 041 $id = $_POST['id']; 042 if(isset($_POST['simpleid']) && !empty($_POST['simpleid'])){ 043 $simpleid = $_POST['simpleid']; 044 } 045 } 046 if(isset($_GET['name'])){ 047 $name = $_GET['name']; 048 if(isset($_GET['simpleid']) && !empty($_GET['simpleid'])){ 049 $simpleid = $_GET['simpleid']; 050 } 051 $id = $_GET['id']; 052 } 053 054 // retrict shopping cart to only allow 5 samples 055 if ($totalNumOfCartItem <= 4) 056 { 057 $theproduct = Mage::getModel('catalog/product')->load($id); 058 059 if($simpleid){ 060 $thesimple = Mage::getModel('catalog/product')->load($simpleid); 061 } 062 063 if($thecount < 2){ 064 065 // instatiate Product 066 $product = Mage::getModel('catalog/product'); 067 if($simpleid){ 068 $product->setSku($thesimple->getSku()."*".rand()); 069 } else { 070 $product->setSku($theproduct->getSku()."*".rand()); 071 } 072 $product->setName("Sample of ".$name); 073 // $product->setDescription("Sample of ".$name); 074 $product->setShortDescription($name." - Sample"); 075 $product->setPrice(00.00); 076 $product->setTypeId('simple'); 077 078 $product->setImageUrl($theproduct->getImageUrl()); // set the images from the original product 079 $product->setThumbnailUrl($theproduct->getImageUrl()); 080 $product->setImage($theproduct->getSmallImage()); 081 $product->setMediaGallery (array('images'=>array (), 'values'=>array ())); 082 $product->addImageToMediaGallery($_SERVER['DOCUMENT_ROOT']."/media/catalog/product".$theproduct->getSmallImage(), array('image','small_image','thumbnail'), false, false); 083 $product->setAttributeSetId(9); // need to look this up 084 $product->setCategoryIds("15"); // need to look these up 085 $product->setWeight(21212121.21); 086 $product->setTaxClassId(2); // taxable goods 087 $product->setVisibility(1); // catalog, search 088 $product->setStatus(1); // enabled 089 // assign product to the default website 090 $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); 091 092 093 // get product's general info such price, status, description 094 095 $stockData = $product->getStockData(); 096 097 // update stock data using new data 098 $stockData['qty'] = 1; 099 $stockData['is_in_stock'] = 1; 100 $stockData['manage_stock'] = 1; 101 $stockData['max_sale_qty'] = 5; 102 103 // then set product's stock data to update 104 $product->setStockData($stockData); 105 //die(); 106 107 // call save() method to save your product with updated data 108 $product->save(); 109 110 111 header("Location: /checkout/cart/add/product/".$product->getId()."/"); 112 } 113 } 114 115 else 116 { 117 Mage::getSingleton('checkout/session')->addError("You are only allowed a maximum of 5 sample products"); 118 119 header("Location: /checkout/cart"); 120 } 121 ?> The above code is simply the function which will create sample products for you on the fly. Also not that in this example we have assigned each sample product with a ridiculous weight because the client offered the sample product and the shipping of the sample products for free meaning we had to create a table rate for the shipping method which did not interfere with the other shipping logic so that anything that exceeds 21212121 will have free shipping. 2. Next you will need to create a button where you want people to add a free sample product in the shopping basket. I have placed my sample button in the list.phtml and placed the button in both my list view and grid view.   1 <form action="/getSample.php" method="post"> 2 <input type="hidden" name="id" value="<?php echo $_product->getId() ?>" /> 3 <input type="hidden" name="name" value="<?php echo $this->htmlEscape($_product->getName()) ?>" /> 4 <input type="image" name="getsample" alt="Get Sample for <?php echo $this->htmlEscape($_product->getName()) ?>" src="/<?php echo $this->getSkinUrl('images/your_theme_name/sample-btn.jpg') ?>" /> 5 </form> The above will execute the getSample.php and add a sample product to your shopping basket whilst still allowing you to purchase other products from the Magento shop.

Google Optimizer on Magento: Where to start for maximum gain

Magento has Google Optimizer tools built in and so it makes sense to use them.  Google Optimizer allows you to present different content options to your prospective customers and then tracks which version converts more.  On top of this Google Optimizer has built in probability formulae that understand when a result is a ‘confident result’ rather than a random occurrence. To get a confident result you need to either have a test that is really obviously better or a decent number of transactions.  But as a rule of thumb if you are getting more than 10 transactions a day then you can benefit from using Google Optimizer.

Where to start?

If you have a lower number of transactions it makes sense to start optimizing on the pages that most people see.  This tends to be the home and checkout pages of the site. However we need not guess the best place to start when we have good data available to tell us exactly. We can find the best place to start by looking at Google Analytics.  Google Analytics should be setup using Ecommerce mode and to be tracking conversions, which is a standard part of Magento as long as you have entered the Google ID in the Google API area of Magento’s configuration settings. In Google Analytics go to ‘content’ Then top content Then set the time line for Google Analytics to show a decent length of time.  I am using 6 months in my example – just use as much data as you have since the site has been stable and not changed. On the top content screen find the right most column called $ index – the $ index is the average value for a page that a user visited before completing an Ecommerce transaction.  Ordering by the $ index will give you the most valuable pages on your site.  However you also need to click on ‘weighted sort’ to give you not only the most valuable pages but the most relevant valuable pages.  Without weighted sort you are only going to see the pages that randomly got high values because an odd buyer used them to make a big purchase.  By using weighted sort we can filter out these anomalies. On the site I am looking at for this example this gives me the following pages As you can see these are all checkout pages which are NOT part of the inbuilt Google Optimizer set of tools that Magento supplies.  Whilst I have personally run split tests here, its tricky and not something I can easily show you.  However you can optimise these pages by creating a ‘goal’ funnel and looking at the profile, but I want to cover that in another blog post. So what I am going to do is to scroll through the list until I find one of the following pages that is built into Magento to Google Optimizer test
    • Product page
    • CMS page – (this could be a Google Adwords landing page and in many of my sites these are the best pages to test as they drive a significant proportion of my revenue)
In my example site the first page I find is not the home page as I would have expected but instead a product page.  It just goes to show how important it is to look at the stats before deciding where to test. The product I can use to test is worth $102 and thus a decent sale for the site and must have a fair number of transactions to rank this highly.  So this is where I would start. I am not going to go through how to actually setup the experiment as there are plenty of good blog tutorials available – just Google “Google Optimizer for Magento” – but I wanted to show you where to test first as this will actually allow you to make the most important changes to your site first.

Site Search

Contact Us

 
 
 
Parent Technology Inc.
1535 Rosalind Rd Se
East Grand Rapids, MI 49506, USA
 
 

This email address is being protected from spambots. You need JavaScript enabled to view it.