20
20
use Psr \Log \LoggerInterface ;
21
21
22
22
/**
23
- * Class UpdateItemQty
23
+ * UpdateItemQty ajax request
24
24
*
25
25
* @package Magento\Checkout\Controller\Cart
26
26
*/
@@ -55,12 +55,12 @@ class UpdateItemQty extends Action implements HttpPostActionInterface
55
55
/**
56
56
* UpdateItemQty constructor
57
57
*
58
- * @param Context $context Parent dependency
58
+ * @param Context $context
59
59
* @param RequestQuantityProcessor $quantityProcessor Request quantity
60
- * @param FormKeyValidator $formKeyValidator Form validator
61
- * @param CheckoutSession $checkoutSession Session
62
- * @param Json $json Json serializer
63
- * @param LoggerInterface $logger Logger
60
+ * @param FormKeyValidator $formKeyValidator Form validator
61
+ * @param CheckoutSession $checkoutSession Session
62
+ * @param Json $json Json serializer
63
+ * @param LoggerInterface $logger Logger
64
64
*/
65
65
66
66
public function __construct (
@@ -72,12 +72,12 @@ public function __construct(
72
72
LoggerInterface $ logger
73
73
) {
74
74
$ this ->quantityProcessor = $ quantityProcessor ;
75
- $ this ->formKeyValidator = $ formKeyValidator ;
76
- $ this ->checkoutSession = $ checkoutSession ;
77
- $ this ->json = $ json ;
78
- $ this ->logger = $ logger ;
75
+ $ this ->formKeyValidator = $ formKeyValidator ;
76
+ $ this ->checkoutSession = $ checkoutSession ;
77
+ $ this ->json = $ json ;
78
+ $ this ->logger = $ logger ;
79
79
parent ::__construct ($ context );
80
- }//end __construct()
80
+ }
81
81
82
82
/**
83
83
* Controller execute method
@@ -95,11 +95,11 @@ public function execute()
95
95
$ this ->validateCartData ($ cartData );
96
96
97
97
$ cartData = $ this ->quantityProcessor ->process ($ cartData );
98
- $ quote = $ this ->checkoutSession ->getQuote ();
98
+ $ quote = $ this ->checkoutSession ->getQuote ();
99
99
100
100
foreach ($ cartData as $ itemId => $ itemInfo ) {
101
101
$ item = $ quote ->getItemById ($ itemId );
102
- $ qty = isset ($ itemInfo ['qty ' ]) ? (double ) $ itemInfo ['qty ' ] : 0 ;
102
+ $ qty = isset ($ itemInfo ['qty ' ]) ? (double ) $ itemInfo ['qty ' ] : 0 ;
103
103
if ($ item ) {
104
104
$ this ->updateItemQuantity ($ item , $ qty );
105
105
}
@@ -111,18 +111,16 @@ public function execute()
111
111
} catch (\Exception $ e ) {
112
112
$ this ->logger ->critical ($ e ->getMessage ());
113
113
$ this ->jsonResponse ('Something went wrong while saving the page. Please refresh the page and try again. ' );
114
- }//end try
115
- }//end execute()
114
+ }
115
+ }
116
116
117
117
/**
118
118
* Updates quote item quantity.
119
119
*
120
- * @param Item $item
120
+ * @param Item $item
121
121
* @param float $qty
122
- *
123
- * @throws LocalizedException
124
- *
125
122
* @return void
123
+ * @throws LocalizedException
126
124
*/
127
125
private function updateItemQuantity (Item $ item , float $ qty )
128
126
{
@@ -134,27 +132,25 @@ private function updateItemQuantity(Item $item, float $qty)
134
132
throw new LocalizedException (__ ($ item ->getMessage ()));
135
133
}
136
134
}
137
- }//end updateItemQuantity()
135
+ }
138
136
139
137
/**
140
138
* JSON response builder.
141
139
*
142
140
* @param string $error
143
- *
144
141
* @return void
145
142
*/
146
143
private function jsonResponse (string $ error = '' )
147
144
{
148
145
$ this ->getResponse ()->representJson (
149
146
$ this ->json ->serialize ($ this ->getResponseData ($ error ))
150
147
);
151
- }//end jsonResponse()
148
+ }
152
149
153
150
/**
154
151
* Returns response data.
155
152
*
156
153
* @param string $error
157
- *
158
154
* @return array
159
155
*/
160
156
private function getResponseData (string $ error = '' ): array
@@ -163,34 +159,32 @@ private function getResponseData(string $error = ''): array
163
159
164
160
if (!empty ($ error )) {
165
161
$ response = [
166
- 'success ' => false ,
162
+ 'success ' => false ,
167
163
'error_message ' => $ error ,
168
164
];
169
165
}
170
166
171
167
return $ response ;
172
- }//end getResponseData()
168
+ }
173
169
174
170
/**
175
171
* Validates the Request HTTP method
176
172
*
177
- * @throws NotFoundException
178
- *
179
173
* @return void
174
+ * @throws NotFoundException
180
175
*/
181
176
private function validateRequest ()
182
177
{
183
178
if ($ this ->getRequest ()->isPost () === false ) {
184
179
throw new NotFoundException (__ ('Page Not Found ' ));
185
180
}
186
- }//end validateRequest()
181
+ }
187
182
188
183
/**
189
184
* Validates form key
190
185
*
191
- * @throws LocalizedException
192
- *
193
186
* @return void
187
+ * @throws LocalizedException
194
188
*/
195
189
private function validateFormKey ()
196
190
{
@@ -199,16 +193,14 @@ private function validateFormKey()
199
193
__ ('Something went wrong while saving the page. Please refresh the page and try again. ' )
200
194
);
201
195
}
202
- }//end validateFormKey()
196
+ }
203
197
204
198
/**
205
199
* Validates cart data
206
200
*
207
201
* @param array|null $cartData
208
- *
209
- * @throws LocalizedException
210
- *
211
202
* @return void
203
+ * @throws LocalizedException
212
204
*/
213
205
private function validateCartData ($ cartData = null )
214
206
{
@@ -217,5 +209,5 @@ private function validateCartData($cartData = null)
217
209
__ ('Something went wrong while saving the page. Please refresh the page and try again. ' )
218
210
);
219
211
}
220
- }//end validateCartData()
221
- }//end class
212
+ }
213
+ }
0 commit comments