1
- define ( [
2
- 'jquery' ,
3
- 'mage/translate' ,
4
- 'jquery/ui'
5
- ] , function ( $ ) {
6
- 'use strict' ;
1
+ define ( [ "jquery" , "mage/translate" , "jquery/ui" ] , function ( $ ) {
2
+ "use strict" ;
7
3
8
- var config = window [ ' checkout' ] [ ' add_to_cart_notification' ] ;
4
+ var config = window [ " checkout" ] [ " add_to_cart_notification" ] ;
9
5
10
6
var mixin = {
11
7
/**
@@ -17,46 +13,70 @@ define([
17
13
18
14
this . _super ( form ) ;
19
15
20
- self . element . find ( '.message.error' ) . remove ( ) ;
21
-
22
- $ . when (
23
- this . productPromise ( productId ) ,
24
- this . cartPromise ( )
25
- ) . then ( function ( data ) {
26
- var product = data [ 0 ] ;
27
- var title = $ . mage . __ ( 'Added To Bag' ) ;
28
- var message = $ . mage . __ ( 'You added %1 to your <a href="%2">shopping cart</a>.' )
29
- . replace ( '%1' , product [ 'name' ] )
30
- . replace ( '%2' , product [ 'cart_url' ] ) ;
31
-
32
- $ ( 'body' ) . append (
33
- '<div id="add_to_cart_notification" class="add-to-cart">' +
34
- '<div class="btn-close"></div>' +
35
- '<img class="notification-image" src="' + product [ 'image' ] + '" alt="' + product [ 'name' ] + '" title="' + product [ 'name' ] + '">' +
36
- '<div class="notification-content">' +
37
- '<p class="notification-title">' + title + '</p>' +
38
- '<p class="notification-message">' + message + '</p>' +
39
- '</div>' +
40
- '</div>'
41
- ) ;
42
-
43
- $ ( "#add_to_cart_notification" ) . find ( ".btn-close" ) . click ( function ( ) {
44
- self . removeNotification ( ) ;
45
- } ) ;
46
-
47
- setTimeout ( function ( ) {
48
- self . removeNotification ( ) ;
49
- } , config [ 'notificationLifetime' ] ) ;
50
- } , function ( messages ) {
51
- if ( self . element . find ( 'div.mage-error' ) . filter ( ':visible' ) . length > 0 ) {
52
- return ;
16
+ self . element . find ( ".message.error" ) . remove ( ) ;
17
+
18
+ $ . when ( this . productPromise ( productId ) , this . cartPromise ( ) ) . then (
19
+ function ( data ) {
20
+ var product = data [ 0 ] ;
21
+ var title = $ . mage . __ ( "Added To Bag" ) ;
22
+ var message = $ . mage . __ ( 'You added %1 to your <a href="%2">shopping cart</a>.' )
23
+ . replace ( "%1" , product [ "name" ] )
24
+ . replace ( "%2" , product [ "cart_url" ] ) ;
25
+
26
+ var modalCloseBtn =
27
+ '<button class="action-close"><span>' + $ . mage . __ ( "Close" ) + "</span></button>" ;
28
+
29
+ // TODO: get width and height from product image xml config
30
+ var modalImage =
31
+ '<img class="notification-image" src="' +
32
+ product [ "image" ] +
33
+ '" alt="' +
34
+ product [ "name" ] +
35
+ '" width="80" height="80">' ;
36
+
37
+ $ ( "body" ) . append (
38
+ '<div id="add_to_cart_notification" role="dialog" class="modal-custom modal-added-to-cart">' +
39
+ '<div class="modal-header">' +
40
+ modalCloseBtn +
41
+ "</div>" +
42
+ '<div class="modal-content"><div class="product-image">' +
43
+ modalImage +
44
+ '</div><div class="product-content">' +
45
+ '<div class="block-title">' +
46
+ '<strong id="add_to_cart_notification-heading" role="heading" aria-level="2">' +
47
+ title +
48
+ "</strong></div>" +
49
+ '<div class="notification-message">' +
50
+ message +
51
+ "</div>" +
52
+ "</div></div></div>"
53
+ ) ;
54
+
55
+ $ ( "#add_to_cart_notification" )
56
+ . find ( ".action-close" )
57
+ . click ( function ( ) {
58
+ self . removeNotification ( ) ;
59
+ } ) ;
60
+
61
+ setTimeout ( function ( ) {
62
+ self . removeNotification ( ) ;
63
+ } , config [ "notificationLifetime" ] ) ;
64
+ } ,
65
+ function ( messages ) {
66
+ if ( self . element . find ( "div.mage-error" ) . filter ( ":visible" ) . length > 0 ) {
67
+ return ;
68
+ }
69
+
70
+ var button = self . element . find ( "button.tocart" ) ;
71
+ messages . forEach ( function ( message ) {
72
+ button . after (
73
+ '<div class="message info message-add-to-cart"><div>' +
74
+ message . text +
75
+ "</div></div>"
76
+ ) ;
77
+ } ) ;
53
78
}
54
-
55
- var button = self . element . find ( 'button.tocart' ) ;
56
- messages . forEach ( function ( message ) {
57
- button . after ( '<p class="message error add-to-cart-error">' + message . text + '</p>' ) ;
58
- } ) ;
59
- } ) ;
79
+ ) ;
60
80
} ,
61
81
62
82
removeNotification : function ( ) {
@@ -67,40 +87,40 @@ define([
67
87
68
88
productPromise : function ( productId ) {
69
89
return $ . get ( {
70
- url : window [ ' BASE_URL' ] + ' /cart_notification/data/product/product_id/' + productId ,
90
+ url : window [ " BASE_URL" ] + " /cart_notification/data/product/product_id/" + productId ,
71
91
cache : true
72
92
} ) ;
73
93
} ,
74
94
75
95
cartPromise : function ( ) {
76
96
var dfd = $ . Deferred ( ) ;
77
97
78
- $ ( document ) . on ( ' ajaxSuccess' , function ( event , request , settings ) {
79
- if ( settings . url . indexOf ( ' /checkout/cart/add' ) === - 1 ) {
98
+ $ ( document ) . on ( " ajaxSuccess" , function ( event , request , settings ) {
99
+ if ( settings . url . indexOf ( " /checkout/cart/add" ) === - 1 ) {
80
100
return ;
81
101
}
82
102
83
103
if ( request . responseJSON . error_messages ) {
84
104
dfd . reject ( request . responseJSON . error_messages ) ;
85
- $ ( document ) . off ( ' ajaxSuccess' ) ;
105
+ $ ( document ) . off ( " ajaxSuccess" ) ;
86
106
return ;
87
107
}
88
108
89
109
dfd . resolve ( ) ;
90
- $ ( document ) . off ( ' ajaxSuccess' ) ;
110
+ $ ( document ) . off ( " ajaxSuccess" ) ;
91
111
} ) ;
92
112
93
113
return dfd . promise ( ) ;
94
114
}
95
115
} ;
96
116
97
117
return function ( target ) {
98
- if ( ! config [ ' enabled' ] ) {
118
+ if ( ! config [ " enabled" ] ) {
99
119
return target ;
100
120
}
101
121
102
- $ . widget ( ' mooore.catalogAddToCart' , target , mixin ) ;
122
+ $ . widget ( " mooore.catalogAddToCart" , target , mixin ) ;
103
123
104
124
return $ . mooore . catalogAddToCart ;
105
- }
125
+ } ;
106
126
} ) ;
0 commit comments