Skip to content

Commit 3900bff

Browse files
committed
MC-18338: Pulling products from single category into ProductList and sort them by product position in the Category
1 parent 41308fe commit 3900bff

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/code/Magento/PageBuilder/Plugin/Catalog/Block/Product/ProductsListPlugin.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\Category;
1313
use Magento\CatalogInventory\Helper\Stock;
1414
use Magento\Catalog\Api\CategoryRepositoryInterface;
15+
use Magento\Framework\Exception\NoSuchEntityException;
1516

1617
/**
1718
* Catalog Products List widget block plugin
@@ -54,7 +55,6 @@ public function __construct(
5455
* @param \Magento\CatalogWidget\Block\Product\ProductsList $subject
5556
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $result
5657
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
57-
* @throws \Magento\Framework\Exception\NoSuchEntityException
5858
*/
5959
public function afterCreateCollection(
6060
\Magento\CatalogWidget\Block\Product\ProductsList $subject,
@@ -66,7 +66,14 @@ public function afterCreateCollection(
6666
$this->stock->addIsInStockFilterToCollection($result);
6767

6868
if (!empty($categoryId)) {
69-
$result->addCategoryFilter($this->categoryRepository->get($categoryId));
69+
try {
70+
$category = $this->categoryRepository->get($categoryId);
71+
} catch (NoSuchEntityException $noEntityException) {
72+
$category = null;
73+
}
74+
if ($category) {
75+
$result->addCategoryFilter($category);
76+
}
7077
}
7178

7279
if (!empty($sortOption)) {

0 commit comments

Comments
 (0)