Wednesday, May 14, 2014

Magento 1.8 Notes - III

1. Get Customer's FirstName in transactional Emails in Magento ::
    
    In transactional email template files ( order_new.html/invoice_new.html etc), the following line
   
   Hello, {{htmlescape var=$order.getCustomerFirstName()}}
   
   should give the customer first name. However, in email templates (order_new.html etc) where "Hello, {{htmlescape var=$billing.getName()}}" is used, replacing this with the above mentioned "{{htmlescape var=$order.getCustomerFirstName()}}" may give full name of the  customer. In such situations, the following method would always work.
   
   The class Mage_Sales_Model_Order is defined in app\code\core\Mage\Sales\Model\Order.php file where getCustomerName(), getCustomerFirstName() etc functions are defined. We can add our own method inside this class.
   
   public function getCustomerOnlyFirstName()
 {
   // GET Name
   $name = trim($this->getCustomerName());
 
   // Find if any Space is there within Name
   $pos = strpos($name," ");
 
   // If Space is found, extract till that Space
   if($pos !== false) 
   {
     $name = trim(substr( $name, 0, $pos ));
   }
 
   // return 
   return $name;
 }
   
   and then use the line below to get the customer's first name in email templates ( where $order variable is used ) ::
   
   Hello, {{htmlescape var=$order.getCustomerOnlyFirstName()}}

2. Include Customer IP address in New Order Email template ::
   
   To achieve this, we need to follow steps shown below --
   a. Modify /public_html/app/code/core/Mage/Sales/Model/Order.php
   b. We need to edit the function sendNewOrderEmail()
   c. We nee add a new variable 'remoteaddr' or anything of our choice and set some value to it.
   
   $mailer->setTemplateParams(array(
       'order'        => $this,
       'billing'      => $this->getBillingAddress(),
       'payment_html' => $paymentBlockHtml,
       'remoteaddr'   => $_SERVER['REMOTE_ADDR']
     ));
   
 d. Now we must call the variable from within template file as {{var remoteaddr }}   

3. Get Order Comments in Transaction Email :: 
   
     Use the below line to get Customer Comments in Email Template :-
   
     {{var order.getEmailCustomerNote()}}

4. Run Installation process again : 
   
   Once, I forgot the Admin Password on Local installation of Magento, I wanted to restore it. I thought that it would be better if I could run the Installation process again. Running the Installation process again did not delete my existing data on Database. Which means it did not create new tables on the DB rather used the old ones. So my Admin Panel was intact. 
   
   To go through install wizard again, we need to delete app/etc/local.xml file and reload any magento page, it will be redirected to /install. 

5. Magento Error :: "There was a problem with the subscription: This email address is already assigned to another user."
   
   This is not a bug but an intended behaviour in Magento. This message can be seen in the following scenarios ..
   
   i. When the user is not logged in, however he/she is using an email address with which another customer is already registered.
   ii. When the user is logged in, however he/she is not using his/her own email address, rather an email address with which another customer is already registered.
   
   So, if we use a right email address, this error message can be avoided.
   
6. Get the GIANT XML file programmatically which is created after every module's config.xml file is parsed by Magento and included in the global config. 
   
   echo Mage::app()->getConfig()->getNode()->asXML() ;

No comments: