@@ -83,7 +83,7 @@ class Guest extends \Magento\Framework\App\Helper\AbstractHelper
83
83
/**
84
84
* @var \Magento\Store\Model\StoreManagerInterface
85
85
*/
86
- private $ _storeManager ;
86
+ private $ storeManager ;
87
87
88
88
/**
89
89
* @var string
@@ -119,7 +119,7 @@ public function __construct(
119
119
\Magento \Framework \Api \SearchCriteriaBuilder $ searchCriteria = null
120
120
) {
121
121
$ this ->coreRegistry = $ coreRegistry ;
122
- $ this ->_storeManager = $ storeManager ;
122
+ $ this ->storeManager = $ storeManager ;
123
123
$ this ->customerSession = $ customerSession ;
124
124
$ this ->cookieManager = $ cookieManager ;
125
125
$ this ->cookieMetadataFactory = $ cookieMetadataFactory ;
@@ -158,9 +158,10 @@ public function loadValidOrder(App\RequestInterface $request)
158
158
// It is unique place in the class that process exception and only InputException. It is need because by
159
159
// input data we found order and one more InputException could be throws deeper in stack trace
160
160
try {
161
- $ order = (!empty ($ post ) && isset ($ post ['oar_order_id ' ], $ post ['oar_type ' ]))
161
+ $ order = (!empty ($ post )
162
+ && isset ($ post ['oar_order_id ' ], $ post ['oar_type ' ])
163
+ && !$ this ->hasPostDataEmptyFields ($ post ))
162
164
? $ this ->loadFromPost ($ post ) : $ this ->loadFromCookie ($ fromCookie );
163
- $ this ->validateOrderStoreId ($ order ->getStoreId ());
164
165
$ this ->coreRegistry ->register ('current_order ' , $ order );
165
166
return true ;
166
167
} catch (InputException $ e ) {
@@ -186,7 +187,7 @@ public function getBreadcrumbs(\Magento\Framework\View\Result\Page $resultPage)
186
187
[
187
188
'label ' => __ ('Home ' ),
188
189
'title ' => __ ('Go to Home Page ' ),
189
- 'link ' => $ this ->_storeManager ->getStore ()->getBaseUrl ()
190
+ 'link ' => $ this ->storeManager ->getStore ()->getBaseUrl ()
190
191
]
191
192
);
192
193
$ breadcrumbs ->addCrumb (
@@ -247,12 +248,9 @@ private function loadFromCookie($fromCookie)
247
248
*/
248
249
private function loadFromPost (array $ postData )
249
250
{
250
- if ($ this ->hasPostDataEmptyFields ($ postData )) {
251
- throw new InputException ();
252
- }
253
251
/** @var $order \Magento\Sales\Model\Order */
254
252
$ order = $ this ->getOrderRecord ($ postData ['oar_order_id ' ]);
255
- if (!$ this ->compareSoredBillingDataWithInput ($ order , $ postData )) {
253
+ if (!$ this ->compareStoredBillingDataWithInput ($ order , $ postData )) {
256
254
throw new InputException (__ ('You entered incorrect data. Please try again. ' ));
257
255
}
258
256
$ toCookie = base64_encode ($ order ->getProtectCode () . ': ' . $ postData ['oar_order_id ' ]);
@@ -267,7 +265,7 @@ private function loadFromPost(array $postData)
267
265
* @param array $postData
268
266
* @return bool
269
267
*/
270
- private function compareSoredBillingDataWithInput (Order $ order , array $ postData )
268
+ private function compareStoredBillingDataWithInput (Order $ order , array $ postData )
271
269
{
272
270
$ type = $ postData ['oar_type ' ];
273
271
$ email = $ postData ['oar_email ' ];
@@ -288,7 +286,7 @@ private function compareSoredBillingDataWithInput(Order $order, array $postData)
288
286
private function hasPostDataEmptyFields (array $ postData )
289
287
{
290
288
return empty ($ postData ['oar_order_id ' ]) || empty ($ postData ['oar_billing_lastname ' ]) ||
291
- empty ($ postData ['oar_type ' ]) || empty ($ this ->_storeManager ->getStore ()->getId ()) ||
289
+ empty ($ postData ['oar_type ' ]) || empty ($ this ->storeManager ->getStore ()->getId ()) ||
292
290
!in_array ($ postData ['oar_type ' ], ['email ' , 'zip ' ], true ) ||
293
291
('email ' === $ postData ['oar_type ' ] && empty ($ postData ['oar_email ' ])) ||
294
292
('zip ' === $ postData ['oar_type ' ] && empty ($ postData ['oar_zip ' ]));
@@ -306,26 +304,15 @@ private function getOrderRecord($incrementId)
306
304
$ records = $ this ->orderRepository ->getList (
307
305
$ this ->searchCriteriaBuilder
308
306
->addFilter ('increment_id ' , $ incrementId )
307
+ ->addFilter ('store_id ' , $ this ->storeManager ->getStore ()->getId ())
309
308
->create ()
310
309
);
311
- if ($ records ->getTotalCount () < 1 ) {
312
- throw new InputException (__ ($ this ->inputExceptionMessage ));
313
- }
314
- $ items = $ records ->getItems ();
315
- return array_shift ($ items );
316
- }
317
310
318
- /**
319
- * Check that store_id from order are equals with system
320
- *
321
- * @param int $orderStoreId
322
- * @return void
323
- * @throws InputException
324
- */
325
- private function validateOrderStoreId ($ orderStoreId )
326
- {
327
- if ($ orderStoreId != $ this ->_storeManager ->getStore ()->getId ()) {
311
+ $ items = $ records ->getItems ();
312
+ if (empty ($ items )) {
328
313
throw new InputException (__ ($ this ->inputExceptionMessage ));
329
314
}
315
+
316
+ return array_shift ($ items );
330
317
}
331
318
}
0 commit comments