@@ -100,6 +100,10 @@ public function addEavAttributes(array $attributeCodes) : void
100
100
*/
101
101
public function getProductBySku (string $ sku , ContextInterface $ context = null ) : array
102
102
{
103
+ if (isset ($ this ->productList [$ sku ])) {
104
+ return $ this ->productList [$ sku ];
105
+ }
106
+
103
107
$ this ->fetch ($ context );
104
108
105
109
if (!isset ($ this ->productList [$ sku ])) {
@@ -113,13 +117,17 @@ public function getProductBySku(string $sku, ContextInterface $context = null) :
113
117
* Fetch product data and return in array format. Keys for products will be their skus.
114
118
*
115
119
* @param null|ContextInterface $context
116
- * @return array
117
120
*/
118
- private function fetch (ContextInterface $ context = null ) : array
121
+ private function fetch (ContextInterface $ context = null ): void
119
122
{
123
+ if (empty ($ this ->productSkus )) {
124
+ return ;
125
+ }
126
+
120
127
$ 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 ;
123
131
}
124
132
125
133
$ this ->searchCriteriaBuilder ->addFilter (ProductInterface::SKU , $ skusToFetch , 'in ' );
@@ -135,7 +143,5 @@ private function fetch(ContextInterface $context = null) : array
135
143
foreach ($ result ->getItems () as $ product ) {
136
144
$ this ->productList [$ product ->getSku ()] = ['model ' => $ product ];
137
145
}
138
-
139
- return $ this ->productList ;
140
146
}
141
147
}
0 commit comments