Skip to content

Commit d0404e9

Browse files
committed
MAGE-940 Limit test product retrieval query to one product only
1 parent 34a08b4 commit d0404e9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Observer/RecommendSettings.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,16 @@ protected function getProductId(): string
177177
Visibility::VISIBILITY_BOTH
178178
],
179179
'in')
180-
->setPageSize(10)
180+
->setPageSize(1)
181+
->setCurrentPage(1)
181182
->create();
182183
$result = $this->productRepository->getList($searchCriteria);
183-
if ($result->getTotalCount()) {
184-
$products = array_reverse($result->getItems());
185-
$firstProduct = array_pop($products);
186-
$this->productId = (string)$firstProduct->getId();
184+
$items = $result->getItems();
185+
$firstProduct = reset($items);
186+
if ($firstProduct) {
187+
$this->productId = (string) $firstProduct->getId();
188+
} else {
189+
throw new LocalizedException(__("Unable to locate product to validate Recommend model."));
187190
}
188191
}
189192

0 commit comments

Comments
 (0)