在prestashop 1.7中从购物车中移除商品之前,prestashop中是否可以显示确认消息?我只想指向包含此方法的文件,以便我可以添加一个确认对话框,因为现在用户可以直接删除而无需确认
答案 0 :(得分:2)
是的,您可以在从购物车中删除商品之前显示确认对话框。默认情况下,core.js
和theme.js
文件处理所有事件,并在updateCart
事件上相应地更新购物车。 (Refer more on events here)
要克服默认行为,请在js
之前添加theme.js
,这有助于防止默认点击事件。请遵循下面提到的分步指南来加载您自己的js
并在删除项目时添加确认对话框。
1)通过在js
下添加以下代码,在theme.yml
(More 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.json
(Reference)
4)将产品添加到购物车并检查购物车;删除项目,您将看到确认消息。附上图片以供参考。