Skip to content

Commit 618c9d7

Browse files
author
Stanislav Idolov
authored
MAGETWO-86399: Improvement: Magento\Sales\Helper\Guest refactoring and bugfix #12893
2 parents 112beee + 827970b commit 618c9d7

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

app/code/Magento/Sales/Helper/Guest.php

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Guest extends \Magento\Framework\App\Helper\AbstractHelper
8383
/**
8484
* @var \Magento\Store\Model\StoreManagerInterface
8585
*/
86-
private $_storeManager;
86+
private $storeManager;
8787

8888
/**
8989
* @var string
@@ -119,7 +119,7 @@ public function __construct(
119119
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria = null
120120
) {
121121
$this->coreRegistry = $coreRegistry;
122-
$this->_storeManager = $storeManager;
122+
$this->storeManager = $storeManager;
123123
$this->customerSession = $customerSession;
124124
$this->cookieManager = $cookieManager;
125125
$this->cookieMetadataFactory = $cookieMetadataFactory;
@@ -158,9 +158,10 @@ public function loadValidOrder(App\RequestInterface $request)
158158
// It is unique place in the class that process exception and only InputException. It is need because by
159159
// input data we found order and one more InputException could be throws deeper in stack trace
160160
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))
162164
? $this->loadFromPost($post) : $this->loadFromCookie($fromCookie);
163-
$this->validateOrderStoreId($order->getStoreId());
164165
$this->coreRegistry->register('current_order', $order);
165166
return true;
166167
} catch (InputException $e) {
@@ -186,7 +187,7 @@ public function getBreadcrumbs(\Magento\Framework\View\Result\Page $resultPage)
186187
[
187188
'label' => __('Home'),
188189
'title' => __('Go to Home Page'),
189-
'link' => $this->_storeManager->getStore()->getBaseUrl()
190+
'link' => $this->storeManager->getStore()->getBaseUrl()
190191
]
191192
);
192193
$breadcrumbs->addCrumb(
@@ -247,12 +248,9 @@ private function loadFromCookie($fromCookie)
247248
*/
248249
private function loadFromPost(array $postData)
249250
{
250-
if ($this->hasPostDataEmptyFields($postData)) {
251-
throw new InputException();
252-
}
253251
/** @var $order \Magento\Sales\Model\Order */
254252
$order = $this->getOrderRecord($postData['oar_order_id']);
255-
if (!$this->compareSoredBillingDataWithInput($order, $postData)) {
253+
if (!$this->compareStoredBillingDataWithInput($order, $postData)) {
256254
throw new InputException(__('You entered incorrect data. Please try again.'));
257255
}
258256
$toCookie = base64_encode($order->getProtectCode() . ':' . $postData['oar_order_id']);
@@ -267,7 +265,7 @@ private function loadFromPost(array $postData)
267265
* @param array $postData
268266
* @return bool
269267
*/
270-
private function compareSoredBillingDataWithInput(Order $order, array $postData)
268+
private function compareStoredBillingDataWithInput(Order $order, array $postData)
271269
{
272270
$type = $postData['oar_type'];
273271
$email = $postData['oar_email'];
@@ -288,7 +286,7 @@ private function compareSoredBillingDataWithInput(Order $order, array $postData)
288286
private function hasPostDataEmptyFields(array $postData)
289287
{
290288
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()) ||
292290
!in_array($postData['oar_type'], ['email', 'zip'], true) ||
293291
('email' === $postData['oar_type'] && empty($postData['oar_email'])) ||
294292
('zip' === $postData['oar_type'] && empty($postData['oar_zip']));
@@ -306,26 +304,15 @@ private function getOrderRecord($incrementId)
306304
$records = $this->orderRepository->getList(
307305
$this->searchCriteriaBuilder
308306
->addFilter('increment_id', $incrementId)
307+
->addFilter('store_id', $this->storeManager->getStore()->getId())
309308
->create()
310309
);
311-
if ($records->getTotalCount() < 1) {
312-
throw new InputException(__($this->inputExceptionMessage));
313-
}
314-
$items = $records->getItems();
315-
return array_shift($items);
316-
}
317310

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)) {
328313
throw new InputException(__($this->inputExceptionMessage));
329314
}
315+
316+
return array_shift($items);
330317
}
331318
}

0 commit comments

Comments
 (0)