1

Magento 2 how to implement catalog search programmatically.

I need categories and product details.

Please provide reference links if any.

Please find the screenshot : enter image description here

0

EX: http://testsite.com/filename.php?q={yoursearchterm}

<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$appState = $objectManager->get(\Magento\Framework\App\State::class);
$layerResolver = $objectManager->get(\Magento\Catalog\Model\Layer\Resolver::class);
$appState->setAreaCode('frontend');
$layerResolvers = $layerResolver->create('search');
$layerResolvers1 = $layerResolver->get();
$productCollection = $layerResolvers1->getProductCollection();

echo "Search layered navigation :<br>";
echo "products count == ".count($productCollection)."<br>";
foreach ($productCollection as $product) {
    echo "Name : ".$product->getName()." Price : ".$product->getPrice()."<br>";
}
?>
  • thanks for u r reply but how to get categories here? – NIPPU Aug 4 '17 at 7:38
  • Just add the categories on Magento Admin – DevAnd Aug 7 '17 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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