Skip to content

Totals Sort Order

Custom totals items can be injected into the checkout price summary using a custom phtml template. This is accomplished by adding a custom block to the price-summary.total-segments block via layout XML, with a child block aliased using the total name (e.g., custom_fee).

view/frontend/layout/hyva_checkout_components.xml
<referenceBlock name="price-summary.total-segments">
    <block name="price-summary.total-segments.custom_fee"
           as="custom_fee"
           template="..."
    />
</referenceBlock>

Sort Order Configuration

While it may seem logical to use the after or before attributes to modify the sort order by repositioning blocks, this approach only affects the virtual block structure and does not change the visible order in the checkout.

Hyvä Checkout respects the system configuration settings that are already established within Magento's core functionality. This approach allows system administrators to modify the sort order through configuration rather than requiring developer intervention.

Setting Default Sort Order

Configure the default sort order by adding the total to the totals_sort configuration group:

etc/config.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd"
>
    <default>
        <sales>
            <totals_sort>
                <custom_fee>69</custom_fee>
            </totals_sort>
        </sales>
    </default>
</config>

Admin Configuration (Optional)

To make the sort order configurable through the Magento admin panel, add a corresponding field to the system configuration by referencing the totals_sort group:

etc/adminhtml/system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"
>
    <system>
        <section id="sales">
            <group id="totals_sort">
                <field id="custom_fee"
                       translate="label"
                       type="text"
                       sortOrder="4"
                       showInDefault="1"
                       showInWebsite="1"
                       canRestore="1"
                >
                    <label>Custom Fee</label>
                    <validate>required-number validate-number</validate>
                </field>
            </group>
        </section>
    </system>
</config>

This configuration will add an editable field in the admin panel under Sales > Sales > Checkout Totals Sort Order, allowing administrators to modify the sort order without code changes.