Wednesday, October 19

How to add contact us link on the top menu bar in Magento

Step 1: Open [magento_root]/app/design/frontend/default/default/template/catalog/navigation/top.phtml in your favorite editor

Step 2: After this line:



Add a line like this:
<li><a href="<?php echo $this->getUrl('contacts')?>"><?php echo $this->__('Contact Us') ?></a></li>

Step 3: Click the Magento cache; System > Cache Management.

Hope it Helps... thanks....

How to add custom field in Magento Contact us Form

Step 1: Open [magento_root]/app/design/frontend/default/default/template/contacts/form.phtml in your favorite editor

Step 2: Copy & paste an existing form field code on this script and rename the field to create new field. For example:

This is the default code in the file:
<div class="input-box">
<label for="email"><?php echo Mage::helper('contacts')->__('Email') ?> <span class="required">*</span></label>
<input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="required-entry input-text validate-email" type="text" />
</div>
<div class="clear"></div>
<div class="input-box">
<label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
<input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text" type="text" />
</div>

This is how the modified code will look like:
<div class="input-box">
<label for="email"><?php echo Mage::helper('contacts')->__('Email') ?> <span class="required">*</span></label>
<input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="required-entry input-text validate-email" type="text" />
</div>
<div class="clear"></div>
<span style="background-color: rgb(255, 255, 0);"><!-- New Field Code-->
<div class="input-box">
<label for="website"><?php echo Mage::helper('contacts')->__('Website') ?></label>
<input name="website" id="website" title="<?php echo Mage::helper('contacts')->__('Website') ?>" value="" class="input-text" type="text" />
</div>
<div class="clear"></div>
<!-- End New Field Code--></span>
<div class="input-box">
<label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
<input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text" type="text" />
</div>

Step 3: Now go to, System > Transaction Emails.

Step 4: Click ‘Add New Template’

Step 5: In the ‘Load default template’ section, select ‘Contact Form’ template and click ‘Load Template’

Step 6: The template content will look like this:

Name: {{var data.name}}
E-mail: {{var data.email}}
Telephone: {{var data.telephone}}

Comment: {{var data.comment}}

Step 7: Add your new field in this content like this:

Name: {{var data.name}}
E-mail: {{var data.email}}
Website: {{var data.website}}
Telephone: {{var data.telephone}}

Comment: {{var data.comment}}

Step 8: Enter a new ‘Template Name’ and click ‘Save template’

Step 9: Now go to, System > Configuration > Contacts

Step 10: Click the ‘Email Options’ section on this page and select the new template that you just created.

Step 11: Click ‘Save Config’

Hope it Helps.... Thanks.......

How to enable contact form in Magento

Here is the step by step procedure to enable contact form from magento back-end

Step 1. System > Configuration > Contacts

Step 2. Click the ‘Contact Us’ section on this page. Set ‘Enable Contact Us’ to ‘Yes’

Step 3. Click the ‘Email Options’ section on the same page, just under it. Set the email
address to which the comments should come, subject and email template.

Step 4. Click ‘Save Config’

Hope it Helps.... Thanks.....

Thursday, October 13

How to Access Magento session from external site

there is a simple way to access the running Magento session from outside the installation folder. The magic happens here:

$mageFilename = realpath(‘mymagentoshop/app/Mage.php’);
require_once( $mageFilename );
umask(0);
 
Mage::app();
Mage::getSingleton(‘core/session’, array(‘name’ => ‘frontend’));
$session = Mage::getSingleton(‘customer/session’);
 
if($session->isLoggedIn())
   echo ‘LOGGED IN’;
else
   echo ‘NOT LOGGED IN’;

The line 5 presents the Magento initialization, and from there you can call any Magento core API functions and procedures. In order for session to work properly (as one) in both sites, you need to retrieve it, and that is exactly what is done on the lines 6 (for the core session) and 7 (for the customer session). Later in our example we’re checking whether the customer is logged in or not, but you can do whatever you want!

Oh yes, on more thing – Use SID on Frontend setting in the Magento admin (System -> Configuration -> Web -> Session Validation Settings) MUST be set to YES, otherwise it won’t work.

Hope it Helps.... Thanks....

Tuesday, October 11

How to Add Custom Tabs to Magento Customer Edit page in backend

Magento Provides the manage customers feature to list and edit the customers information.
The Customer edit page in the admin panel gives details about the customers account information,address,orders etc.

In some scenarios we may need to show our custom module contents related to the customer in a additional tab. To achieve this functionality we need to create a custom module and add our tab.

Step 1: We start with our config.xml file. In this file we are specifying an adminhtml xml layout file and a Block class for our custom module.

