0

I have the custom module with product collection and custom router.

for example i want to have link https://domain.com/gaires/something

Router code:

namespace UseApp\Gaires\Controller;
class Router implements \Magento\Framework\App\RouterInterface
{
 protected $actionFactory;
 protected $_response;
 public function __construct(
 \Magento\Framework\App\ActionFactory $actionFactory,
 \Magento\Framework\App\ResponseInterface $response
 ) {
 $this->actionFactory = $actionFactory;
 $this->_response = $response;
 }
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
 $exlpoded = array_filter(explode('/', trim($request->getPathInfo()) ) );
 if($exlpoded && $exlpoded[1]=='gaires' && count($exlpoded)>=2){
 $request->setModuleName('gaires')
 ->setControllerName('index')
 ->setActionName('gaire')
 ->setParam('q', urldecode($exlpoded[2]));
 }
 }
}

Router working fine.

In the page (controller) gaires/index/gaire I have product collection with toolbar (sorter, limeter, pagger )

The problem is that the bad url address in the pager, sorter and limiter links.

For example: http://domain.com/gaires/index/gaire/q/something/?p=2

address must be: http://domain.com/gaires/something?p=2

If I change the adres in browser url field manually (http://domain.com/gaires/something?p=2) Router and collection working fine, but toolbar links also no

How can this be fixed?

asked Apr 16, 2018 at 8:24

1 Answer 1

2

after

$request->setModuleName('gaires')
 ->setControllerName('index')
 ->setActionName('gaire')
 ->setParam('q', urldecode($exlpoded[2]));

You add

$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, YOUR_NEW_PATH_HERE);

That "YOUR_NEW_PATH_HERE" is what the pagination is looking at.

answered Jul 11, 2018 at 13:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.