0

I need to get customer details(first name, last name so on) after guest checkout when submitting the email and without creating an account.

For more detail please check secreenshot:

enter image description here

After placing the order

enter image description here

  • Without creating an account ? How you can achieve this without account ? Do you mean without customer login here ? – Kishan Savaliya Nov 5 '19 at 7:17
  • I think you want customer account information when user enter their email, if that email exist in your system then you will get firstname, lastname and all other information otherwise not. – Kishan Savaliya Nov 5 '19 at 7:18
  • Is there any guest checkout event? After guest order success – Shomita Nov 5 '19 at 7:18
  • Acutally at that time customer does not sync in magento admin – Shomita Nov 5 '19 at 7:19
  • Your requirement is not clear, Can you please update your question with some more information ? – Kishan Savaliya Nov 5 '19 at 7:20
1

You need to create events.xml file in your custom module here

app/code/Vendor/Module/etc/events.xml

Here you need to add checkout_submit_all_after event like this..

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_submit_all_after"> <!-- sales_order_place_after -->
        <observer name="your_observer_name" instance="Vendor\Module\Observer\OrderPlaceAfter" />
    </event>
</config>

Now you need to create one observer file there you can get customer and order details.

app/code/Vendor/Module/Observer/OrderPlaceAfter.php

Content for this file..

<?php
namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;
use Psr\Log\LoggerInterface;

class OrderPlaceAfter implements ObserverInterface
{
    protected $logger;

    public function __construct(
        LoggerInterface $logger
    ) {
        $this->logger = $logger;
    }

    public function execute(Observer $observer){
        try {
            $order = $observer->getEvent()->getOrder();
            $customerFirstName = $order->getCustomerFirstname();
            $customerLastName = $order->getCustomerLastname();

            $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/guest_orders.log');
            $logger = new \Zend\Log\Logger();
            $logger->addWriter($writer);
            $logger->info($customerFirstName);
            $logger->info($customerLastName);

            /*Here you can get all fields value which is available in `sales_order` table.*/

            return $observer;
        }catch (\Exception $e) {
            $this->logger->info($e->getMessage());
        }
    }
}

Based on your requirement you can modify code in your observer.

Hope this will help you!

  • 1
    Thanks Kishan, I am working on this – Shomita Nov 5 '19 at 7:51
  • Did you check this code? am getting error – Shomita Nov 5 '19 at 8:14
  • What error you are getting? – aravind Nov 5 '19 at 8:32
  • 1 exception(s): Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Requested entity doesn't exist Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Requested entity doesn't exist – Shomita Nov 5 '19 at 8:36
  • 1
    I've updated my code with logger you will get log of you customer first and last name there. – Kishan Savaliya Nov 5 '19 at 8:54

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.