0

How to read 'aref' parameter while creating new Magento account using :

http://mydomain.in/customer/account/create/?aref=88987990

I have implemented as below:

use Magento\Framework\Event\Observer;

use Magento\Framework\App\RequestInterface;

    /**
     * This is the method that fires when 'customer_register_success' event runs.
     *
     * @param Observer $observer
     */
    public function execute( Observer $observer ) {
    // Write to default log file: var/log/system.log
        $this->_logger->info('printing inside RegisterSuccess execute');

    $postData = $this->_request->getPostValue();
    $this->_logger->info('reached 1');
    if($postData) {
        $this->_logger->info('got $postData!!!');
    }

    $allParams = $this->_request->getParams();
    $this->_logger->info('reached 2');
    if($allParams) {
        $this->_logger->info('got $allParams!!!');
        $this->_logger->log(100,print_r($allParams,true));
    }

    $aref = $this->_request->getParam('aref', false);
    $this->_logger->info('reached 3');
    if($aref) {
        $this->_logger->info('got referrer!!!');
    }
    $this->_logger->info('reached 4');
}

Now when I am creating the new account with http://mydomain.in/customer/account/create/?aref=88987990

it's giving logs below:

[2018-11-26 05:02:27] main.INFO: printing inside RegisterSuccess execute [] []

[2018-11-26 05:02:27] main.INFO: reached 1 [] []

[2018-11-26 05:02:27] main.INFO: got $postData!!! [] []

[2018-11-26 05:02:27] main.INFO: reached 2 [] []

[2018-11-26 05:02:27] main.INFO: got $allParams!!! [] []

[2018-11-26 05:02:27] main.INFO: reached 3 [] []

[2018-11-26 05:02:27] main.INFO: reached 4 [] []

but it's not giving 'aref' value. What am I doing wrong?

0

try to get like

$aref = $this->_request->getParam('aref');

OR

 $aref = $this->getRequest()->getParam('aref');
2
  • tried as you said but no result. any further solution?
    – Prince FB
    Nov 26 '18 at 6:16
  • Did you get any solution for this ? Oct 10 '20 at 7:44
0

Use below

\Magento\Framework\App\RequestInterface::getParams().

for example below code

<?php namespace Custom\Checkout\Observer; 

use Magento\Framework\Event\ObserverInterface; 
use Magento\Framework\Event\Observer as EventObserver;

class UpdateItemBefore implements ObserverInterface 
{ 
    /** * @var \Magento\Framework\App\RequestInterface */ 
    protected $_request; 
    /** * @param \Magento\Framework\App\RequestInterface $request */ 

    public function __construct( \Magento\Framework\App\RequestInterface $request ) {
        $this->_request = $request; 
    } 
    /** * @param EventObserver $observer * @return void */ 
    public function execute(EventObserver $observer) 
    { 
        $reqeustParams = $this->_request->getParams(); 
    }
}

Hope this help you.

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.