I want to add popup notify after adding products Magento 2Adding a modal after adding to cartHow to add my custom popup form after adding the products in Shopping cart magento 2How to add “Add To Cart” Pop Up Magento 2 Custom theme?Magento 2 How to add Product Review Form to Popup?Product not showing after adding related products in Magento2How to add my custom popup form after adding the products in Shopping cart magento 2Mini cart is not working after adding custom themeMagento 2 - custom price can not add to subtotal and grand total after add to cartMagento2 : Add Simple Products to bundle product selectionHow to show popup for going to continue shop or checkout page after product adding to cart page?Adding CMS Blocks to a Products, not programatically - Magento 2
New order #4: World
Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore
Can a planet have a different gravitational pull depending on its location in orbit around its sun?
Are white and non-white police officers equally likely to kill black suspects?
What is the meaning of "of trouble" in the following sentence?
Why is the design of haulage companies so “special”?
Is this food a bread or a loaf?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Can I legally use front facing blue light in the UK?
Are cabin dividers used to "hide" the flex of the airplane?
Ideas for 3rd eye abilities
How to move the player while also allowing forces to affect it
How can I fix this gap between bookcases I made?
"listening to me about as much as you're listening to this pole here"
Does bootstrapped regression allow for inference?
Why was the "bread communication" in the arena of Catching Fire left out in the movie?
Need help identifying/translating a plaque in Tangier, Morocco
What do the Banks children have against barley water?
What are the advantages and disadvantages of running one shots compared to campaigns?
Where else does the Shulchan Aruch quote an authority by name?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Pristine Bit Checking
I see my dog run
Can the Produce Flame cantrip be used to grapple, or as an unarmed strike, in the right circumstances?
I want to add popup notify after adding products Magento 2
Adding a modal after adding to cartHow to add my custom popup form after adding the products in Shopping cart magento 2How to add “Add To Cart” Pop Up Magento 2 Custom theme?Magento 2 How to add Product Review Form to Popup?Product not showing after adding related products in Magento2How to add my custom popup form after adding the products in Shopping cart magento 2Mini cart is not working after adding custom themeMagento 2 - custom price can not add to subtotal and grand total after add to cartMagento2 : Add Simple Products to bundle product selectionHow to show popup for going to continue shop or checkout page after product adding to cart page?Adding CMS Blocks to a Products, not programatically - Magento 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I wanted to Add notify popup form after adding the products but I couldn't get the file in magento 2. I need someone help who already done this work.
magento2 mini-cart
add a comment |
I wanted to Add notify popup form after adding the products but I couldn't get the file in magento 2. I need someone help who already done this work.
magento2 mini-cart
Where I have add additional code to make this popup.
– Shakib Rahman
Dec 18 '16 at 7:42
Go to this file and see the Ajax Add to Cartvendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
.
– Khoa TruongDinh
Dec 18 '16 at 7:44
@ShakibRahman check my answer, it is very easy and clear.
– LucScu
Mar 4 '18 at 10:55
add a comment |
I wanted to Add notify popup form after adding the products but I couldn't get the file in magento 2. I need someone help who already done this work.
magento2 mini-cart
I wanted to Add notify popup form after adding the products but I couldn't get the file in magento 2. I need someone help who already done this work.
magento2 mini-cart
magento2 mini-cart
edited Aug 24 '18 at 5:09
Teja Bhagavan Kollepara
2,97341949
2,97341949
asked Dec 18 '16 at 7:40
Shakib RahmanShakib Rahman
67210
67210
Where I have add additional code to make this popup.
– Shakib Rahman
Dec 18 '16 at 7:42
Go to this file and see the Ajax Add to Cartvendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
.
– Khoa TruongDinh
Dec 18 '16 at 7:44
@ShakibRahman check my answer, it is very easy and clear.
– LucScu
Mar 4 '18 at 10:55
add a comment |
Where I have add additional code to make this popup.
– Shakib Rahman
Dec 18 '16 at 7:42
Go to this file and see the Ajax Add to Cartvendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
.
– Khoa TruongDinh
Dec 18 '16 at 7:44
@ShakibRahman check my answer, it is very easy and clear.
– LucScu
Mar 4 '18 at 10:55
Where I have add additional code to make this popup.
– Shakib Rahman
Dec 18 '16 at 7:42
Where I have add additional code to make this popup.
– Shakib Rahman
Dec 18 '16 at 7:42
Go to this file and see the Ajax Add to Cart
vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
.– Khoa TruongDinh
Dec 18 '16 at 7:44
Go to this file and see the Ajax Add to Cart
vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
.– Khoa TruongDinh
Dec 18 '16 at 7:44
@ShakibRahman check my answer, it is very easy and clear.
– LucScu
Mar 4 '18 at 10:55
@ShakibRahman check my answer, it is very easy and clear.
– LucScu
Mar 4 '18 at 10:55
add a comment |
3 Answers
3
active
oldest
votes
You have to override vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js.
.
And you can add this below script in your override catalog-add-to-cart.js
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
...
...
...
var popup = $('<div class="themecafe-free-popup"/>').html('<h1>HTML Content</h1>').modal(
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
...
...
...
);
EDIT
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
$.widget('mage.catalogAddToCart',
.....
ajaxSubmit: function (form)
var self = this;
$(self.options.minicartSelector).trigger('contentLoading');
self.disableAddToCartButton(form);
$.ajax(
url: form.attr('action'),
data: form.serialize(),
type: 'post',
dataType: 'json',
beforeSend: function ()
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStart);
,
success: function (res)
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStop);
if (res.backUrl)
window.location = res.backUrl;
return;
if (res.messages)
$(self.options.messagesSelector).html(res.messages);
if (res.minicart)
$(self.options.minicartSelector).replaceWith(res.minicart);
$(self.options.minicartSelector).trigger('contentUpdated');
if (res.product && res.product.statusText)
$(self.options.productStatusSelector)
.removeClass('available')
.addClass('unavailable')
.find('span')
.html(res.product.statusText);
self.enableAddToCartButton(form);
//popup code start
//for 2 option you can check you value is coming in `res` and get product name
var popup = $('<div class="themecafe-free-popup"/>').html($('.page-title span').text()).modal( //get product name from product view page only
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
//popup code end
);
,
....
);
return $.mage.catalogAddToCart;
);
or
Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="name.of.block" type="VendorModulePluginCartAdd" sortOrder="10" />
</type>
</config>
'Vendor/Module/Plugin/Cart/Add.php'
<?php
namespace VendorModulePluginCart;
use MagentoFrameworkAppObjectManager;
class Add
public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result)
//Your customization is here for passing product name
$subject->getResponse()->representJson(
$objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result1)
);
return $result;
Thanks a lot. But it didn't work.
– Shakib Rahman
Dec 19 '16 at 9:22
try my updated answer
– chirag
Dec 19 '16 at 9:27
Nothing is working. I don't have any idea how I can solve it.
– Shakib Rahman
Dec 19 '16 at 17:04
Checkcatalog-add-to-cart
is successfully override or not and checm your updated code of js from opening js in browser through console.
– chirag
Dec 19 '16 at 18:27
How can we display product name in pop ?
– Jai
Feb 17 '17 at 6:12
|
show 6 more comments
In product page you can obtain it with this code.
In vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml
add at the end the modal div
<div id="addtocart_modal" style="display: none;"></div>
more, add the below attribute to the submit button with class="action primary tocart"
, so you could pass product name to the modal
data-name="<?php echo $_product->getName() ?>"
Now, in vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
after
self.enableAddToCartButton(form);
add the code to init the modal
var cartUrl = url.build('checkout/cart');
var modal_options =
type: 'popup',
buttons: [
text: "« Continue shopping",
class: 'primary btn-lg btn-info addtocart_modal_continue',
click: function ()
this.closeModal();
return false;
,
text: "Go to cart »",
class: 'primary btn-lg btn-success addtocart_modal_gotocart',
click: function ()
location.href = cartUrl;
return false;
]
;
var popup = $('#addtocart_modal');
var product_name = form.find("button").data("name");
// reset modal content every time
popup.html("");
popup.append("<div>The product " + product_name + " is added to your cart</div>");
popup.modal(modal_options);
popup.modal('openModal');
It's done! If you need this modal also in catalog page or everywhere there is an add to cart button keep this logic and adjust it.
PS: override core files is a bad practice, so take in mind to override the files in your module/theme
add a comment |
you can try the free extension Shopping Cart Notifications Magento 2 by MageWorkshop. I hope that solve your issue in a simple way.
https://mageworkshop.com/shopping-cart-notifications-magento-2.html
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');
);
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%2f150794%2fi-want-to-add-popup-notify-after-adding-products-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have to override vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js.
.
And you can add this below script in your override catalog-add-to-cart.js
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
...
...
...
var popup = $('<div class="themecafe-free-popup"/>').html('<h1>HTML Content</h1>').modal(
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
...
...
...
);
EDIT
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
$.widget('mage.catalogAddToCart',
.....
ajaxSubmit: function (form)
var self = this;
$(self.options.minicartSelector).trigger('contentLoading');
self.disableAddToCartButton(form);
$.ajax(
url: form.attr('action'),
data: form.serialize(),
type: 'post',
dataType: 'json',
beforeSend: function ()
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStart);
,
success: function (res)
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStop);
if (res.backUrl)
window.location = res.backUrl;
return;
if (res.messages)
$(self.options.messagesSelector).html(res.messages);
if (res.minicart)
$(self.options.minicartSelector).replaceWith(res.minicart);
$(self.options.minicartSelector).trigger('contentUpdated');
if (res.product && res.product.statusText)
$(self.options.productStatusSelector)
.removeClass('available')
.addClass('unavailable')
.find('span')
.html(res.product.statusText);
self.enableAddToCartButton(form);
//popup code start
//for 2 option you can check you value is coming in `res` and get product name
var popup = $('<div class="themecafe-free-popup"/>').html($('.page-title span').text()).modal( //get product name from product view page only
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
//popup code end
);
,
....
);
return $.mage.catalogAddToCart;
);
or
Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="name.of.block" type="VendorModulePluginCartAdd" sortOrder="10" />
</type>
</config>
'Vendor/Module/Plugin/Cart/Add.php'
<?php
namespace VendorModulePluginCart;
use MagentoFrameworkAppObjectManager;
class Add
public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result)
//Your customization is here for passing product name
$subject->getResponse()->representJson(
$objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result1)
);
return $result;
Thanks a lot. But it didn't work.
– Shakib Rahman
Dec 19 '16 at 9:22
try my updated answer
– chirag
Dec 19 '16 at 9:27
Nothing is working. I don't have any idea how I can solve it.
– Shakib Rahman
Dec 19 '16 at 17:04
Checkcatalog-add-to-cart
is successfully override or not and checm your updated code of js from opening js in browser through console.
– chirag
Dec 19 '16 at 18:27
How can we display product name in pop ?
– Jai
Feb 17 '17 at 6:12
|
show 6 more comments
You have to override vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js.
.
And you can add this below script in your override catalog-add-to-cart.js
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
...
...
...
var popup = $('<div class="themecafe-free-popup"/>').html('<h1>HTML Content</h1>').modal(
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
...
...
...
);
EDIT
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
$.widget('mage.catalogAddToCart',
.....
ajaxSubmit: function (form)
var self = this;
$(self.options.minicartSelector).trigger('contentLoading');
self.disableAddToCartButton(form);
$.ajax(
url: form.attr('action'),
data: form.serialize(),
type: 'post',
dataType: 'json',
beforeSend: function ()
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStart);
,
success: function (res)
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStop);
if (res.backUrl)
window.location = res.backUrl;
return;
if (res.messages)
$(self.options.messagesSelector).html(res.messages);
if (res.minicart)
$(self.options.minicartSelector).replaceWith(res.minicart);
$(self.options.minicartSelector).trigger('contentUpdated');
if (res.product && res.product.statusText)
$(self.options.productStatusSelector)
.removeClass('available')
.addClass('unavailable')
.find('span')
.html(res.product.statusText);
self.enableAddToCartButton(form);
//popup code start
//for 2 option you can check you value is coming in `res` and get product name
var popup = $('<div class="themecafe-free-popup"/>').html($('.page-title span').text()).modal( //get product name from product view page only
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
//popup code end
);
,
....
);
return $.mage.catalogAddToCart;
);
or
Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="name.of.block" type="VendorModulePluginCartAdd" sortOrder="10" />
</type>
</config>
'Vendor/Module/Plugin/Cart/Add.php'
<?php
namespace VendorModulePluginCart;
use MagentoFrameworkAppObjectManager;
class Add
public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result)
//Your customization is here for passing product name
$subject->getResponse()->representJson(
$objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result1)
);
return $result;
Thanks a lot. But it didn't work.
– Shakib Rahman
Dec 19 '16 at 9:22
try my updated answer
– chirag
Dec 19 '16 at 9:27
Nothing is working. I don't have any idea how I can solve it.
– Shakib Rahman
Dec 19 '16 at 17:04
Checkcatalog-add-to-cart
is successfully override or not and checm your updated code of js from opening js in browser through console.
– chirag
Dec 19 '16 at 18:27
How can we display product name in pop ?
– Jai
Feb 17 '17 at 6:12
|
show 6 more comments
You have to override vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js.
.
And you can add this below script in your override catalog-add-to-cart.js
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
...
...
...
var popup = $('<div class="themecafe-free-popup"/>').html('<h1>HTML Content</h1>').modal(
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
...
...
...
);
EDIT
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
$.widget('mage.catalogAddToCart',
.....
ajaxSubmit: function (form)
var self = this;
$(self.options.minicartSelector).trigger('contentLoading');
self.disableAddToCartButton(form);
$.ajax(
url: form.attr('action'),
data: form.serialize(),
type: 'post',
dataType: 'json',
beforeSend: function ()
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStart);
,
success: function (res)
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStop);
if (res.backUrl)
window.location = res.backUrl;
return;
if (res.messages)
$(self.options.messagesSelector).html(res.messages);
if (res.minicart)
$(self.options.minicartSelector).replaceWith(res.minicart);
$(self.options.minicartSelector).trigger('contentUpdated');
if (res.product && res.product.statusText)
$(self.options.productStatusSelector)
.removeClass('available')
.addClass('unavailable')
.find('span')
.html(res.product.statusText);
self.enableAddToCartButton(form);
//popup code start
//for 2 option you can check you value is coming in `res` and get product name
var popup = $('<div class="themecafe-free-popup"/>').html($('.page-title span').text()).modal( //get product name from product view page only
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
//popup code end
);
,
....
);
return $.mage.catalogAddToCart;
);
or
Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="name.of.block" type="VendorModulePluginCartAdd" sortOrder="10" />
</type>
</config>
'Vendor/Module/Plugin/Cart/Add.php'
<?php
namespace VendorModulePluginCart;
use MagentoFrameworkAppObjectManager;
class Add
public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result)
//Your customization is here for passing product name
$subject->getResponse()->representJson(
$objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result1)
);
return $result;
You have to override vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js.
.
And you can add this below script in your override catalog-add-to-cart.js
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
...
...
...
var popup = $('<div class="themecafe-free-popup"/>').html('<h1>HTML Content</h1>').modal(
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
...
...
...
);
EDIT
define([
'jquery',
'mage/translate',
'jquery/ui',
'Magento_Ui/js/modal/modal',
], function ($, $t, modal)
"use strict";
$.widget('mage.catalogAddToCart',
.....
ajaxSubmit: function (form)
var self = this;
$(self.options.minicartSelector).trigger('contentLoading');
self.disableAddToCartButton(form);
$.ajax(
url: form.attr('action'),
data: form.serialize(),
type: 'post',
dataType: 'json',
beforeSend: function ()
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStart);
,
success: function (res)
if (self.isLoaderEnabled())
$('body').trigger(self.options.processStop);
if (res.backUrl)
window.location = res.backUrl;
return;
if (res.messages)
$(self.options.messagesSelector).html(res.messages);
if (res.minicart)
$(self.options.minicartSelector).replaceWith(res.minicart);
$(self.options.minicartSelector).trigger('contentUpdated');
if (res.product && res.product.statusText)
$(self.options.productStatusSelector)
.removeClass('available')
.addClass('unavailable')
.find('span')
.html(res.product.statusText);
self.enableAddToCartButton(form);
//popup code start
//for 2 option you can check you value is coming in `res` and get product name
var popup = $('<div class="themecafe-free-popup"/>').html($('.page-title span').text()).modal( //get product name from product view page only
modalClass: 'changelog',
title: $.mage.__("Model Title"),
buttons: [
text: 'Continue Shopping',
click: function ()
this.closeModal();
]
);
popup.modal('openModal');
//popup code end
);
,
....
);
return $.mage.catalogAddToCart;
);
or
Vendor/Module/etc/frontend/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutControllerCartAdd">
<plugin name="name.of.block" type="VendorModulePluginCartAdd" sortOrder="10" />
</type>
</config>
'Vendor/Module/Plugin/Cart/Add.php'
<?php
namespace VendorModulePluginCart;
use MagentoFrameworkAppObjectManager;
class Add
public function afterExecute(MagentoCheckoutControllerCartAdd $subject, $result)
//Your customization is here for passing product name
$subject->getResponse()->representJson(
$objectManager->get('MagentoFrameworkJsonHelperData')->jsonEncode($result1)
);
return $result;
edited Jul 6 '18 at 5:40
Nagaraju Kasa
2,75821541
2,75821541
answered Dec 18 '16 at 12:38
chiragchirag
2,1511830
2,1511830
Thanks a lot. But it didn't work.
– Shakib Rahman
Dec 19 '16 at 9:22
try my updated answer
– chirag
Dec 19 '16 at 9:27
Nothing is working. I don't have any idea how I can solve it.
– Shakib Rahman
Dec 19 '16 at 17:04
Checkcatalog-add-to-cart
is successfully override or not and checm your updated code of js from opening js in browser through console.
– chirag
Dec 19 '16 at 18:27
How can we display product name in pop ?
– Jai
Feb 17 '17 at 6:12
|
show 6 more comments
Thanks a lot. But it didn't work.
– Shakib Rahman
Dec 19 '16 at 9:22
try my updated answer
– chirag
Dec 19 '16 at 9:27
Nothing is working. I don't have any idea how I can solve it.
– Shakib Rahman
Dec 19 '16 at 17:04
Checkcatalog-add-to-cart
is successfully override or not and checm your updated code of js from opening js in browser through console.
– chirag
Dec 19 '16 at 18:27
How can we display product name in pop ?
– Jai
Feb 17 '17 at 6:12
Thanks a lot. But it didn't work.
– Shakib Rahman
Dec 19 '16 at 9:22
Thanks a lot. But it didn't work.
– Shakib Rahman
Dec 19 '16 at 9:22
try my updated answer
– chirag
Dec 19 '16 at 9:27
try my updated answer
– chirag
Dec 19 '16 at 9:27
Nothing is working. I don't have any idea how I can solve it.
– Shakib Rahman
Dec 19 '16 at 17:04
Nothing is working. I don't have any idea how I can solve it.
– Shakib Rahman
Dec 19 '16 at 17:04
Check
catalog-add-to-cart
is successfully override or not and checm your updated code of js from opening js in browser through console.– chirag
Dec 19 '16 at 18:27
Check
catalog-add-to-cart
is successfully override or not and checm your updated code of js from opening js in browser through console.– chirag
Dec 19 '16 at 18:27
How can we display product name in pop ?
– Jai
Feb 17 '17 at 6:12
How can we display product name in pop ?
– Jai
Feb 17 '17 at 6:12
|
show 6 more comments
In product page you can obtain it with this code.
In vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml
add at the end the modal div
<div id="addtocart_modal" style="display: none;"></div>
more, add the below attribute to the submit button with class="action primary tocart"
, so you could pass product name to the modal
data-name="<?php echo $_product->getName() ?>"
Now, in vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
after
self.enableAddToCartButton(form);
add the code to init the modal
var cartUrl = url.build('checkout/cart');
var modal_options =
type: 'popup',
buttons: [
text: "« Continue shopping",
class: 'primary btn-lg btn-info addtocart_modal_continue',
click: function ()
this.closeModal();
return false;
,
text: "Go to cart »",
class: 'primary btn-lg btn-success addtocart_modal_gotocart',
click: function ()
location.href = cartUrl;
return false;
]
;
var popup = $('#addtocart_modal');
var product_name = form.find("button").data("name");
// reset modal content every time
popup.html("");
popup.append("<div>The product " + product_name + " is added to your cart</div>");
popup.modal(modal_options);
popup.modal('openModal');
It's done! If you need this modal also in catalog page or everywhere there is an add to cart button keep this logic and adjust it.
PS: override core files is a bad practice, so take in mind to override the files in your module/theme
add a comment |
In product page you can obtain it with this code.
In vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml
add at the end the modal div
<div id="addtocart_modal" style="display: none;"></div>
more, add the below attribute to the submit button with class="action primary tocart"
, so you could pass product name to the modal
data-name="<?php echo $_product->getName() ?>"
Now, in vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
after
self.enableAddToCartButton(form);
add the code to init the modal
var cartUrl = url.build('checkout/cart');
var modal_options =
type: 'popup',
buttons: [
text: "« Continue shopping",
class: 'primary btn-lg btn-info addtocart_modal_continue',
click: function ()
this.closeModal();
return false;
,
text: "Go to cart »",
class: 'primary btn-lg btn-success addtocart_modal_gotocart',
click: function ()
location.href = cartUrl;
return false;
]
;
var popup = $('#addtocart_modal');
var product_name = form.find("button").data("name");
// reset modal content every time
popup.html("");
popup.append("<div>The product " + product_name + " is added to your cart</div>");
popup.modal(modal_options);
popup.modal('openModal');
It's done! If you need this modal also in catalog page or everywhere there is an add to cart button keep this logic and adjust it.
PS: override core files is a bad practice, so take in mind to override the files in your module/theme
add a comment |
In product page you can obtain it with this code.
In vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml
add at the end the modal div
<div id="addtocart_modal" style="display: none;"></div>
more, add the below attribute to the submit button with class="action primary tocart"
, so you could pass product name to the modal
data-name="<?php echo $_product->getName() ?>"
Now, in vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
after
self.enableAddToCartButton(form);
add the code to init the modal
var cartUrl = url.build('checkout/cart');
var modal_options =
type: 'popup',
buttons: [
text: "« Continue shopping",
class: 'primary btn-lg btn-info addtocart_modal_continue',
click: function ()
this.closeModal();
return false;
,
text: "Go to cart »",
class: 'primary btn-lg btn-success addtocart_modal_gotocart',
click: function ()
location.href = cartUrl;
return false;
]
;
var popup = $('#addtocart_modal');
var product_name = form.find("button").data("name");
// reset modal content every time
popup.html("");
popup.append("<div>The product " + product_name + " is added to your cart</div>");
popup.modal(modal_options);
popup.modal('openModal');
It's done! If you need this modal also in catalog page or everywhere there is an add to cart button keep this logic and adjust it.
PS: override core files is a bad practice, so take in mind to override the files in your module/theme
In product page you can obtain it with this code.
In vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml
add at the end the modal div
<div id="addtocart_modal" style="display: none;"></div>
more, add the below attribute to the submit button with class="action primary tocart"
, so you could pass product name to the modal
data-name="<?php echo $_product->getName() ?>"
Now, in vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
after
self.enableAddToCartButton(form);
add the code to init the modal
var cartUrl = url.build('checkout/cart');
var modal_options =
type: 'popup',
buttons: [
text: "« Continue shopping",
class: 'primary btn-lg btn-info addtocart_modal_continue',
click: function ()
this.closeModal();
return false;
,
text: "Go to cart »",
class: 'primary btn-lg btn-success addtocart_modal_gotocart',
click: function ()
location.href = cartUrl;
return false;
]
;
var popup = $('#addtocart_modal');
var product_name = form.find("button").data("name");
// reset modal content every time
popup.html("");
popup.append("<div>The product " + product_name + " is added to your cart</div>");
popup.modal(modal_options);
popup.modal('openModal');
It's done! If you need this modal also in catalog page or everywhere there is an add to cart button keep this logic and adjust it.
PS: override core files is a bad practice, so take in mind to override the files in your module/theme
edited Feb 10 '18 at 9:46
answered Feb 9 '18 at 18:31
LucScuLucScu
1,3731230
1,3731230
add a comment |
add a comment |
you can try the free extension Shopping Cart Notifications Magento 2 by MageWorkshop. I hope that solve your issue in a simple way.
https://mageworkshop.com/shopping-cart-notifications-magento-2.html
add a comment |
you can try the free extension Shopping Cart Notifications Magento 2 by MageWorkshop. I hope that solve your issue in a simple way.
https://mageworkshop.com/shopping-cart-notifications-magento-2.html
add a comment |
you can try the free extension Shopping Cart Notifications Magento 2 by MageWorkshop. I hope that solve your issue in a simple way.
https://mageworkshop.com/shopping-cart-notifications-magento-2.html
you can try the free extension Shopping Cart Notifications Magento 2 by MageWorkshop. I hope that solve your issue in a simple way.
https://mageworkshop.com/shopping-cart-notifications-magento-2.html
answered 13 hours ago
Alex GrammAlex Gramm
12
12
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');
);
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%2f150794%2fi-want-to-add-popup-notify-after-adding-products-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');
);
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');
);
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');
);
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
Where I have add additional code to make this popup.
– Shakib Rahman
Dec 18 '16 at 7:42
Go to this file and see the Ajax Add to Cart
vendor/magento/module-catalog/view/frontend/web/js/catalog-add-to-cart.js
.– Khoa TruongDinh
Dec 18 '16 at 7:44
@ShakibRahman check my answer, it is very easy and clear.
– LucScu
Mar 4 '18 at 10:55