cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 - Once on a product go back to searched

Magento 2 - Once on a product go back to searched

I want to have a button saying "back to results" or a bar above the product which says  "HOME > SEARCH RESULT FOR: ...." so once I've clicked on a product i can then go back to what i have searched or what categorie i have clicked on to find the product.

 

Thanks

1 REPLY 1

Re: Magento 2 - Once on a product go back to searched

@paddy_james

 

You can redirects to previous page with the help of HTTP_REFERER

 

You can follow like:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get('Magento\Framework\App\Request\Http');

$backurl = $request->getServer('HTTP_REFERER');

?>

 

OR 

 

namespace Vendorname\Modulename\Controller\Adminhtml\Index;
class Fetch extends \Magento\Backend\App\Action
{
    public function execute()
    {
        // TODO: Implement execute() method.
        $this->_redirect($this->_redirect->getRefererUrl());
    }
}

 

Manish Mittal
https://www.manishmittal.com/