0

I'm using the observer layout_generate_blocks_after to perform redirection to an empty cart on a condition but it is not redirecting. Any help would be appreciated.

Here is the piece of code which i try to do:

$cart->truncate();
$cart->save();

$redirectUrl = $this->urlBuilder->getUrl('checkout/cart'); 

$this->_responseFactory->create()->setRedirect($redirectUrl)->sendResponse();
die();
0

The event 'layout_generate_blocks_after' will not fire on full page cache pages. It's only generated during the initial page render on a non-cache page.

2
  • I'm getting "too many redirects" error in "network" tab.
    – Max28
    Sep 11 '20 at 6:57
  • If it's a non-cached page this event will fire, redirect the user and then run again, and so redirect the user again, causing an infinite loop until the browser stops redirecting. Sep 11 '20 at 7:20

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.