从购物车中删除商品前的确认消息
confirmation message before deleting an item from cart
在 prestashop 1.7 中,prestashop 是否有一种方法可以在从购物车中删除商品之前显示确认消息?我只想指向包含此方法的文件,以便我可以添加确认对话框,因为现在用户可以在没有确认的情况下直接删除
是的,您可以在从购物车中删除商品之前显示确认对话框。默认情况下 core.js
和 theme.js
文件处理所有事件并在 updateCart
事件上相应地更新购物车。 (Refer more on events here)
为了克服默认行为,在 theme.js
之前添加 js
将帮助我们防止默认点击事件。按照下面提到的分步指南加载您自己的 js
并在项目删除时添加确认对话框。
1) 通过在 assets
下添加以下代码,在 theme.yml
(More details here) 中注册您的 js
主题/{your_theme}/config/theme.yml
assets:
js:
cart:
- id: cart-extra-lib
path: assets/js/cart-lib.js
priority: 30
2) 在 themes/{your_theme}/assets/js
下创建文件 cart-lib.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
()
4) 将产品添加到购物车并查看购物车;删除项目你会看到确认消息。附上图片以供参考。
在 prestashop 1.7 中,prestashop 是否有一种方法可以在从购物车中删除商品之前显示确认消息?我只想指向包含此方法的文件,以便我可以添加确认对话框,因为现在用户可以在没有确认的情况下直接删除
是的,您可以在从购物车中删除商品之前显示确认对话框。默认情况下 core.js
和 theme.js
文件处理所有事件并在 updateCart
事件上相应地更新购物车。 (Refer more on events here)
为了克服默认行为,在 theme.js
之前添加 js
将帮助我们防止默认点击事件。按照下面提到的分步指南加载您自己的 js
并在项目删除时添加确认对话框。
1) 通过在 assets
theme.yml
(More details here) 中注册您的 js
主题/{your_theme}/config/theme.yml
assets:
js:
cart:
- id: cart-extra-lib
path: assets/js/cart-lib.js
priority: 30
2) 在 themes/{your_theme}/assets/js
下创建文件 cart-lib.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
(
4) 将产品添加到购物车并查看购物车;删除项目你会看到确认消息。附上图片以供参考。