7
7
8
8
use Magento \Customer \CustomerData \SectionSourceInterface ;
9
9
use Magento \Catalog \Api \ProductRepositoryInterface ;
10
+ use Magento \Framework \Exception \NoSuchEntityException ;
10
11
use Psr \Log \LoggerInterface ;
11
12
use Magento \Framework \App \ObjectManager ;
12
13
13
14
/**
14
15
* Returns information for "Recently Ordered" widget.
15
16
* It contains list of 5 salable products from the last placed order.
16
17
* Qty of products to display is limited by LastOrderedItems::SIDEBAR_ORDER_LIMIT constant.
18
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
19
*/
18
20
class LastOrderedItems implements SectionSourceInterface
19
21
{
@@ -74,6 +76,7 @@ class LastOrderedItems implements SectionSourceInterface
74
76
* @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
75
77
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
76
78
* @param ProductRepositoryInterface $productRepository
79
+ * @param LoggerInterface|null $logger
77
80
*/
78
81
public function __construct (
79
82
\Magento \Sales \Model \ResourceModel \Order \CollectionFactory $ orderCollectionFactory ,
@@ -90,7 +93,7 @@ public function __construct(
90
93
$ this ->stockRegistry = $ stockRegistry ;
91
94
$ this ->_storeManager = $ storeManager ;
92
95
$ this ->productRepository = $ productRepository ;
93
- $ this ->logger = $ logger ?: ObjectManager::getInstance ()->get (LoggerInterface::class);
96
+ $ this ->logger = $ logger ?? ObjectManager::getInstance ()->get (LoggerInterface::class);
94
97
}
95
98
96
99
/**
@@ -133,9 +136,9 @@ protected function getItems()
133
136
false ,
134
137
$ this ->_storeManager ->getStore ()->getId ()
135
138
);
136
- }catch (\ Magento \ Framework \ Exception \ NoSuchEntityException $ e ) {
137
- $ this ->logger ->critical ($ e );
138
- break ;
139
+ } catch (NoSuchEntityException $ noEntityException ) {
140
+ $ this ->logger ->critical ($ noEntityException );
141
+ continue ;
139
142
}
140
143
if (isset ($ product ) && in_array ($ website , $ product ->getWebsiteIds ())) {
141
144
$ url = $ product ->isVisibleInSiteVisibility () ? $ product ->getProductUrl () : null ;
@@ -166,7 +169,7 @@ protected function isItemAvailableForReorder(\Magento\Sales\Model\Order\Item $or
166
169
$ orderItem ->getStore ()->getWebsiteId ()
167
170
);
168
171
return $ stockItem ->getIsInStock ();
169
- } catch (\ Magento \ Framework \ Exception \ NoSuchEntityException $ noEntityException ) {
172
+ } catch (NoSuchEntityException $ noEntityException ) {
170
173
return false ;
171
174
}
172
175
}
0 commit comments