0

I have set link like this

http://localhost/magento/customer/account/create/?param_id=20

how I can get that (param_id) value in customer registration success observer in Magento 2

how I can do this??

I already tried this answer but not working --> https://magento.stackexchange.com/a/154141/73525

Observer

namespace Lunatic\Module\Observer;
use Magento\Framework\Event\ObserverInterface;


class Setcustomer implements ObserverInterface
{

    const CUSTOMER_GROUP_ID = 2;
    protected $request;
    protected $_customerRepositoryInterface;

    public function __construct(
        \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface,
       \Magento\Framework\App\Request\Http $request
    ) {
        $this->_customerRepositoryInterface = $customerRepositoryInterface;
        $this->request = $request;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {


        $customer = $observer->getEvent()->getCustomer();
        if ($customer->getGroupId() == 1) {
            $customer->setGroupId(self::CUSTOMER_GROUP_ID);
            $id=getIddata();
            $this->_customerRepositoryInterface->save($customer);
        }

    }
    public function getIddata()
    {
        $this->request->getParams();

        return $this->request->getParam('id');
    }

}

xml

<?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="customer_register_success">
        <observer name="setdealer_forcustomer" instance="Lunatic\Module\Observer\Setcustomer"/>
    </event>
</config>
  • please add your code here – Rutvee Sojitra May 27 at 9:19
  • added code...... – prabhakaran7 May 27 at 9:24
  • You cant pass parameter in URL like this, Instead of this you can pass parameter into hidden field in get in your observer. – anonymous May 27 at 10:12
0

You need to call your functuinn using $this

        public function execute(\Magento\Framework\Event\Observer $observer)
        {                
            $customer = $observer->getEvent()->getCustomer();
            if ($customer->getGroupId() == 1) {
                $customer->setGroupId(self::CUSTOMER_GROUP_ID);
                $id=$this->getIddata();
                $this->_customerRepositoryInterface->save($customer);
            }

        }
        public function getIddata()
        {
           $this->request->getParams();

           return $this->request->getParam('param_id');
        }

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.