Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture an URL parameter - Magento

Tags:

magento

I have the following requirement: my URLs can be any of the following

  • http://localhost.com/index.php/?resid=anyvalue
  • http://localhost.com/index.php/storeviewname/?resid=anyvalue, or ......?resid=anyvalue

I want to capture the resid value and place it in the backend and save it along the order the customer makes.

I.e., if ?resid=133 is requested and the customer later proceeds to make an order, I want the resid to be saved (133) along with the order id (say 100000123).

And later I want the resid value to be shown in the sales order grid (in admin).

Can somebody guide me in doing this?

like image 734
kuhajeyan Avatar asked Dec 08 '11 11:12

kuhajeyan


People also ask

How do I get parameters in Magento 2?

You can get Post Data value in the After plugin using Magento 2. You can get all the Params() data after the plugin which is sent by request. If you send the query string Or data within the URL, you can get those data using getParams() in the after plugin.

How can get current URL in Magento?

If you need to get current URL in Magento 2 PHTML file the easiest way to do this is to use the following code: $currentUrl = $block->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]); This is the best method since you don't even need to use the Object Manager.

How can I get referral URL in Magento 2?

Magento 2, Get Referer url by calling function getRefererUrl() or getRedirectUrl() from RedirectInterface Object. Magento core Interface, Magento\Framework\App\Response\RedirectInterface used for fetch Referer URL.

What is a link parameter?

Also known by the aliases of query strings or URL variables, parameters are the portion of a URL that follows a question mark. They are comprised of a key and a value pair, separated by an equal sign. Multiple parameters can be added to a single page by using an ampersand.


1 Answers

In the controller do $this->getRequest()->getParam('resid') to get the value. Save that in the user's session. To save it in the order, you have to add a field to the Order table then you can add it to the Order object once its created. You'll have to then overwrite the Grid Block used to display orders to add that field to the grid. It'll be a lot of work to do this all.

like image 153
Max Avatar answered Sep 25 '22 02:09

Max