I'm trying to filter my product search by returning only products within the current category I'm in, I can't find where the product collection is created within the search module
Can anyone help point me in the right direction?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI'm trying to filter my product search by returning only products within the current category I'm in, I can't find where the product collection is created within the search module
Can anyone help point me in the right direction?
Please run the below code in the default magento2 at root (test.php), Here i am giving u sample example with the filter options and returning the collection array.
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cateid = '9';
$cateinstance = $objectManager->get('Magento\Catalog\Model\CategoryFactory');
$allcategoryproducts = $cateinstance->create()->load($cateid)->getProductCollection()->addAttributeToSelect('*')->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
echo "<pre>";
echo count($allcategoryproducts);?>