从购物车中删除商品之前的确认消息

时间:2018-09-12 19:32:03

标签: prestashop-1.7

在prestashop 1.7中从购物车中移除商品之前,prestashop中是否可以显示确认消息?我只想指向包含此方法的文件,以便我可以添加一个确认对话框,因为现在用户可以直接删除而无需确认

1 个答案:

答案 0 :(得分:2)

是的,您可以在从购物车中删除商品之前显示确认对话框。默认情况下,core.jstheme.js文件处理所有事件,并在updateCart事件上相应地更新购物车。 (Refer more on events here

要克服默认行为,请在js之前添加theme.js,这有助于防止默认点击事件。请遵循下面提到的分步指南来加载您自己的js并在删除项目时添加确认对话框。

1)通过在js下添加以下代码,在theme.ymlMore details here)中注册assets

themes / {your_theme} /config/theme.yml

assets:
  js:
    cart:
      - id: cart-extra-lib
        path: assets/js/cart-lib.js
        priority: 30

2)在cart-lib.js下创建文件themes/{your_theme}/assets/js,并在其中添加以下代码。

主题/{your_theme}/assets/js/cart-lib.js

function refreshDataLinkAction() {
    $('[data-link-action="delete-from-cart"]').each(function(){
        $(this).attr('data-link-action', 'confirm-remove-item');
    });
}

$(document).on('click', '[data-link-action="confirm-remove-item"]', function(e) {
    e.preventDefault();
    if (confirm('Are you sure you want to remove product from cart?')) {
        $(this).attr('data-link-action', 'delete-from-cart');
        $(this).trigger('click');
    }
    return false;
});

$(document).ready(function () {
    refreshDataLinkAction();
    prestashop.on('updatedCart', function (event) {
        refreshDataLinkAction();
    });
});

3)现在,要加载js文件,您需要删除文件config/themes/{your_theme}/shop1.jsonReference

4)将产品添加到购物车并检查购物车;删除项目,您将看到确认消息。附上图片以供参考。

enter image description here