Monthly Archives: January 2012

Magento Transactional Emails

Magento Provide Transitional emails which will allow to create or customize our won email template
Some of the Template variable which we can used in our customization or which are widely used and some magento provide by default

– For registration:
{{var customer}}

{{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}}

{{var customer.store.group.name}}

– 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

– Depend Condition

{{depend order.getIsNotVirtual()}}

{{/depend}}

{{depend salable}}

{{/depend}}

– If Condition

{{if order.getIsNotVirtual()}}

{{else}}

{{/if}}

(else is optional)

– Skin

{{skin url=”‘}}

– Store

{{store url=””}}

– 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}}

Magento Layout Elements

Layout Elements Which magento generally used in there XML
label: It helps the label of the handle which is shown as a descriptive reference in some areas of the admin panel.
reference: It is used to link an already defined block in any layout XML. To add any child block to an existing block, to modify attributes of an existing block or to perform any action on an existing block, the reference element is used to link to the existing block. The reference element must have a name attribute which refers to the existing block name.
block: It is used to define a new block. This element is usually defined inside a reference element when we want to create a new block. The block element must have a name attribute, which is a unique identifier of the block in the layout and a type attribute, which defines the block class name. If the block is of type or subtype of core/template, it can also have the template attribute which defines the actual phtml template file to be used for rendering the block
remove: It is used to remove an existing block from the layout. The block to be removed is specified with the name attribute
action: It defines an action to be performed on the referenced or newly defined block. An action is simply a method of the block instance on which it is to be executed. The method attribute defines the method name in the block instance and all child elements of the action element are treated as parameters to the method. This element can be placed inside reference or block elements.
update: It will loads an existing layout handle into the current layout handle. It provides a kind of inheritance of layout handles. It must have the handle attribute, which defines the handle of the block to be included.

Magento Block Types

Magento uses some mostly commomn built-in blocks which are as follows.
core/template: It will renders a template defined by its template attribute. The majority of blocks defined in the layout are of type or subtype of core/template.
page/html: It’s a subtype of core/template and defines the root block. All other blocks are child blocks of this block.
page/html_head: It will help the HTML head section of the page which contains elements for including JavaScript, CSS etc.
page/html_header: It will help the header part of the page which contains the site logo, top links, etc.
page/template_links: It is used to create a list of links. Links visible in the footer and header area use this block type.
core/text_list: This will allow Some blocks like content, left, right etc. are of type core/text_list. When these blocks are rendered, all their child blocks are rendered automatically without the need to call the getChildHtml() method.
page/html_wrapper: It is used to create a wrapper block which renders its child blocks inside an HTML tag set by the action setHtmlTagName. The default tag is

if no element is set.
page/html_breadcrumbs: It will help to define breadcrumbs on the page.
page/html_footer: It will help to define footer area of page which contains footer links, copyright message and other static links
core/messages: It will help to renders error/success/notice messages.
page/switch: It will help to used for the language or store switcher.Note:There are many more but this are commonly used

Magento How to Remove the Block through XML

Basically there are two ways to remove blocks in layout XML:

by using: <remove name=”” />

by using: <action method=”unsetChild”>

 

Both are important to understand

<remove name=”” /> will operate on a global context, after all the layouts are processed which means that it will remove the named layout block completely, regardless of which layout handle added it.

 

<action method=”unsetChild”> operates on a localized context, specifically, in the context where you use it. So, if you want to remove a specific block from a specific layout handle and possibly insert it at another position or layout handle, you need to use this approach.

 

Let us understand with example

Use remove

<default>

<!– remove the language and store switcher and footer links blocks, we won’t use them –>

<remove name=”top.menu” />

<remove name=”footer_links” />

</default>

 

Use unsetChild to move or rearrange blocks in your layout:

<default>

<!– move the breadcrumb block from the top.bar child block back to the template root –>

<reference name=”top.bar”>

<action method=”unsetChild”><name>breadcrumbs</name></action>

</reference>

 

<reference name=”root”>

<block type=”page/html_breadcrumbs” name=”breadcrumbs” as=”breadcrumbs”/>

</reference>

</default>

Magento Add product on home page

There are numerous ways to put products on your home pageNew products on home page{{block type=”catalog/product_new” name=”home.catalog.product.new” alias=”product_homepage” template=”catalog/product/new.phtml”}}New products on home page through xml<reference name=”content”>

    <block type=”catalog/product_new” template=”catalog/product/new.phtml”>

        <action method=”setProductsCount”><count>5</count></action>

        <action method=”addColumnCountLayoutDepend”><layout>empty</layout><count>6</count></action>

        <action method=”addColumnCountLayoutDepend”><layout>one_column</layout><count>5</count></action>

        <action method=”addColumnCountLayoutDepend”><layout>two_columns_left</layout><count>4</count></action>

        <action method=”addColumnCountLayoutDepend”><layout>two_columns_right</layout><count>4</count></action>

        <action method=”addColumnCountLayoutDepend”><layout>three_columns</layout><count>3</count></action>

    </block>

