Как удалить товар из корзины при оформлении заказа


Как удалить товар из корзины при оформлении заказа? Файл Magento_Checkout/web/template/summary/item/details.html

<div class="cart-item__col-subtotal">
   <div class="cart-item__subtotal" >
       <div class="cart-item__delete" data-bind="click: console.log($parent.item_id)"><span data-bind="i18n: 'Delete'"></span></div>
       <!-- ko foreach: getRegion('after_details') -->
       <!-- ko template: getTemplate() --><!-- /ko -->
       <!-- /ko -->
   </div>
</div>

Как подключить файл js и удалить элемент по щелчку мыши?

Author: Prathap Gunasekaran, 2019-02-12

1 answers

Vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js

define([
    'uiComponent',
    'mage/url'
], function (Component, url) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'Magento_Checkout/summary/item/details'
        },

        /**
         * @param {Object} quoteItem
         * @return {String}
         */
        getValue: function (quoteItem) {
            return quoteItem.name;
        },
        getDataPost: function(itemId) { 
            console.log(itemId);
            var itemsData = window.checkoutConfig.quoteItemData;
            var obj = {};
            var obj = {
                data: {}
            };

            itemsData.forEach(function (item) {
                if(item.item_id == itemId) { 
                    var mainlinkUrl = url.build('checkout/cart/delete/');
                    var baseUrl = url.build('checkout/');
                    console.log(mainlinkUrl);
                    obj.action = mainlinkUrl;
                    obj.data.id= item.item_id;
                    obj.data.uenc = btoa(baseUrl);
                }
            });
            return JSON.stringify(obj);
        }
    });
});

Vendor/magento/module-checkout/view/frontend/web/template/summary/item/details.html

<!-- ko foreach: getRegion('before_details') -->
    <!-- ko template: getTemplate() --><!-- /ko -->
<!-- /ko -->
<div class="product-item-details">

    <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 class="secondary">
             <a href="#" data-bind="attr: {'data-post': getDataPost($parent.item_id),title: $t('Delete item')}" class="action delete">
                <span data-bind="i18n: 'Remove'"></span>
             </a>
        </div>
    </div>

    <!-- ko if: (JSON.parse($parent.options).length > 0)-->
    <div class="product options" data-bind="mageInit: {'collapsible':{'openedState': 'active'}}">
        <span data-role="title" class="toggle"><!-- ko i18n: 'View Details' --><!-- /ko --></span>
        <div data-role="content" class="content">
            <strong class="subtitle"><!-- ko i18n: 'Options Details' --><!-- /ko --></strong>
            <dl class="item-options">
                <!--ko foreach: JSON.parse($parent.options)-->
                <dt class="label" data-bind="text: label"></dt>
                    <!-- ko if: ($data.full_view)-->
                    <dd class="values" data-bind="html: full_view"></dd>
                    <!-- /ko -->
                    <!-- ko ifnot: ($data.full_view)-->
                    <dd class="values" data-bind="html: value"></dd>
                    <!-- /ko -->
                <!-- /ko -->
            </dl>
        </div>
    </div>
    <!-- /ko -->
</div>

Примечание: Я изменил основные файлы только для целей тестирования. Вы должны создать расширение, чтобы переопределить эти файлы.

 2
Author: Kishan Patadia, 2019-02-12 09:58:53