0

I want to get the listed product's IDs in the product listing page without pagination. But the products will be listed with pagination.

If it is filtered by layered navigation/search then I want that filtered collection without pagination.

How can I do it?

2
  • you can get product data by category which assign products. Aug 23, 2022 at 9:05
  • @DivyarajsinhBarad What about layered navigation? Aug 23, 2022 at 9:15

1 Answer 1

0

I would create a custom block that is active only for the category layout (catalog_category_view.xml).

This block would use the product collection and would filter the product by category id. When the category page is loaded, the registry current_category ($registry->registry('current_category')->getId();) is set. The code below would give you all the product ids.

/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
$collection = $this->collectionFactory->create();
$collection->addCategoriesFilter([$categoryId]);
$productIds = $collection->getAllIds();

Once done, I would advise to set a cache lifetime to this block so that it does not slow down your category pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.