magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Extend Checkout XML to allow shipping method additional templates and UiComponents #38128

Open jakwinkler opened 1 year ago

jakwinkler commented 1 year ago

Description

When a payment method is added on the checkout page, it renders its children automatically:

However, for the shipping methods, there is no such option and in my personal opinion, that feature is missing from the platform.

This can be achieved by adding this to shipping-method-item.html template:

<tr class="row row-hidden"
    data-bind="css: {'show': element.isSelected}" attr="'id': 'row_' + method.method_code + '_' + method.carrier_code">
    <td class="col col-additional">
        <!-- ko if: (method.method_code) -->
        <each args="element.getRegion(method.method_code)" render=""></each>
        <!-- /ko -->
    </td>
</tr>

By having this in knockout.JS tempate, you can add a uiComponent by XML like this:

<item name="shippingAddress" xsi:type="array">
    <item name="children" xsi:type="array">
        <item name="pocztapolska" xsi:type="array">
            <item name="component" xsi:type="string">Custom_Shipping/js/view/checkout/shipping</item>
            <item name="config" xsi:type="array">
                <item name="method" xsi:type="string">pocztapolska</item>
            </item>
            <item name="displayArea" xsi:type="string">pocztapolska</item>
        </item>
    </item>
</item>

FOr reference: this is how payment methods do it:

<item name="children" xsi:type="array">
    <item name="renders" xsi:type="array">
        <item name="component" xsi:type="string">uiComponent</item>
        <item name="children" xsi:type="array">
            <!-- merge payment method renders here -->
        </item>
    </item>
</item>

Expected behavior

Benefits

Additional information

This can be implemented just by simple shipping-method-item.html template modification. Would require some information for developers and some samples how easy it is to create UiComponents for shipping methods.

Release note

No response

m2-assistant[bot] commented 1 year ago

Hi @qsolutions-pl. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue: