How to assign a Guest Order to a Customer using Using Controller- Magento 2 - Magento source24

How to assign a Guest Order to a Customer using Using Controller- Magento 2 -  Magento source24
How to assign a Guest Order to a Customer using Using Controller- Magento 2 -  Magento source24


How to assign a Guest Order to a Customer using Using Controller- Magento 2 -  Magento source24


In this Blog post im share with you to code How to assign a Guest Order to a Customer using Using Controller- Magento 2 - 

👉in this sql query i'm update two table sales_order  and sales_order_grid  to set Guest order to customer.

👉 this query is required CUSTOMER ID and  ORDER ID.



<?php

class SaveGuestOrderToCustomer extends \Magento\Backend\App\Action

protected $orderRepository;

protected $searchCriteriaBuilder;

{

public function __construct(

    \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,

    \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder

) {

    $this->orderRepository = $orderRepository;

    $this->searchCriteriaBuilder = $searchCriteriaBuilder;

  }

public function execute()

{

    $incrementId = {YOUR ORDER ID};

    $customerId = {YOUR CUSTOMER ID};

    $searchCriteria = $this->searchCriteriaBuilder->addFilter('increment_id', $incrementId, 'eq')->create();

    $order = $this->orderRepository->getList($searchCriteria)->getFirstItem();

     if ($order->getId() && !$order->getCustomerId()) 

    {

        $order->setCustomerId($customerId);

        $order->setCustomerIsGuest(0);

        $this->orderRepository->save($order);

}

}

}






Deepak Kumar Bind

Success is peace of mind, which is a direct result of self-satisfaction in knowing you made the effort to become the best of which you are capable.

Post a Comment

If you liked this post please do not forget to leave a comment. Thanks

Previous Post Next Post