In Magento 1.9 PayPal is transferring a SHIPTONAME which is used for the shipping address. Instead of populating firstname and lastname with the correct variables, only firstname is populated with SHIPTONAME which includes both first- and lastname and the field for lastname remains empty. I need to change this so SHIPTONAME isn't being used and instead each field is populated with the correct variable.

This function

protected function _exportAddressses($data)
    $address = new Varien_Object();
    Varien_Object_Mapper::accumulateByMap($data, $address, $this->_billingAddressMap);
    // assume there is shipping address if there is at least one field specific to shipping
    if (isset($data['SHIPTONAME'])) {
        $shippingAddress = clone $address;
        Varien_Object_Mapper::accumulateByMap($data, $shippingAddress, $this->_shippingAddressMap);
        // PayPal doesn't provide detailed shipping name fields, so the name will be overwritten
            'firstname'  => $data['SHIPTONAME'],

assigns SHIPTONAME to the firstname field, but simply adding a second declaration like 'lastname' => $data['LASTNAME'], has no effect, as apparently only the firstname field is being used for the shipping address for PayPal Express orders.

3 Answers 3


In Model/Express/Checkout.php the returnFromPaypal($token) function includes this:


If I remove this, I can change the _exportAddressses function in Model/Api/Nvp.php to include

'firstname'  => $data['FIRSTNAME'],
'lastname'  => $data['LASTNAME'],

instead of

'firstname'  => $data['SHIPTONAME'],

This will properly assign first- and lastname to their respective fields. I am still trying to figure out, why Magento is assigning the full name to the firstname field in the first place - and why nobody is bothered by this...

Edit 26.09.2017

As some have pointed out, this will force customers to use the billing address stored within PayPal without being able to select a differing shipping address. So I have chosen a different approach:


$shiptofirstname = substr($data['SHIPTONAME'], 0, strrpos($data['SHIPTONAME'], ' '));
$shiptolastname = array_pop(explode(' ', $data['SHIPTONAME']));
    'firstname'  => $shiptofirstname,
    'lastname'  => $shiptolastname,

This will split SHIPTONAME after the last space. For my country this will most likely work 99% of the time as surnames usually don't include spaces. And even if the surname includes a space, at least I am not getting empty surname fields or double surnames (see a differenet solution further down) which will force me to edit orders manually but only incorrectly splitted surnames.

  • 1
    The problem with this approach is that $data['FIRSTNAME'] and $data['LASTNAME'] keeps data from Magento. This mean if shipping address name from PayPal is different from Magento it will be overwritten. I'm afraid the only solution here is to parse $data['SHIPTONAME']. May 31, 2016 at 14:00
  • Correction, $data['FIRSTNAME'] and $data['LASTNAME'] is PayPal account holder which can definitely be different from shipping address name. May 31, 2016 at 14:20
  • 2017 and we still ahve this problem ;) Is there a workaround or fix for this??? Or is the solution still to parse $data['SHIPTONAME']? thanks in advance
    – snh_nl
    Aug 28, 2017 at 13:31
  • Update! I am an Magento 1934 .... if I take a look in the sales_flat_quote table ... then I can clearly see first+lastname ... can it be that the PP Exress was updated and is now sending firstname + lastname? only Magento keeps hard-resetting it? See here: imgur.com/a/ucf6U -- how else could it get there?
    – snh_nl
    Aug 28, 2017 at 15:01
  • We are using this answer and see: the billing address has a firstname+lastname and the shipping address has a firstname+lastname .... only the account itself in customer/accoount in the backend nass no value for firstname+lastname. Is this fixed supposed to fix this too? Or is there another solution? thx
    – snh_nl
    Mar 2, 2019 at 16:02

Uncomment the SetName methods ... they are no longer needed.

Paypal does send the customer information Firstname and Lastname.

Magento 1934 28-8-17

public function returnFromPaypal($token)
    $quote = $this->_quote;


    // import shipping address
    $exportedShippingAddress = $this->_api->getExportedShippingAddress();
    if (!$quote->getIsVirtual()) {
        $shippingAddress = $quote->getShippingAddress();
        if ($shippingAddress) {
            if ($exportedShippingAddress) {
                $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress);

                if ($quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1) {
                    // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix
  • So what's happening with this solution is SHIPTONAME will still insert the entire Pay Pal name into Magentos first name field while the described changes will result in the Pay Pal billing last name being inserted into Magentos last name field. Not a solution either I am afraid
    – loeffel
    Sep 26, 2017 at 9:33
        // PayPal doesn't provide detailed shipping name fields, so the name will be overwritten
        $_arraydata = explode(' ', $data['SHIPTONAME'], 2);
        if (!empty($_arraydata[0]) && !empty($_arraydata[1])) {
                'firstname'  => $_arraydata[0],
                'lastname'  => $_arraydata[1]
        } else {
                'firstname'  => $data['FIRSTNAME'],
                'lastname'  => $data['LASTNAME']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.