1

In Magento 2 I don't understand how knockout js templates work.

In this file : vendor/magento/module-checkout/view/frontend/web/template/summary/item/details.phtml

<div class="product-item-inner">
    <div class="product-item-name-block">
        <strong class="product-item-name" data-bind="html: $parent.name"></strong>
        <div class="details-qty">
            <span class="label"><!-- ko i18n: 'Qty' --><!-- /ko --></span>
            <span class="value" data-bind="text: $parent.qty"></span>
        </div>
    </div>
    <!-- ko foreach: getRegion('after_details') -->
        <!-- ko template: getTemplate() --><!-- /ko -->
    <!-- /ko -->
</div>

I need to know where html: $parent.name and text: $parent.qty are defined, in order to change these values.

Thanks for your help.

-1

We need to create Plugin to do so create a < vender >/< module >/etc/di.xml file

<type name="Magento\Checkout\Model\DefaultConfigProvider">
        <plugin name="AddAttPlug" type="Mycar\Checkout\Plugin\ConfigProviderPlugin" />
    </type>

< vender >/< module >/Plugin/ConfigProviderPlugin.php

public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result) {
    $_items = [];
    $quoteId = $this->checkoutSession->getQuote()->getId();
    if ($quoteId) {
        $itemOptionCount = count($result['totalsData']['items']);
        for ($i = 0; $i < $itemOptionCount; $i++) {           
                $result['totalsData']['items'][$i]['name'] = 'Test name';
                $result['totalsData']['items'][$i]['qty'] = 2;
                $_items[$i] = $result['totalsData']['items'][$i];
        }
        $result['totalsData']['items'] = $_items;
        json_encode($result);
    }
    return $result;
}
| improve this answer | |
  • Ok I understand, but how to access $parent.name variable and change value in php ? – Fbr Mar 12 at 10:13
  • @Fbr please check the updated code – Mandar Parbate Mar 12 at 10:29
  • Ok thanks, it work on checkout step "delivery" but it doesn't work in next step "payment". Is it managed in 2 different ways ? – Fbr Mar 12 at 13:26
  • @Fbr this was only for delivery step, need to do the same for the payment step too. – Mandar Parbate Mar 13 at 5:04
  • Yes I understand, but how to do it ? Where is code for payment step ? – Fbr Mar 13 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.