0

I want edit shipping address after create order on frontend in magento 1.

I used observer, it's ok, but i cann't set new shipping address

Ex: i want change firstname to "ABC"

$orderId = $observer->getEvent()->getOrder()->getData('entity_id');
$order = Mage::getModel('sales/order')->load($orderId);
$order->getShippingAddress()->addFirstname("Abd");
$order->save();

And i also try this code but it not working

$order = Mage::getModel('sales/order')->load($orderId);
$quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
$billingAddress = $quote->getBillingAddress();
$billingAddress
            ->setFirstName($defaultBilling->getFirstName())
            ->setCountryId($defaultBilling->getCountryId())
            ->setPostcode($defaultBilling->getPostCode());
$quote->save();

It's not work, please help me

1 Answer 1

2

Please try something like this: $order->setData('customer_firstname', 'abc'); to set first name, and to set last name you can use: $order->setData('customer_lastname', 'abc');. I tested this code in observer for sales_order_place_after event and it works.

SOLUTION:

$event = $observer->getEvent();   
$order = $event->getOrder();   
$order->getShippingAddress()->setData('firstname', 'abcd');
12
  • thanks for answer but it not work for me
    – Brian N
    Jan 20, 2020 at 10:54
  • please try code from edit
    – SebastianT
    Jan 20, 2020 at 10:56
  • i tryed, it's also not work :((
    – Brian N
    Jan 20, 2020 at 10:57
  • please try Mage::log(print_r($order->getShippingAddress()->getData(), true), null, 'system.log', true); and tell what shows in system.log
    – SebastianT
    Jan 20, 2020 at 10:58
  • it show [firstname] => abcd, but in order details on backend, it not change
    – Brian N
    Jan 20, 2020 at 11:00

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.