从购物车中删除商品之前的确认消息 [英] confirmation message before deleting an item from cart
问题描述
在 prestashop 1.7 中从购物车中移除商品之前,prestashop 是否可以显示确认消息?我只想指向包含此方法的文件,以便我可以添加确认对话框,因为现在用户无需确认即可删除
是的,您可以在从购物车中删除项目之前显示确认对话框.默认情况下,core.js
和 theme.js
文件处理所有事件并在 updateCart
事件上相应地更新购物车.(
Is there a way in prestashop to show a confirmation message before an item is removed from the cart in prestashop 1.7? I'd just like to be pointed to the file that contains this method so that I may be able to add a confirm dialog, since right now a user can just delete without confirmin
Yes, you can show confirm dialog before deleting item from cart. By default core.js
and theme.js
file handles all events and update cart accordingly on updateCart
event. (Refer more on events here)
To overcome default behaviour adding js
prior to theme.js
will help us to prevent default click event. Follow below mentioned step by step guide to load you own js
and add confirmation dialog on item delete.
1) Register your js
in theme.yml
(More details here) by adding below code under assets
themes/{your_theme}/config/theme.yml
assets:
js:
cart:
- id: cart-extra-lib
path: assets/js/cart-lib.js
priority: 30
2) Create file cart-lib.js
under themes/{your_theme}/assets/js
and add below code into it.
themes/{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) Now, to load your js file you need to delete file config/themes/{your_theme}/shop1.json
(Reference)
4) Add products to cart and check cart; delete items you will see confirmation message. Attaching image for reference.
这篇关于从购物车中删除商品之前的确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!