Magento 1.9 Paypal Guest Customer Name


Introduction

Many Magento users encounter an issue where the customer name defaults to “guest” during a PayPal Express guest checkout. This results in order confirmation emails addressing the customer as “hello guest”. In this guide, we’ll walk through a solution to ensure the customer’s first and last names are correctly captured and displayed.

Problem Description

When a guest uses PayPal Express to check out, Magento defaults the customer name to “guest”. This is because the default _prepareGuestQuote function does not capture the first and last names from the billing address.

Solution Overview

To resolve this issue, we need to modify the _prepareGuestQuote method in the PayPal Express Checkout model to include the customer’s first and last names from the billing address.

Step-by-Step Guide

Follow these steps to implement the solution:

1. Copy the Original File

Start by copying the original Checkout.php file from the core directory to the local directory:

app/code/core/Mage/Paypal/Model/Express/Checkout.php

to:

app/code/local/Mage/Paypal/Model/Express/Checkout.php

2. Locate the _prepareGuestQuote Method

In the copied file, find the _prepareGuestQuote method. It should look like this:

protected function _prepareGuestQuote()
{
    $quote = $this->_quote;
    $quote->setCustomerId(null)
        ->setCustomerEmail($quote->getBillingAddress()->getEmail())
        ->setCustomerIsGuest(true)
        ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
    return $this;
}

3. Modify the Method

Replace the existing code with the following updated code to include the customer’s first and last names:

protected function _prepareGuestQuote()
{
    $quote = $this->_quote;
    $quote->setCustomerId(null)
        ->setCustomerFirstname($quote->getBillingAddress()->getFirstname()) 
        ->setCustomerLastname($quote->getBillingAddress()->getLastname())
        ->setCustomerEmail($quote->getBillingAddress()->getEmail())
        ->setCustomerIsGuest(true)
        ->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
    return $this;
}

Explanation

The updated method now retrieves the first and last names from the billing address and sets them in the quote object. This ensures that the customer’s name is correctly captured and used in order confirmation emails.

Conclusion

By following these steps, you can effectively resolve the issue of guest customers being addressed as “guest” in order confirmation emails when checking out via PayPal Express. This modification ensures a more personalized customer experience.

Further Assistance

If you have any questions or encounter issues with this solution, feel free to leave a comment below or reach out for support.

Leave a Reply

Your email address will not be published. Required fields are marked *