3

I'm currently working in the success.phtml file. I need to get the name from the shipping address the user put in. I used to have code that would only grab the username of the user and would display Guest for a name if the user was not logged in. So I decided the name from the shipping address would most likely be the correct one to get. Here is the code I am using.

<?php 
$grayson_order_id = $this->getOrderId();
$order = Mage::getModel('sales/order')->load($grayson_order_id);
$custname = $order->getBillingAddress()->getName();
?>

But the page crashes at $custname = $order->getBillingAddress()->getName();

I don't think it really matters but im running Magento EE 1.13

I'm sure it's something simple I'm missing, or I'm simply calling the wrong method. Any help is appreciated.

1

3 Answers 3

8

$this->getOrderId() returns the increment ID (i.e. 100000456) and not the actual database ID. You'll need to use loadByIncrementId() instead of load():

<?php 
$grayson_order_id = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($grayson_order_id);
$custname = $order->getBillingAddress()->getName();
?>

(The page was crashing at that point because $order->getBillingAddress() didn't return anything, and you can't call ->getName() on a null value.)

0
1

As Sales Order address table have not any field 'name' and sales Address Modelldo not have any Function getName(),So Can not get Order full name from sales Order address using getName function

EDIT My Above Description is totally wrong ,@Colin is right.

$custname = $order->getBillingAddress()->getFirstname().' '.$order->getBillingAddress()->getLastname();
5
1

$this->getOrderId() return order increment id

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$custname = $order->getBillingAddress()->getName();

To load by order id

$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId(); // try also $this->getRealOrderId() or $this->getLastOrderId()
$order = Mage::getModel('sales/order')->load($lastOrderId);
$custname = $order->getBillingAddress()->getName();

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.