0

I'm adding a custom UiComponent to checkout using Layout Processor:

  1. LayoutProcessor.php
$this->jsLayout['components']['checkout']['children']['sidebar']
['children']['summary']['children'] = [
'my-item' => [
    'displayArea' => 'my-item',
    'component' => 'Vendor_Module/js/view/my-item',
    'config' => [
        'template' => 'Vendor_Module/my-item'
    ],
    'custom-data' => 'some custom data' 
];
  1. Vendor_Module/js/view/my-item.js
define(
    [
        'jquery',
        'ko',
        'uiComponent',
        'Magento_Checkout/js/model/totals'
    ],
    function ($, ko, Component, totals) {
        'use strict';
        return Component.extend({
            items: ko.observable([]),
            initialize: function () {
                this._super();
                totals.getItems().subscribe(function (items) {
                    this.setItems(items);
                }.bind(this));
            },
            getItemsToRender: function () {
                `I want my custom data here`
            }
        });
    }
);

Is it possible to "send" custom data from LayoutProcessor to js component?

1 Answer 1

1

Try adding config as an argument in your initialize method:

initialize: function (config) {
    this._super();
    totals.getItems().subscribe(function (items) {
        this.setItems(items);
    }.bind(this));

    console.log(config)
}

I have only done this with x-magento-init and not PHP Layout Processors but I'm hoping it works the same.

If it works it will likely only return the template as that's all you have in your config, but you will be able to move your custom data inside the config if that is the case.

2
  • 1
    thanks, I added my custom data under 'config' in PHP Layout Processors and it worked. Commented Jun 25, 2020 at 8:00
  • Great stuff, glad I could help. Commented Jun 25, 2020 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.