app/code/local/Mydons/etc/config.xml
<config>
   <modules>
       <Mydons_Customertab>
           <version>0.1.0</version>
       </Mydons_Customertab>
   </modules>
 <adminhtml>
    <layout>
           <updates>
               <customertab>
                  <file>customertab.xml</file>
               </customertab>
           </updates>
       </layout>
   </adminhtml>
   <global>
       <blocks>
           <customertab>
               <class>Mydons_Customertab_Block</class>
           </customertab>
       </blocks>
 </global>
</config>

Step 2: We need to create an adminhtml block class to show our new custom tab. This class
should extend the Mage_Adminhtml_Block_Template class and implement Mage_Adminhtml_Block_Widget_Tab_Interface to
get the tab related methods.

app/code/local/Mydons/Customertab/Block/Adminhtml/Customer/Edit/Tab/Action.php
<?php
 
/**
 * Adminhtml customer action tab
 *
 */
class Mydons_Customertab_Block_Adminhtml_Customer_Edit_Tab_Action
 extends Mage_Adminhtml_Block_Template
    implements Mage_Adminhtml_Block_Widget_Tab_Interface
{
 
    public function __construct()
    {
        $this->setTemplate('customertab/action.phtml');
 
    }
 
    public function getCustomtabInfo(){
 
        $customer = Mage::registry('current_customer');
        $customtab='My Custom tab Action Contents Here';
        return $customtab;
        }
 
    /**
     * Return Tab label
     *
     * @return string
     */
    public function getTabLabel()
    {
        return $this->__('Action Center');
    }
 
    /**
     * Return Tab title
     *
     * @return string
     */
    public function getTabTitle()
    {
        return $this->__('Action Tab');
    }
 
    /**
     * Can show tab in tabs
     *
     * @return boolean
     */
    public function canShowTab()
    {
        $customer = Mage::registry('current_customer');
        return (bool)$customer->getId();
    }
 
    /**
     * Tab is hidden
     *
     * @return boolean
     */
    public function isHidden()
    {
        return false;
    }
 
     /**
     * Defines after which tab, this tab should be rendered
     *
     * @return string
     */
    public function getAfter()
    {
        return 'tags';
    }
 
}
?>

Step 3: Now we need to create a layout file for our adminhtml.

app/design/adminhtml/default/default/layout/customertab.xml
<layout version="0.1.0">
    <adminhtml_customer_edit>
        <reference name="customer_edit_tabs">
            <action method="addTab"><name>customer_edit_tab_action</name><block>customertab/adminhtml_customer_edit_tab_action</block></action>
        </reference>
   </adminhtml_customer_edit>
</layout>

Step 4: After creating the layout create adminthtml template file as shown below

app/design/adminhtml/default/default/template/customertab/action.phtml
<div id="customer_info_tabs_customer_edit_tab_action_content">
<div class="entry-edit">
<div class="entry-edit-head">
<h4 class="icon-head head-edit-form fieldset-legend">Action Tab</h4>
</div>
<div id="group_fields4" class="fieldset fieldset-wide">
<div class="hor-scroll">
<table class="form-list" cellspacing="0">
<tbody>
<tr>
<td>Custom Action Tab Contents Here</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>

Step 5: Finally we need to activate our module Activation file
app/etc/modules/Mydons_Customertab.xml.
<config>
    <modules>
        <Mydons_Customertab>
            <active>true</active>
            <codepool>local</codepool>
        </Mydons_Customertab>
    </modules>
</config> 

Our new tab will Display as shown below

Hope it helps... Thanks

Saturday, October 1

How to Add Confirmation email field while Register in Magento

The following method allows you to add confirmation email address field in your customer registration or newsletter page.
Create a javascript file called validation.js under "js/email/validation.js"

Validation.addAllThese([

    ['validate-cemail', 'Please make sure your emails match.', function(v) {
                var conf = $('confirmation') ? $('confirmation') : $$('.validate-cemail')[0];
                var pass = false;
  var confirm;
                if ($('email')) {
                    pass = $('email');
                }
  confirm =conf.value;
  if(!confirm && $('email2'))
  {
  confirm = $('email2').value;
  }
                return (pass.value == confirm);
            }],
]); 


Add the new js file into your customer.xml file

<reference name="head">
    <action method="addJs"><script>email/validation.js</script></action>
</reference> 

On the register form add a new field to contain the email confirmation field "template/customer/form/register.phtml".

<label class="required" for="email_address"><em>*</em>CONFIRM EMAIL</label>
<div class="input-box"> <input class="input-text required-entry validate-cemail" title="Email Address" value="" id="email2" name="email2" type="text">
</div>

Hope it Helps.. Thanks...