get confirmation before removing item from cart in magento 2?
I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.
I have tried some examples but still when i click on cancel the item gets removed from cart.
here is the code we need to change:-
<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>
If anyone get the solution?
magento2 cart
|
show 3 more comments
I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.
I have tried some examples but still when i click on cancel the item gets removed from cart.
here is the code we need to change:-
<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>
If anyone get the solution?
magento2 cart
1
Its already present. Check the demo here: magento2-demo.nexcess.net
– Sejal Shah
May 23 '17 at 13:51
No, its not already there. You did not get my point
– Mandar Parbate
May 24 '17 at 4:19
open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it
– Mandar Parbate
May 24 '17 at 4:21
Not for mini-cart
– Mandar Parbate
May 24 '17 at 4:22
ok..I thought it's for minicart in the header
– Sejal Shah
May 24 '17 at 4:39
|
show 3 more comments
I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.
I have tried some examples but still when i click on cancel the item gets removed from cart.
here is the code we need to change:-
<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>
If anyone get the solution?
magento2 cart
I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.
I have tried some examples but still when i click on cancel the item gets removed from cart.
here is the code we need to change:-
<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>
If anyone get the solution?
magento2 cart
magento2 cart
asked May 23 '17 at 13:15
Mandar ParbateMandar Parbate
155423
155423
1
Its already present. Check the demo here: magento2-demo.nexcess.net
– Sejal Shah
May 23 '17 at 13:51
No, its not already there. You did not get my point
– Mandar Parbate
May 24 '17 at 4:19
open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it
– Mandar Parbate
May 24 '17 at 4:21
Not for mini-cart
– Mandar Parbate
May 24 '17 at 4:22
ok..I thought it's for minicart in the header
– Sejal Shah
May 24 '17 at 4:39
|
show 3 more comments
1
Its already present. Check the demo here: magento2-demo.nexcess.net
– Sejal Shah
May 23 '17 at 13:51
No, its not already there. You did not get my point
– Mandar Parbate
May 24 '17 at 4:19
open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it
– Mandar Parbate
May 24 '17 at 4:21
Not for mini-cart
– Mandar Parbate
May 24 '17 at 4:22
ok..I thought it's for minicart in the header
– Sejal Shah
May 24 '17 at 4:39
1
1
Its already present. Check the demo here: magento2-demo.nexcess.net
– Sejal Shah
May 23 '17 at 13:51
Its already present. Check the demo here: magento2-demo.nexcess.net
– Sejal Shah
May 23 '17 at 13:51
No, its not already there. You did not get my point
– Mandar Parbate
May 24 '17 at 4:19
No, its not already there. You did not get my point
– Mandar Parbate
May 24 '17 at 4:19
open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it
– Mandar Parbate
May 24 '17 at 4:21
open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it
– Mandar Parbate
May 24 '17 at 4:21
Not for mini-cart
– Mandar Parbate
May 24 '17 at 4:22
Not for mini-cart
– Mandar Parbate
May 24 '17 at 4:22
ok..I thought it's for minicart in the header
– Sejal Shah
May 24 '17 at 4:39
ok..I thought it's for minicart in the header
– Sejal Shah
May 24 '17 at 4:39
|
show 3 more comments
2 Answers
2
active
oldest
votes
You have to override form.phtml file
app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml
Add below code at last
<script>
require(['jquery', 'jquery/ui'], function($){
jQuery('.action-delete').click(function(e)
{
if(confirm('Do you want to remove this product?'))
{
return true;
}
else
{
return false;
}
});
});
</script>
how to do the same with pop up modal ...
– sangan
Nov 27 '17 at 9:41
add a comment |
To display confirm box using popup modal,
Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml
- Remove data-post from
<a>
tag for delete product from cart - Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.
- Add below code at the bottom of the same file.
<script>
var deleteFromCart;
require([ 'jquery',
'Magento_Customer/js/model/authentication-popup',
'Magento_Ui/js/modal/alert',
'Magento_Ui/js/modal/confirm',
'jquery/ui',
'mage/decorate',
'mage/collapsible',
'mage/cookies'], function($, authenticationPopup, alert, confirm){
deleteFromCart=function(datapass)
{
var data1=datapass;
$.extend(data1.data, {
'form_key': $.mage.cookies.get('form_key')
});
confirm({
content: 'Are you sure you would like to remove this item from the shopping cart?',
actions: {
/** @inheritdoc */
confirm: function () {
$.post({
url: data1.action,
data:data1.data,
showLoader: true,
success: function (res) {
location.reload();
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
}
});
},
/** @inheritdoc */
always: function (e) {
e.stopImmediatePropagation();
return false;
}
}
});
}
});
</script>
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f175731%2fget-confirmation-before-removing-item-from-cart-in-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have to override form.phtml file
app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml
Add below code at last
<script>
require(['jquery', 'jquery/ui'], function($){
jQuery('.action-delete').click(function(e)
{
if(confirm('Do you want to remove this product?'))
{
return true;
}
else
{
return false;
}
});
});
</script>
how to do the same with pop up modal ...
– sangan
Nov 27 '17 at 9:41
add a comment |
You have to override form.phtml file
app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml
Add below code at last
<script>
require(['jquery', 'jquery/ui'], function($){
jQuery('.action-delete').click(function(e)
{
if(confirm('Do you want to remove this product?'))
{
return true;
}
else
{
return false;
}
});
});
</script>
how to do the same with pop up modal ...
– sangan
Nov 27 '17 at 9:41
add a comment |
You have to override form.phtml file
app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml
Add below code at last
<script>
require(['jquery', 'jquery/ui'], function($){
jQuery('.action-delete').click(function(e)
{
if(confirm('Do you want to remove this product?'))
{
return true;
}
else
{
return false;
}
});
});
</script>
You have to override form.phtml file
app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml
Add below code at last
<script>
require(['jquery', 'jquery/ui'], function($){
jQuery('.action-delete').click(function(e)
{
if(confirm('Do you want to remove this product?'))
{
return true;
}
else
{
return false;
}
});
});
</script>
edited May 30 '17 at 13:27
answered May 30 '17 at 12:55
Camit1dkCamit1dk
381117
381117
how to do the same with pop up modal ...
– sangan
Nov 27 '17 at 9:41
add a comment |
how to do the same with pop up modal ...
– sangan
Nov 27 '17 at 9:41
how to do the same with pop up modal ...
– sangan
Nov 27 '17 at 9:41
how to do the same with pop up modal ...
– sangan
Nov 27 '17 at 9:41
add a comment |
To display confirm box using popup modal,
Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml
- Remove data-post from
<a>
tag for delete product from cart - Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.
- Add below code at the bottom of the same file.
<script>
var deleteFromCart;
require([ 'jquery',
'Magento_Customer/js/model/authentication-popup',
'Magento_Ui/js/modal/alert',
'Magento_Ui/js/modal/confirm',
'jquery/ui',
'mage/decorate',
'mage/collapsible',
'mage/cookies'], function($, authenticationPopup, alert, confirm){
deleteFromCart=function(datapass)
{
var data1=datapass;
$.extend(data1.data, {
'form_key': $.mage.cookies.get('form_key')
});
confirm({
content: 'Are you sure you would like to remove this item from the shopping cart?',
actions: {
/** @inheritdoc */
confirm: function () {
$.post({
url: data1.action,
data:data1.data,
showLoader: true,
success: function (res) {
location.reload();
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
}
});
},
/** @inheritdoc */
always: function (e) {
e.stopImmediatePropagation();
return false;
}
}
});
}
});
</script>
New contributor
add a comment |
To display confirm box using popup modal,
Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml
- Remove data-post from
<a>
tag for delete product from cart - Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.
- Add below code at the bottom of the same file.
<script>
var deleteFromCart;
require([ 'jquery',
'Magento_Customer/js/model/authentication-popup',
'Magento_Ui/js/modal/alert',
'Magento_Ui/js/modal/confirm',
'jquery/ui',
'mage/decorate',
'mage/collapsible',
'mage/cookies'], function($, authenticationPopup, alert, confirm){
deleteFromCart=function(datapass)
{
var data1=datapass;
$.extend(data1.data, {
'form_key': $.mage.cookies.get('form_key')
});
confirm({
content: 'Are you sure you would like to remove this item from the shopping cart?',
actions: {
/** @inheritdoc */
confirm: function () {
$.post({
url: data1.action,
data:data1.data,
showLoader: true,
success: function (res) {
location.reload();
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
}
});
},
/** @inheritdoc */
always: function (e) {
e.stopImmediatePropagation();
return false;
}
}
});
}
});
</script>
New contributor
add a comment |
To display confirm box using popup modal,
Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml
- Remove data-post from
<a>
tag for delete product from cart - Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.
- Add below code at the bottom of the same file.
<script>
var deleteFromCart;
require([ 'jquery',
'Magento_Customer/js/model/authentication-popup',
'Magento_Ui/js/modal/alert',
'Magento_Ui/js/modal/confirm',
'jquery/ui',
'mage/decorate',
'mage/collapsible',
'mage/cookies'], function($, authenticationPopup, alert, confirm){
deleteFromCart=function(datapass)
{
var data1=datapass;
$.extend(data1.data, {
'form_key': $.mage.cookies.get('form_key')
});
confirm({
content: 'Are you sure you would like to remove this item from the shopping cart?',
actions: {
/** @inheritdoc */
confirm: function () {
$.post({
url: data1.action,
data:data1.data,
showLoader: true,
success: function (res) {
location.reload();
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
}
});
},
/** @inheritdoc */
always: function (e) {
e.stopImmediatePropagation();
return false;
}
}
});
}
});
</script>
New contributor
To display confirm box using popup modal,
Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml
- Remove data-post from
<a>
tag for delete product from cart - Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.
- Add below code at the bottom of the same file.
<script>
var deleteFromCart;
require([ 'jquery',
'Magento_Customer/js/model/authentication-popup',
'Magento_Ui/js/modal/alert',
'Magento_Ui/js/modal/confirm',
'jquery/ui',
'mage/decorate',
'mage/collapsible',
'mage/cookies'], function($, authenticationPopup, alert, confirm){
deleteFromCart=function(datapass)
{
var data1=datapass;
$.extend(data1.data, {
'form_key': $.mage.cookies.get('form_key')
});
confirm({
content: 'Are you sure you would like to remove this item from the shopping cart?',
actions: {
/** @inheritdoc */
confirm: function () {
$.post({
url: data1.action,
data:data1.data,
showLoader: true,
success: function (res) {
location.reload();
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
}
});
},
/** @inheritdoc */
always: function (e) {
e.stopImmediatePropagation();
return false;
}
}
});
}
});
</script>
New contributor
edited 27 mins ago
New contributor
answered Jan 11 at 11:41
KhushbuKhushbu
11
11
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f175731%2fget-confirmation-before-removing-item-from-cart-in-magento-2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Its already present. Check the demo here: magento2-demo.nexcess.net
– Sejal Shah
May 23 '17 at 13:51
No, its not already there. You did not get my point
– Mandar Parbate
May 24 '17 at 4:19
open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it
– Mandar Parbate
May 24 '17 at 4:21
Not for mini-cart
– Mandar Parbate
May 24 '17 at 4:22
ok..I thought it's for minicart in the header
– Sejal Shah
May 24 '17 at 4:39