1

I have created a redirect controller for the payment gateway for redirection to the payment method host but that controller is being cached when I enable the full page cache of Magento. If I remove full page cache then it is working fine.

Due to the controller being cached, the order total amount is showing the previous order's total on the payment gateway page.

Redirect Controller:-

<?php

namespace ST\Migs\Controller\Hosted;

class Redirect extends \ST\Migs\Controller\Hosted
{

    public function execute()
    {
        $incrementId = $this->_checkoutSession->getLastRealOrderId();
        if (!empty($incrementId)) {
            $order = $this->_getOrder();
            $response = $this->_view->getLayout()
                ->createBlock('ST\Migs\Block\Form\Hosted','st-form-hosted')
                ->setTemplate('ST_Migs::form/redirect.phtml')
                ->setFormUrl($this->_hosted->getFormUrl())
                ->setFormFields($this->_hosted->getFormFields($order))
                ->toHtml();
            $this->getResponse()->setBody($response);
        }

    }

}

Layout st_hosted_redirect.xml :-

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <container name="root">
        <block class="ST\Migs\Block\Form\Hosted" name="st-migs-from-hosted" template="ST_Migs::form/redirect.phtml" cacheable="false"/>
    </container>
</layout>

Is there any solution to disable the cache for this controller and block ?

I have tried adding following solution but none of them worked:-

a) add $this->addData(array('cache_lifetime' => null)); in block constructor.

b) add cacheable="false" in layout for block.

c) add '$page->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0', true);' in controller.

Please let me know if you solved the same problem.

Magento version 2.4.3-p3.

1
  • I am also facing the same issue. Nov 15, 2022 at 10:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy