Skip to content

Commit f6198ad

Browse files
committed
MAGETWO-89337: "My Requisition Lists" option is absent in header menu.
1 parent c42130d commit f6198ad

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

app/code/Magento/Sales/CustomerData/LastOrderedItems.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Magento\Customer\CustomerData\SectionSourceInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Psr\Log\LoggerInterface;
11+
use Magento\Framework\App\ObjectManager;
1012

1113
/**
1214
* Returns information for "Recently Ordered" widget.
@@ -60,6 +62,11 @@ class LastOrderedItems implements SectionSourceInterface
6062
*/
6163
private $productRepository;
6264

65+
/**
66+
* @var LoggerInterface
67+
*/
68+
private $logger;
69+
6370
/**
6471
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
6572
* @param \Magento\Sales\Model\Order\Config $orderConfig
@@ -74,14 +81,16 @@ public function __construct(
7481
\Magento\Customer\Model\Session $customerSession,
7582
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
7683
\Magento\Store\Model\StoreManagerInterface $storeManager,
77-
ProductRepositoryInterface $productRepository
84+
ProductRepositoryInterface $productRepository,
85+
LoggerInterface $logger = null
7886
) {
7987
$this->_orderCollectionFactory = $orderCollectionFactory;
8088
$this->_orderConfig = $orderConfig;
8189
$this->_customerSession = $customerSession;
8290
$this->stockRegistry = $stockRegistry;
8391
$this->_storeManager = $storeManager;
8492
$this->productRepository = $productRepository;
93+
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
8594
}
8695

8796
/**
@@ -118,12 +127,17 @@ protected function getItems()
118127
/** @var \Magento\Sales\Model\Order\Item $item */
119128
foreach ($order->getParentItemsRandomCollection($limit) as $item) {
120129
/** @var \Magento\Catalog\Model\Product $product */
121-
$product = $this->productRepository->getById(
122-
$item->getProductId(),
123-
false,
124-
$this->_storeManager->getStore()->getId()
125-
);
126-
if ($product && in_array($website, $product->getWebsiteIds())) {
130+
try {
131+
$product = $this->productRepository->getById(
132+
$item->getProductId(),
133+
false,
134+
$this->_storeManager->getStore()->getId()
135+
);
136+
}catch (\Magento\Framework\Exception\NoSuchEntityException $e){
137+
$this->logger->critical($e);
138+
break;
139+
}
140+
if (isset($product) && in_array($website, $product->getWebsiteIds())) {
127141
$url = $product->isVisibleInSiteVisibility() ? $product->getProductUrl() : null;
128142
$items[] = [
129143
'id' => $item->getId(),

0 commit comments

Comments
 (0)