Skip to content

Commit 68b5f2d

Browse files
committed
MAGETWO-71229: Warning message is cached and shown a few times on the shopping cart
1 parent f59024f commit 68b5f2d

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/addtocart.phtml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
</div>
4141
</div>
4242
<?php endif; ?>
43-
<script type="text/x-magento-init">
43+
<?php if ($block->isRedirectToCartEnabled()) : ?>
44+
<script type="text/x-magento-init">
4445
{
4546
"#product_addtocart_form": {
4647
"Magento_Catalog/product/view/validation": {
@@ -49,13 +50,11 @@
4950
}
5051
}
5152
</script>
52-
<?php if (!$block->isRedirectToCartEnabled()) : ?>
53-
<script type="text/x-magento-init">
53+
<?php else : ?>
54+
<script type="text/x-magento-init">
5455
{
5556
"#product_addtocart_form": {
56-
"catalogAddToCart": {
57-
"bindSubmit": false
58-
}
57+
"Magento_Catalog/js/validate-product": {}
5958
}
6059
}
6160
</script>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery',
7+
'mage/mage',
8+
'Magento_Catalog/product/view/validation',
9+
'catalogAddToCart'
10+
], function ($) {
11+
'use strict';
12+
13+
$.widget('mage.productValidate', {
14+
options: {
15+
bindSubmit: false,
16+
radioCheckboxClosest: '.nested'
17+
},
18+
19+
/**
20+
* Uses Magento's validation widget for the form object.
21+
* @private
22+
*/
23+
_create: function () {
24+
var bindSubmit = this.options.bindSubmit;
25+
26+
this.element.validation({
27+
radioCheckboxClosest: this.options.radioCheckboxClosest,
28+
29+
/**
30+
* Uses catalogAddToCart widget as submit handler.
31+
* @param {Object} form
32+
* @returns {Boolean}
33+
*/
34+
submitHandler: function (form, event) {
35+
var jqForm = $(form).catalogAddToCart({
36+
bindSubmit: bindSubmit
37+
});
38+
39+
jqForm.catalogAddToCart('submitForm', jqForm, event);
40+
41+
return false;
42+
}
43+
});
44+
}
45+
});
46+
47+
return $.mage.productValidate;
48+
});

app/code/Magento/Theme/view/frontend/web/js/view/messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ define([
2121
initialize: function () {
2222
this._super();
2323

24-
this.cookieMessages = $.cookieStorage.get('mage-messages');
24+
this.cookieMessages = _.unique($.cookieStorage.get('mage-messages'), 'text');
2525
this.messages = customerData.get('messages').extend({
2626
disposableCustomerData: 'messages'
2727
});

0 commit comments

Comments
 (0)