4
4
*/
5
5
define ( [
6
6
'jquery' ,
7
+ 'mage/translate' ,
7
8
'jquery/ui'
8
- ] , function ( $ ) {
9
+ ] , function ( $ , $t ) {
9
10
"use strict" ;
10
11
11
12
$ . widget ( 'mage.catalogAddToCart' , {
@@ -16,7 +17,13 @@ define([
16
17
bindSubmit : true ,
17
18
minicartSelector : '[data-block="minicart"]' ,
18
19
messagesSelector : '[data-placeholder="messages"]' ,
19
- productStatusSelector : '.stock.available'
20
+ productStatusSelector : '.stock.available' ,
21
+ addToCartButtonSelector : '.action.tocart' ,
22
+ addToCartButtonDisabledClass : 'disabled' ,
23
+ addToCartButtonTextWhileAdding : $t ( 'Adding...' ) ,
24
+ addToCartButtonTextAdded : $t ( 'Added' ) ,
25
+ addToCartButtonTextDefault : $t ( 'Add to Cart' )
26
+
20
27
} ,
21
28
22
29
_create : function ( ) {
@@ -49,6 +56,9 @@ define([
49
56
50
57
ajaxSubmit : function ( form ) {
51
58
var self = this ;
59
+ $ ( self . options . minicartSelector ) . trigger ( 'contentLoading' ) ;
60
+ self . disableAddToCartButton ( form ) ;
61
+
52
62
$ . ajax ( {
53
63
url : form . attr ( 'action' ) ,
54
64
data : form . serialize ( ) ,
@@ -82,8 +92,30 @@ define([
82
92
. find ( 'span' )
83
93
. html ( res . product . statusText ) ;
84
94
}
95
+ self . enableAddToCartButton ( form ) ;
85
96
}
86
97
} ) ;
98
+ } ,
99
+
100
+ disableAddToCartButton : function ( form ) {
101
+ var addToCartButton = $ ( form ) . find ( this . options . addToCartButtonSelector ) ;
102
+ addToCartButton . addClass ( this . options . addToCartButtonDisabledClass ) ;
103
+ addToCartButton . attr ( 'title' , this . options . addToCartButtonTextWhileAdding ) ;
104
+ addToCartButton . find ( 'span' ) . text ( this . options . addToCartButtonTextWhileAdding ) ;
105
+ } ,
106
+
107
+ enableAddToCartButton : function ( form ) {
108
+ var self = this ,
109
+ addToCartButton = $ ( form ) . find ( this . options . addToCartButtonSelector ) ;
110
+
111
+ addToCartButton . find ( 'span' ) . text ( this . options . addToCartButtonTextAdded ) ;
112
+ addToCartButton . attr ( 'title' , this . options . addToCartButtonTextAdded ) ;
113
+
114
+ setTimeout ( function ( ) {
115
+ addToCartButton . removeClass ( self . options . addToCartButtonDisabledClass ) ;
116
+ addToCartButton . find ( 'span' ) . text ( self . options . addToCartButtonTextDefault ) ;
117
+ addToCartButton . attr ( 'title' , self . options . addToCartButtonTextDefault ) ;
118
+ } , 1000 ) ;
87
119
}
88
120
} ) ;
89
121
0 commit comments