Skip to content

Reload custom totals block

I have added a custom block below the Order Grand Total at Cart and Checkout pages. That block contains some additional totals information that is calculated on run-time based on the grand total amount.

The problem I am facing is, that custom block is not getting updated when the totals are calculated.

e.g. Whole Summary is reloaded but my custom block is not part of that totals block so maybe that;’s why it is not updating.

Here is my checkout_cart_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>

        <referenceContainer name="cart.summary">
            <block class="Folio3DownPaymentBlockTotalPayLater" name="pay_later" before="checkout.cart.methods.bottom" template="Folio3_DownPayment::total/pay_later.phtml" />
        </referenceContainer>

       
    </body>
</page>

This layout file adding a template after “checkout.cart.totals” block.

Here is my template file pay_later.phtml

<div class='cart-totals' id="cart-totals">
    <div class="table-wrapper">
        <table class="data table totals">
            <tbody>
                <tr class="down-payment">
                    <th class="mark" scope="row">
                        <strong><?= /* @escapeNotVerified */ "Down Payment" ?></strong>
                    </th>
                    <td class="amount">
                        <strong><span class="price"><?= $this->helper(MagentoFrameworkPricingHelperData::class)->currency($block->getDownPaymentValue(),true, false) ?></span></strong>
                    </td>
                </tr>
                <tr class="pay-later grand totals">
                    <th class="mark" scope="row">
                        <strong><?= /* @escapeNotVerified */ $block->getTitle() ?></strong>
                    </th>
                    <td class="amount">
                        <strong><span class="price"><?= $this->helper(MagentoFrameworkPricingHelperData::class)->currency($block->getPayLaterValue(),true, false) ?></span></strong>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>```

This is the current result I am getting:
[![Cart Summary][1]][1]

So when my grand total is updated on this page (e.g. via Estimate Shipping) then my Down Payment and Pay Later values are not updating but the grand total and other totals are getting updated.

I need some quick help in this regard about how can I update my custom block as well so it can return the values from runtime and not just on page load.

Using Magento 2.4.4-p6
[![enter image description here][2]][2]


  [1]: https://i.stack.imgur.com/AJLuP.png
  [2]: https://i.stack.imgur.com/g4gdk.png