</reference>All products on home page

{{block type=”catalog/product_list” name=”home.catalog.product.list” alias=”products_homepage” template=”catalog/product/list.phtml”}}

All products from one categroy

{{block type=”catalog/product_list” name=”home.catalog.product.list” alias=”products_homepage” category_id=”4″ template=”catalog/product/list.phtml”}}


Magento add special character while importing Customer Data

Magento doesnot allow special Character for importing customer data generally
For Example In the Dutch translation the special characters do not (always) show up properly. If we have to import some data like sandéép through csv of magento import it will shows error
so best practice is
Go to .htaccess file and remove # from
AddDefaultCharset UTF-8
and
open the your csv file in .txt format and Save As under UTF-8 and then import the data in magento
Your special character will also get import in magento admin without any error

Magento display the custom attribute value in Frontend

Add an attribute from magento admin and that attribute should belong to corect attribute set

Then edit the template file either view.phtml or list.phtml

For example we are using in list.phtml

app/design/frontend/default/your-theme/template/catalog/product/list.phtml

and use one of these methods to pull your attribute on the product listing page (list or grid view):

<?php foreach ($_productCollection as $_product): ?>

<!– these are regular text attributes –>

<?php echo $_product->getMyAttribute() ?>

<?php echo $_product->getAnotherCustomAttribute() ?>

<!– this is dropdown attribute –>

<?php echo $_product->getAttributeText(‘your_attribute’) ?>

<!– this is a boolean attribute –>

<?php echo $_product->getMyAttributeName() ? “Yes” : “No” ?>

<?php endforeach?>

Magento calling folder path

Magento uses its own structure to call the Particular file from specific folder

For example if we want to call the the .wsdl file which is stored in the app/modulename/etc/wsdl/your.wsdl
so we will write the code in our php file like this
 public function __construct()
{
$this->_yourWsdl = Mage::getModuleDir(‘etc’, ‘Mage_ Modulename’)  . DS . ‘wsdl’ . DS . ‘ Modulename’
. DS . ‘your .wsdl’;
}
Where 
your.wsdl is the file which is stored in the app/modulename/etc/wsdl/

Magento Add Static Block through XML or Phtml

We are assuming  that you know how to add the static block through admin.We can add the Static block in any page through two ways

Add through xml

<block type=”cms/block” name=”cms_test_block”>

<action method=”setBlockId”><block_id>test_block</block_id></action>

</block>

Through phtml files

<?php echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘ test_block’)->toHTMl(); ?>

Magento Adding new field in category for admin

Adding an Attribute in Product quite simple we can add through admin but adding a field(attribute) in category cannot be achieved through admin so here is the simple solution for adding the attribute in Category through Database.Open the phpmyadmin.Here we need to work on three tables.

  1. eav_attribute
  2. eav_entity_attribute
  3. catalog_eav_attribute
First query for the eav_attribute table
Insert into eav_attribute
`attribute_id` = ”,
`entity_type_id` = 9,
`attribute_code` = ‘new_attribute_code’,
`attribute_model` = NULL,
`backend_model` = ”,
`backend_type` = ‘text’,
`backend_table` = ”,
`frontend_model` = ”,
`frontend_input` = ‘textarea’,
`frontend_label` = ‘New Attribute Name’,
`frontend_class` = NULL,
`source_model` = ”,
`is_required` = 0,
`is_user_defined` = 0,
`default_value` = ”,
`is_unique` = 0,
`note` = ”After insert this query it will generate attribute id that attribute id we will be using in our second query for me it generated the 963 so we are using that in second query

Second query for the  eav_entity_attribute table
Insert into eav_entity_attribute
`entity_attribute_id` = ”,
`entity_type_id` = 9,
`attribute_set_id` = 12,
`attribute_group_id` = 7,
`attribute_id` = 963, [attribute_id you get from first table insert]
`sort_order` = 8

Third query for the  eav_entity_attribute table
Insert into eav_entity_attribute
`attribute_id` = 963, [attribute_id you get from first table insert]
`frontend_input_renderer` = NULL,
`is_global` = 0
`is_visible` = 1,
`is_searchable` = 0,
`is_filterable` = 0,
`is_comparable` = 0,
`is_visible_on_front` = 0,
`is_html_allowed_on_front` = 0,
`is_used_for_price_rules` = 1,
`is_filterable_in_search` = 0,
`used_in_product_listing` = 0,
`used_for_sort_by` = 0,
`is_configurable` = 1,
`apply_to` = ”,
`is_visible_in_advanced_search` = 0,
`position` = 1,
`is_wysiwyg_enabled` = 0

Now You can check that attribute will be get inserted in the category

Note: We can add the Browse button image in category with the same query only need to change the   `backend_type`

Magento How to get the Brand list in Product page

Add an attribute from magento admin and that attribute should belong to corect attribute set

Then edit the template file either view.phtml or list.phtml

For example we are using in list.phtml

app/design/frontend/default/your-theme/template/catalog/product/list.phtml

and use one of these methods to pull your attribute on the product listing page (list or grid view):

<?php foreach ($_productCollection as $_product): ?>

<!– these are regular text attributes –>

<?php echo $_product->getMyAttribute() ?>

<?php echo $_product->getAnotherCustomAttribute() ?>

<!– this is dropdown attribute –>

<?php echo $_product->getAttributeText(‘your_attribute’) ?>

<!– this is a boolean attribute –>

<?php echo $_product->getMyAttributeName() ? “Yes” : “No” ?>

<?php endforeach?>

Magento get the current URL and Name of category

Magneto registry make it easier to get the current category name and category url
The registry object we are interested in is ‘current_category’ and utilise the registry call getName() to create call to retrieve the needed information.Category Name: Mage::registry(‘current_category’)->getName();

Category URL: Mage::registry(‘current_category’)->getUrl();

Adding review in Product page

1) Add form data to catalog.xml & view.phtml The first thing to do is to add the review blocks to

the correct XML reference in catalog.xml which is in

app > design > frontend > default > yourtheme > layout

you’ll see the <reference name=”content”> for the catalog_product_view class.

Inside this reference add the following code:

<block type=”review/product_view_list” name=”product.info.product_additional_data” as=”product_review” template=”review/product/view/list.phtml”>

<block type=”review/form” name=”product.review.form” as=”review_form”/>

</block>

Now the XML is set up, you just need to echo it on the product page in

app > design > frontend > default > yourtheme > template > catalog > product > view.phtml

<?php echo $this->getChildHtml(‘product_review’) ?>

2) Add Ratings to Reviews Star ratings on reviews are not enabled as standard, but should be utilised because they give customers a quick reference to the feedback of the product, without having to read the whole review.

 

To enable this simply go to Catalog > Reviews & Ratings > Manage Ratings

 

From here simply go into each rating that you want to enable, find Rating Visibility and click on the store view that you want to enable it for, then Save.At this stage you’ll need to apply some CSS styling to improve

the appearance of the summary and form. Below is an example on a site I worked on recently.

Hope this will help hope

Getting the reviews page URL for a product in the product page sidebar

Adding the Review url in your customization page

For example

Since it is a new block that is needed, you need new template file.

Add:

app/design/frontend/base/default/template/review/sidebar.phtml

Enter into it something like:

<div>

<div>

<strong><span>Reviews</span></strong>

</div>

<div>

<p><a href=”<?php echo $this->getNewReview($this->getProductId()) ?>”>NewReview</a></p>

</div>

</div>

Edit app/code/core/Mage/Review/Block/Product/View/List.php and add the helper URL function before the class closing brace:

public function getNewReview($id)

{

return Mage::getUrl(‘review/product/list’, array(‘id’=> $id));

}

Now sort out your layout XML add to the reference left block or reference right, whatever, for the product page directives:

<block type=”review/product_view_list” name=”review_sidebar” as=”newreview” template=”review/sidebar.phtml”/>

That gets you the link you wanted, in a nice sidebar block with some stuff you can CSS to. Copy it over to your main theme. You can take what you want from the list.phtml template I pointed you towards earlier

and do your own code to summarize your reviews or say something else if you have no reviews.

Note :You can use this code to add in the Product page also to add the Review button image

Hope this will help you

Remove Price from Custom Options

IF wana remove the price change indicators on the options of configurable products. The product shows the configurable options as a dropdown box at the moment.:“Large +£20.00” and If want to just show the option name “Large”You can easily remove by overriding the JS
Open the template file
catalog/product/view/type/options/configurable.phtml

Find the
var spConfig = new Product.Config(getJsonConfig() ?>);

Replace with
Product.Config.prototype.formatPrice = function(){
return ”;
}
var spConfig = new Product.Config(getJsonConfig() ?>);

Hope this will help you

Add New Indian Currency symbol

To Add New Rupee symbol in magento currency follow below steps:1)Copy the below url in your browser and add the css in your css folder
http://cdn.webrupee.com/font
same with js
http://cdn.webrupee.com/js

2) Add the css and js in Page.xml

3) Add below code in root.xml
path of file: lib/Zend/Locale/Data/root.xml open file in wordpad
find:
currency type=”INR”
replace symbol Rs with: amp#x20B9; (use & for amp).

4. After this refersh cache from admin and manually delete cache from front var/cache folder.
Now in front end it will display new India rupee symbol.

Hope this will help you

Magento Certified Developer Exam

Register for a Magento Certified Developer Exam today and Find the Test center 
Magento Launches Certified Developer Study Guides and  Certified Developer Study Guides Plus for preparing for the Certification exam.The study guide will help to go through the topic related to certification exam. Down load the PDF and explore through Topic.PDF can be downloaded under Resource Tab at the bottom
Hope this will help you