enter image description here

I want to call the shopnow categeory inside the search bar as a filter option in the search bar.


You need to add the following code to your form.mini.phtml

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

// @codingStandardsIgnoreFile
/** @var $block \Magento\Framework\View\Element\Template */
/** @var $helper \Magento\Search\Helper\Data */
$helper = $this->helper(\Magento\Search\Helper\Data::class);

$_categoryHelper = $this->helper(\Magento\Catalog\Helper\Category::class);
$categories = $_categoryHelper->getStoreCategories(true,false,true);
<div class="block block-search">
    <div class="block block-title"><strong><?= /* @escapeNotVerified */ __('Search') ?></strong></div>
    <div class="block block-content">
        <form class="form minisearch" id="search_mini_form" action="<?= /* @escapeNotVerified */ $helper->getResultUrl() ?>" method="get">
            <div class="field search">
                <label class="label" for="search" data-role="minisearch-label">
                    <span><?= /* @escapeNotVerified */ __('Search') ?></span>
                <div class="control">
                    <select id="cat" name="cat">
                      <option value="">All Category</option>
                      <?php foreach($categories as $category): ?>
                        <option value="<?php echo $category->getEntityId(); ?>"><?php echo $category->getName(); ?></option>
                      <?php endforeach; ?>
                    <input id="search"
                                "url":"<?= /* @escapeNotVerified */ $helper->getSuggestUrl()?>",
                           name="<?= /* @escapeNotVerified */ $helper->getQueryParamName() ?>"
                           value="<?= /* @escapeNotVerified */ $helper->getEscapedQueryText() ?>"
                           placeholder="<?= /* @escapeNotVerified */ __('Search entire store here...') ?>"
                           maxlength="<?= /* @escapeNotVerified */ $helper->getMaxQueryLength() ?>"
                    <div id="search_autocomplete" class="search-autocomplete"></div>
                    <?= $block->getChildHtml() ?>
            <div class="actions">
                <button type="submit"
                        title="<?= $block->escapeHtml(__('Search')) ?>"
                        class="action search">
                    <span><?= /* @escapeNotVerified */ __('Search') ?></span>

This will show the 1st level categories in the dropdown. If you have shop now category as 1st level then you need to modify the below code:

$categories = $_categoryHelper->getStoreCategories(true,false,true) 

to get sub categories of shop now. Hope this helps!

  • hi tnx for your response it s working but the category is coming outside the search bar – Dattatraya Pullavarthi Jul 24 '18 at 9:50

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.