0

enter image description here

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

0

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

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

// @codingStandardsIgnoreFile
?>
<?php
/** @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>
                </label>
                <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; ?>
                    </select>
                    <input id="search"
                           data-mage-init='{"quickSearch":{
                                "formSelector":"#search_mini_form",
                                "url":"<?= /* @escapeNotVerified */ $helper->getSuggestUrl()?>",
                                "destinationSelector":"#search_autocomplete"}
                           }'
                           type="text"
                           name="<?= /* @escapeNotVerified */ $helper->getQueryParamName() ?>"
                           value="<?= /* @escapeNotVerified */ $helper->getEscapedQueryText() ?>"
                           placeholder="<?= /* @escapeNotVerified */ __('Search entire store here...') ?>"
                           class="input-text"
                           maxlength="<?= /* @escapeNotVerified */ $helper->getMaxQueryLength() ?>"
                           role="combobox"
                           aria-haspopup="false"
                           aria-autocomplete="both"
                           autocomplete="off"/>
                    <div id="search_autocomplete" class="search-autocomplete"></div>
                    <?= $block->getChildHtml() ?>
                </div>
            </div>
            <div class="actions">
                <button type="submit"
                        title="<?= $block->escapeHtml(__('Search')) ?>"
                        class="action search">
                    <span><?= /* @escapeNotVerified */ __('Search') ?></span>
                </button>
            </div>
        </form>
    </div>
</div>

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.