On this weblog, we are going to discover ways to set customized knowledge in checkout in Magento 2. On the checkout web page, typically we have to move some customized knowledge to show or add knowledge on the time of the checkout course of. So, we have to use MagentoCheckoutModelCompositeConfigProvider class to move customized variables on the checkout web page.
Let’s begin step-by-step and find out how we will try this :
Step 1: We assume, you have got created a easy module, then it’s a must to add the beneath code in the app/code/Webkul/CustomCheckoutData/and many others/frontend/di.xml file :
<?xml model="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/and many others/config.xsd"> <sort identify="MagentoCheckoutModelCompositeConfigProvider"> <arguments> <argument identify="configProviders" xsi:sort="array"> <merchandise identify="set_custom_data" xsi:sort="object">WebkulCustomCheckoutDataModelCheckoutConfigProvider</merchandise> </argument> </arguments> </sort> </config>
Step 2: After that, It’s essential create an app/code/Webkul/CustomCheckoutData/Mannequin/CustomConfigProvider.php file and paste the beneath code so as to add a customized worth :
<?php namespace WebkulCustomCheckoutDataModel; use MagentoCheckoutModelConfigProviderInterface class CheckoutConfigProvider implements ConfigProviderInterface { public perform getConfig() { $configArray = []; $configArray['custom_data'] = 'Webkul Take a look at Worth'; return $configArray; } }
Right here, you should implement the MagentoCheckoutModelConfigProviderInterface interface in a customized file to move a customized worth within the checkout config.
Now, you should flush the cache after which, you may entry this worth within the JS file on the checkout web page utilizing the beneath approach :
window.checkoutConfig.custom_data
Output:

We hope this tutorial is helpful for you.
You could like our different tutorials :