0

In the guest order info customer name displaying as a guest and looked into the database table of sales_order here customer first name & last name storing as a null.

how can we set name before place order?

5

Create one observer file :

Namespace\Module\Observer\SalesOrderPlaceBefore.php

namespace Namespace\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class SalesOrderPlaceBefore implements ObserverInterface
{

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
        if (!$order->getCustomerFirstname() && !$order->getCustomerLastname()) {
            $order->setCustomerFirstname($order->getBillingAddress()->getFirstname());
            $order->setCustomerLastname($order->getBillingAddress()->getLastname());
        }
        $order->save();
    }
}
0

You can do this by creating an observer similar to 'AssignOrderToCustomerObserver.php' in sales module.

$order->setCustomerFirstname($customer->getFirstname())
      ->setCustomerLastname($customer->getLastname())

This should work.

  • Thank you for your answer. Actually, $customer->getFirstname() getting as blank value and I was solved by using observer after place order. – Praveen Chelumalla Aug 22 at 4:08
  • Good to know :) – Sanjay Sharma Aug 22 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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