Search code examples
magentoinvoices

Get FirstName in Invoice Email in Magento


I need to use the greeting as "Hello customer_firstname" in Invoice emails.

In the Invoice email template file invoice_new.html file, the following line is written, however it is showing the full name of the customer.

Hello, {{htmlescape var=$order.getCustomerFirstname()}

Solution

  • I found a solution where I modified the class Mage_Sales_Model_Order a little and added a new Method called "getCustomerOnlyFirstName" as shown below ::

    The class "Mage_Sales_Model_Order" can be found in app\code\core\Mage\Sales\Model\Order.php path..

    public function getCustomerOnlyFirstName()
    {
      $name = trim($this->getCustomerName());
      $pos = strpos($name," ");
    
      if($pos !== false) /// FirstName can be extracted
      {
         $name = trim(substr( $name, 0, $pos ));
      }
    
      return $name; 
    }
    

    And in Email templates ( invoice_new.html and invoice_new_guest.html ), I had to write the following lines to get the things done ...

    Hello, {{htmlescape var=$order.getCustomerOnlyFirstName()}}
    

    It worked perfectly.