@@ -62,10 +62,7 @@ public function __construct(
62
62
*/
63
63
public function addProductSku (string $ sku ) : void
64
64
{
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 )) {
69
66
$ this ->productSkus [] = $ sku ;
70
67
}
71
68
}
@@ -79,12 +76,7 @@ public function addProductSku(string $sku) : void
79
76
public function addProductSkus (array $ skus ) : void
80
77
{
81
78
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 );
88
80
}
89
81
}
90
82
@@ -108,13 +100,13 @@ public function addEavAttributes(array $attributeCodes) : void
108
100
*/
109
101
public function getProductBySku (string $ sku , ContextInterface $ context = null ) : array
110
102
{
111
- $ products = $ this ->fetch ($ context );
103
+ $ this ->fetch ($ context );
112
104
113
- if (!isset ($ products [$ sku ])) {
105
+ if (!isset ($ this -> productList [$ sku ])) {
114
106
return [];
115
107
}
116
108
117
- return $ products [$ sku ];
109
+ return $ this -> productList [$ sku ];
118
110
}
119
111
120
112
/**
@@ -125,11 +117,12 @@ public function getProductBySku(string $sku, ContextInterface $context = null) :
125
117
*/
126
118
private function fetch (ContextInterface $ context = null ) : array
127
119
{
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 )) {
129
122
return $ this ->productList ;
130
123
}
131
124
132
- $ this ->searchCriteriaBuilder ->addFilter (ProductInterface::SKU , $ this -> productSkus , 'in ' );
125
+ $ this ->searchCriteriaBuilder ->addFilter (ProductInterface::SKU , $ skusToFetch , 'in ' );
133
126
$ result = $ this ->productDataProvider ->getList (
134
127
$ this ->searchCriteriaBuilder ->create (),
135
128
$ this ->attributeCodes ,
0 commit comments