9
9
10
10
use Magento \Checkout \Model \Cart \RequestQuantityProcessor ;
11
11
use Magento \Checkout \Model \Session as CheckoutSession ;
12
+ use Magento \Framework \App \Action \Action ;
12
13
use Magento \Framework \App \Action \Context ;
14
+ use Magento \Framework \App \Action \HttpPostActionInterface ;
13
15
use Magento \Framework \Data \Form \FormKey \Validator as FormKeyValidator ;
14
16
use Magento \Framework \Exception \LocalizedException ;
15
17
use Magento \Framework \Exception \NotFoundException ;
16
18
use Magento \Framework \Serialize \Serializer \Json ;
17
19
use Magento \Quote \Model \Quote \Item ;
18
- use Magento \Framework \App \Action \Action ;
19
- use Magento \Framework \App \Action \HttpPostActionInterface ;
20
20
use Psr \Log \LoggerInterface ;
21
21
22
22
/**
26
26
*/
27
27
class UpdateItemQty extends Action implements HttpPostActionInterface
28
28
{
29
+
29
30
/**
30
31
* @var RequestQuantityProcessor
31
32
*/
@@ -76,9 +77,7 @@ public function __construct(
76
77
$ this ->json = $ json ;
77
78
$ this ->logger = $ logger ;
78
79
parent ::__construct ($ context );
79
-
80
- }
81
-
80
+ }//end __construct()
82
81
83
82
/**
84
83
* Controller execute method
@@ -96,11 +95,11 @@ public function execute()
96
95
$ this ->validateCartData ($ cartData );
97
96
98
97
$ cartData = $ this ->quantityProcessor ->process ($ cartData );
99
- $ quote = $ this ->checkoutSession ->getQuote ();
98
+ $ quote = $ this ->checkoutSession ->getQuote ();
100
99
101
100
foreach ($ cartData as $ itemId => $ itemInfo ) {
102
101
$ item = $ quote ->getItemById ($ itemId );
103
- $ qty = isset ($ itemInfo ['qty ' ]) ? (double )$ itemInfo ['qty ' ] : 0 ;
102
+ $ qty = isset ($ itemInfo ['qty ' ]) ? (double ) $ itemInfo ['qty ' ] : 0 ;
104
103
if ($ item ) {
105
104
$ this ->updateItemQuantity ($ item , $ qty );
106
105
}
@@ -112,8 +111,8 @@ public function execute()
112
111
} catch (\Exception $ e ) {
113
112
$ this ->logger ->critical ($ e ->getMessage ());
114
113
$ this ->jsonResponse ('Something went wrong while saving the page. Please refresh the page and try again. ' );
115
- }
116
- }
114
+ }//end try
115
+ }//end execute()
117
116
118
117
/**
119
118
* Updates quote item quantity.
@@ -135,7 +134,7 @@ private function updateItemQuantity(Item $item, float $qty)
135
134
throw new LocalizedException (__ ($ item ->getMessage ()));
136
135
}
137
136
}
138
- }
137
+ }//end updateItemQuantity()
139
138
140
139
/**
141
140
* JSON response builder.
@@ -149,7 +148,7 @@ private function jsonResponse(string $error = '')
149
148
$ this ->getResponse ()->representJson (
150
149
$ this ->json ->serialize ($ this ->getResponseData ($ error ))
151
150
);
152
- }
151
+ }//end jsonResponse()
153
152
154
153
/**
155
154
* Returns response data.
@@ -160,19 +159,17 @@ private function jsonResponse(string $error = '')
160
159
*/
161
160
private function getResponseData (string $ error = '' ): array
162
161
{
163
- $ response = [
164
- 'success ' => true ,
165
- ];
162
+ $ response = ['success ' => true ];
166
163
167
164
if (!empty ($ error )) {
168
165
$ response = [
169
- 'success ' => false ,
166
+ 'success ' => false ,
170
167
'error_message ' => $ error ,
171
168
];
172
169
}
173
170
174
171
return $ response ;
175
- }
172
+ }//end getResponseData()
176
173
177
174
/**
178
175
* Validates the Request HTTP method
@@ -184,12 +181,9 @@ private function getResponseData(string $error = ''): array
184
181
private function validateRequest ()
185
182
{
186
183
if ($ this ->getRequest ()->isPost () === false ) {
187
- throw new NotFoundException (
188
- __ ('Page Not Found ' )
189
- );
184
+ throw new NotFoundException (__ ('Page Not Found ' ));
190
185
}
191
-
192
- }
186
+ }//end validateRequest()
193
187
194
188
/**
195
189
* Validates form key
@@ -205,8 +199,7 @@ private function validateFormKey()
205
199
__ ('Something went wrong while saving the page. Please refresh the page and try again. ' )
206
200
);
207
201
}
208
-
209
- }
202
+ }//end validateFormKey()
210
203
211
204
/**
212
205
* Validates cart data
@@ -224,6 +217,5 @@ private function validateCartData($cartData = null)
224
217
__ ('Something went wrong while saving the page. Please refresh the page and try again. ' )
225
218
);
226
219
}
227
-
228
- }
229
- }
220
+ }//end validateCartData()
221
+ }//end class
0 commit comments