在Onepage Checkout页面Magento2中的订单摘要中显示删除和编辑项目按钮

时间:2017-11-03 12:02:16

标签: magento magento2 onepage-checkout

我想在结帐页面的订单摘要部分显示删除和修改图标,我尝试过以下更改:

  

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

我添加了如下编辑/删除链接:

<div class="primary">
     <a data-bind="attr: {href: getConfigUrl($parent.item_id),title: $t('Edit item')}" class="action edit">
          <span data-bind="i18n: 'Edit'"></span>
     </a>
</div>
<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>
  

在   /magento_demo/vendor/magento/module-checkout/view/frontend/web/js/view/summary/item/details.js

我做了以下更改:

define(
    [
        'uiComponent',
        'mage/url',
        'Magento_Customer/js/customer-data',
        'jquery',
        'ko',
        'underscore',
        'sidebar',
        'mage/translate'
    ],
    function (Component,url,customerData,$,ko, _) {
        "use strict";
        return Component.extend({
            defaults: {
                template: 'Magento_Checkout/summary/item/details'
            },
            getValue: function(quoteItem) {
                var itemId = elem.data('cart-item'),
                itemQty = elem.data('item-qty');
                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/cart/');
                        console.log(mainlinkUrl);
                        obj.action = mainlinkUrl;
                        obj.data.id= item.item_id;
                        obj.data.uenc = btoa(baseUrl);
                    }
                });
                return JSON.stringify(obj);
            },
            getConfigUrl: function(itemId) { 
                var itemsData = window.checkoutConfig.quoteItemData;
                var configUrl = null;
                var mainlinkUrl = url.build('checkout/cart/configure');
                var linkUrl;
                itemsData.forEach(function (item) {
                    var itm_id = item.item_id;
                    var product_id = item.product.entity_id;
                    if(item.item_id == itemId) { 
                        linkUrl = mainlinkUrl+"/id/"+itm_id+"/product_id/"+product_id;
                    }
                });
                if(linkUrl != null) {
                    return linkUrl;
                }
                else {
                    return '';
                }

            }
        });
    }
);

但是当我点击删除按钮时,它只是重定向到购物车页面而不是删除产品,这可能是什么问题。

0 个答案:

没有答案