@@ -100,6 +100,10 @@ public function addEavAttributes(array $attributeCodes) : void
100100 */
101101 public function getProductBySku (string $ sku , ContextInterface $ context = null ) : array
102102 {
103+ if (isset ($ this ->productList [$ sku ])) {
104+ return $ this ->productList [$ sku ];
105+ }
106+
103107 $ this ->fetch ($ context );
104108
105109 if (!isset ($ this ->productList [$ sku ])) {
@@ -113,13 +117,17 @@ public function getProductBySku(string $sku, ContextInterface $context = null) :
113117 * Fetch product data and return in array format. Keys for products will be their skus.
114118 *
115119 * @param null|ContextInterface $context
116- * @return array
117120 */
118- private function fetch (ContextInterface $ context = null ) : array
121+ private function fetch (ContextInterface $ context = null ): void
119122 {
123+ if (empty ($ this ->productSkus )) {
124+ return ;
125+ }
126+
120127 $ skusToFetch = array_diff ($ this ->productSkus , array_keys ($ this ->productList ));
121- if (empty ($ this ->productSkus ) || empty ($ skusToFetch )) {
122- return $ this ->productList ;
128+
129+ if (empty ($ skusToFetch )) {
130+ return ;
123131 }
124132
125133 $ this ->searchCriteriaBuilder ->addFilter (ProductInterface::SKU , $ skusToFetch , 'in ' );
@@ -135,7 +143,5 @@ private function fetch(ContextInterface $context = null) : array
135143 foreach ($ result ->getItems () as $ product ) {
136144 $ this ->productList [$ product ->getSku ()] = ['model ' => $ product ];
137145 }
138-
139- return $ this ->productList ;
140146 }
141147}
0 commit comments