@@ -62,10 +62,7 @@ public function __construct(
6262 */
6363 public function addProductSku (string $ sku ) : void
6464 {
65- if (!in_array ($ sku , $ this ->productSkus ) && !empty ($ this ->productList )) {
66- $ this ->productList = [];
67- $ this ->productSkus [] = $ sku ;
68- } elseif (!in_array ($ sku , $ this ->productSkus )) {
65+ if (!in_array ($ sku , $ this ->productSkus )) {
6966 $ this ->productSkus [] = $ sku ;
7067 }
7168 }
@@ -79,12 +76,7 @@ public function addProductSku(string $sku) : void
7976 public function addProductSkus (array $ skus ) : void
8077 {
8178 foreach ($ skus as $ sku ) {
82- if (!in_array ($ sku , $ this ->productSkus ) && !empty ($ this ->productList )) {
83- $ this ->productList = [];
84- $ this ->productSkus [] = $ sku ;
85- } elseif (!in_array ($ sku , $ this ->productSkus )) {
86- $ this ->productSkus [] = $ sku ;
87- }
79+ $ this ->addProductSku ($ sku );
8880 }
8981 }
9082
@@ -108,13 +100,13 @@ public function addEavAttributes(array $attributeCodes) : void
108100 */
109101 public function getProductBySku (string $ sku , ContextInterface $ context = null ) : array
110102 {
111- $ products = $ this ->fetch ($ context );
103+ $ this ->fetch ($ context );
112104
113- if (!isset ($ products [$ sku ])) {
105+ if (!isset ($ this -> productList [$ sku ])) {
114106 return [];
115107 }
116108
117- return $ products [$ sku ];
109+ return $ this -> productList [$ sku ];
118110 }
119111
120112 /**
@@ -125,11 +117,12 @@ public function getProductBySku(string $sku, ContextInterface $context = null) :
125117 */
126118 private function fetch (ContextInterface $ context = null ) : array
127119 {
128- if (empty ($ this ->productSkus ) || !empty ($ this ->productList )) {
120+ $ skusToFetch = array_diff ($ this ->productSkus , array_keys ($ this ->productList ));
121+ if (empty ($ this ->productSkus ) || empty ($ skusToFetch )) {
129122 return $ this ->productList ;
130123 }
131124
132- $ this ->searchCriteriaBuilder ->addFilter (ProductInterface::SKU , $ this -> productSkus , 'in ' );
125+ $ this ->searchCriteriaBuilder ->addFilter (ProductInterface::SKU , $ skusToFetch , 'in ' );
133126 $ result = $ this ->productDataProvider ->getList (
134127 $ this ->searchCriteriaBuilder ->create (),
135128 $ this ->attributeCodes ,
0 commit comments