How to add a custom field with its value in the checkout cart summary in Magento 2 ?
I have followed many links, but none helped me.
Any help would be appreciated.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityHow to add a custom field with its value in the checkout cart summary in Magento 2 ?
I have followed many links, but none helped me.
Any help would be appreciated.
If you need just dynamic data at the cart or checkout page
1.create etc/frontend/di.xml file
<?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="custom_provider" xsi:type="object">Vendor\Namespace\Model\CustomConfigProvider</item>
</argument>
</arguments>
</type>
</config>
2.create the CustomConfigProvider.php in Vendor\Namespace\Model\ folder
<?php
namespace Vendor\Namespace\Model;
class CustomConfigProvider implements \Magento\Checkout\Model\ConfigProviderInterface
{
public function getConfig()
{
$output['custom_config'] = 'Custom Config';
return $output;
}
}
3.Now Run the command
php bin/magento c:f
4. Please open the console of website and type the command
console.log(window.checkoutConfig.custom_config); OR window.checkoutConfig.custom_config
If the result is 'Custom Config', Now you can use this variable for your purpose where you want.
I hope this is helpful to you!!