How To Enable Remote Shopping Assistance When A New Customer Registers In Magento 2.4 [Adobe Commerce]?

What is Remote Shopping assistance in Magento (Adobe Commerce)?

In Magento (now Adobe Commerce), “Allow remote shopping assistance” refers to a feature or functionality that enables merchants or customer support representatives to assist and guide customers remotely during their shopping experience on a Magento site.

Step 1

Add a plugin to Magento\Customer\Controller\Account\CreatePost. This plugin will be called every time a customer creates a new account. Create a plugin under file path,

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

<?xml version="1.0"?>
 
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Customer\Controller\Account\CreatePost">
        <plugin name="after_customer_create" type="Vendor\Module\Plugin\AllowAssitance" sortOrder="1" />
    </type>
</config>

Step 2:

After we create a plugin AllowAssitance.php plugin, we write our logic to enable allow remote shopping assistance. Place the AllowAssitance.php under the file path,

app/code/Vendor/Module/Plugin/AllowAssitance.php

<?php
namespace Vendor\Module\Plugin; use Magento\Customer\Model\Logger;
use Magento\LoginAsCustomerAssistance\Model\ResourceModel\SaveLoginAsCustomerAssistanceAllowed;

class AllowAssitance {
    protected $logger;
    protected $_customerSession;   
    protected $saveLoginAsCustomerAssistanceAllowed;     public function __construct(
        Logger $logger,
        \Magento\Customer\Model\Session $customerSession,   
        SaveLoginAsCustomerAssistanceAllowed $saveLoginAsCustomerAssistanceAllowed
    )
    {
        $this->logger = $logger;
        $this->_customerSession = $customerSession;       
        $this->saveLoginAsCustomerAssistanceAllowed = $saveLoginAsCustomerAssistanceAllowed;
    }

public function afterExecute(\Magento\Customer\Controller\Account\CreatePost $subject,$result) {        
        $customer_id = $this->_customerSession->getCustomer()->getId();
        try {            //Enable checkbox allow shopping assitance
            if($customer_id) {
            $this->saveLoginAsCustomerAssistanceAllowed->execute($customer_id);
            }
        }catch (\Exception $e) {
            $this->logger->critical($e->getMessage());
        }
        return $result;    }
}

The above plugin will add an entry in login_as_customer_assistance_allowed table.
Please visit the developer documentation to get know more about Magento (Adobe Commerce) Here.

About The Author

We take the guesswork out of ecommerce.
Schedule a consultation call today