I am trying to add some additonal data under checkout items summary (right sidebar).
I am not figuring out how to get dynamic data from maybe Block (or other way).
Here it is what I have already done:
1 / Add my component to checkout_index_index layout
File Foo/Bar/view/frontend/layout/checkout_index_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="sidebar" xsi:type="array">
<item name="children" xsi:type="array">
<item name="summary" xsi:type="array">
<item name="children" xsi:type="array">
<item name="itemsAfter" xsi:type="array">
<item name="children" xsi:type="array">
<item name="foo-bar-summary" xsi:type="array">
<item name="component" xsi:type="string">Foo_Bar/js/sample/summary</item>
<!--<item name="displayArea" xsi:type="string">summary</item>-->
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Foo_Bar/sample/summary</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
2 / Create component
File Foo/Bar/view/frontend/web/js/sample/summary.js
define([
'jquery',
'uiComponent',
'ko'
], function ($, Component, ko) {
'use strict';
return Component.extend({
initialize: function () {
this._super();
}
});
}
);
3 / Add template
File Foo/Bar/view/frontend/web/template/sample/summary.html
<div class="component-wrapper">
<div data-bind="text: 'Test sample'"></div>
</div>
4 / Same thing with M2 Block / Template logic
File Foo/Bar/view/frontend/templates/summary.phtml
<div id="sample-summary" data-bind="scope: 'sample-summary'">
<!-- ko template: getTemplate() --><!-- /ko -->
<script type="text/x-magento-init">
{
"#sample-summary": {
"Magento_Ui/js/core/app": {
"components": {
"sample-summary": {
"component": "Foo_Bar/js/sample/summary",
"template" : "Foo_Bar/sample/summary"
}
}
}
}
}
</script>
</div>
With that I can see my Test sample
above the items list.
- Do I really need to use
Kojs
or can I just use the "basic" way to implement Block / template / layout ? - How can I call my block / template in the
checkout_index_index
layout ? - Are there others ways to call dynamic data into Kojs ?
- Why my Component is inserted before while it is in
itemsAfter
node ?