Magento 2

Magento2 Adding additional variables in window.checkoutConfig on Checkout page

During checkout customization we often need to add more variables that we need to use on the checkout. Here is how we can do that.

Step : 1 Add the following code in Ace\OrderDeliveryDate/etc/frontend/di.xml of your custom module –

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    
    <type name="Magento\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="ace_deliverydate" xsi:type="object">Ace\OrderDeliveryDate\Model\CompositeConfigProvider</item>
            </argument>
        </arguments>
    </type>

</config>

After this, we will create CompositeConfigProvider.php in Ace\OrderDeliveryDate\Model and add the following code to it –

<?php
namespace Ace\OrderDeliveryDate\Model;

class CompositeConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
{

    public function getConfig()
    {
          
        $output['ace_delivery_enable'] = true ; 
        return $output;
    }
}

Now all you need to do is flush Magento cache and check ‘window.checkoutConfig.ace_delivery_enable’ in your js on the checkout page. It will return true.