layout_generate_blocks_after observer is not redirecting to checkout/cart page in Magento 2

magento.stackexchange https://magento.stackexchange.com/questions/322077

سؤال

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();
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top