Add to window.checkoutConfig with a checkout config provider

Create a checkout config provider

While it's not the best practice in the world to use Magento's global window.checkoutConfig object to store data, this method is used all throughout Magento's core code.

This can greatly simplify custom frontend code in situations where it's hard to grab the same data and store it in a local component state, allowing you to easily store PHP-generated data in a JavaScript object.

By just adding an element to Magento_Checkout's CompositeConfigProvider model, then creating the simple PHP class, you can write any PHP code you wish and it will automatically be made available in this window.checkoutConfig object!

This includes any dynamic data, including CMS blocks as well as info pulled out of the database. This cannot be easily accomplished with pure JavaScript.

Wherever possible, you should strive to use local component state instead, as using & referencing a global JavaScript object is generally considered a bad practice. That said, this can be incredibly useful in order to quickly get dynamic data in a way that can be easily accessed with JavaScript.

Complete and Continue  
Extra lesson content locked
Enroll to access all lessons, source code & comments.
Enroll now to Unlock