If customer is guest then i like to add customer registration process with input fields password & confirm password either customer is already registered then working as it is without shows password & confirm password fields. Can somebody have any idea on it? Thanks.

closed as too broad by Piyush, Jai, 7ochem, Manashvi Birla, Dhiren Vasoya Jul 2 '18 at 12:39

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


You can create a customer with order Id on checkout success

Use checkout_onepage_controller_success_action observer to create customer by order id. If customer email is already registered then, order assigned to the registered customer.

Here is the full module code for creating a new customer on order success. This module creates a new customer with order id. If customer already register, an order will be assigned to already register customer

1) Create registration.php




2) Create module.xml


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Myvendor_GuestRegistration" setup_version="1.0.0" />

3) Create di.xml


<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_onepage_controller_success_action">
        <observer name="myvendor_guestregistration_controller_success_action" instance="Myvendor\GuestRegistration\Observer\Convertguest" />

4) Create Convertguest.php



namespace Myvendor\GuestRegistration\Observer;

class Convertguest implements \Magento\Framework\Event\ObserverInterface
     * @var \Magento\Sales\Model\OrderFactory
    protected $_orderFactory;

     * @var \Magento\Sales\Api\OrderCustomerManagementInterface
    protected $orderCustomerService;

     * @var \Magento\Store\Model\StoreManagerInterface
    protected $_storeManager;

     * Convertguest constructor.
     * @param \Magento\Sales\Model\OrderFactory $orderFactory
     * @param \Magento\Sales\Api\OrderCustomerManagementInterface $orderCustomerService
     * @param \Magento\Customer\Model\CustomerFactory $customer
     * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
    public function __construct(
        \Magento\Sales\Model\OrderFactory $orderFactory,
        \Magento\Sales\Api\OrderCustomerManagementInterface $orderCustomerService,
        \Magento\Customer\Model\CustomerFactory $customer,
        \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
        \Magento\Store\Model\StoreManagerInterface $storeManager
    ) {
        $this->_orderFactory = $orderFactory;
        $this->orderCustomerService = $orderCustomerService;
        $this->_customer = $customer;
        $this->orderRepository = $orderRepository;
        $this->_storeManager = $storeManager;

    public function execute(\Magento\Framework\Event\Observer $observer)
        $orderIds = $observer->getEvent()->getOrderIds();

        if (count($orderIds)) {
            $orderId = $orderIds[0];
            //You can also use checkoutSession to get last order  
            //$order = $this->_checkoutSession->getLastRealOrder();
            $order = $this->_orderFactory->create()->load($orderId);

            $customer= $this->_customer->create();

            /*Convert guest to customer*/
            if ($order->getId() && !$customer->getId()) {
                /*New Customer*/
            } else {
                /*Registered customer guest checkout*/

Now run following commands

php bin/magento setup:upgrade
php bin/magento setup:di:compile
  • It works fine, And generate the password link to customer, but if they trying to reset password,it shows password reset token time is expired. So How do i set reset token time(rp_token) – Jaisa Aug 11 '18 at 11:36
  • 1
    it works perfect in m2.2 – open-ecommerce.org Dec 7 '18 at 12:22

Magento provides a better way to convert guest to the customer during checkout. When a user checkout as a guest, Magento shows an option to create an account after the checkout process completes.

Create Account

When the user clicks on Create Account button, Magento uses the information provided by the customer during checkout, to create a new customer account and sends a link to set the password.

After setting up the password, the user can log in to the customer account in Magento website.

Please let me know if you still want to customize the checkout process like you have mentioned in the question.

  • this is the default feature of magento, but once the account is created, the order placed is not synced with the customer, i mean once customer login and go to dashboard, there is no order history for that customer – jafar pinjar May 29 at 9:18

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