cancel
Showing results for 
Search instead for 
Did you mean: 

Get products list for a current category

Get products list for a current category

$categoryId = $this->getLayer()->getCurrentCategory()->getId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class);
$currentstore = $storeManager->getStore()->getCode();
$categorysFactory = $objectManager->get('\Magento\Catalog\Model\CategoryFactory');

//$categoryId = 4; // YOUR CATEGORY ID
$category = $categorysFactory->create()->load($categoryId);

$collection = $category->getProductCollection()
->addAttributeToSelect('*');
}