1

How to show the Magento Advanced search page in "Search Result Page" if there is no search result for Magento simple search ?

1

You can achieve this with below. Update your app\design\frontend\YourPackage\YourTheme\template\catalogsearch\result.phtml

<?php if($this->getResultCount()): ?>
<?php echo $this->getMessagesBlock()->toHtml() ?>
<div class="page-title">
    <?php if ($this->helper('rss/catalog')->getTagFeedUrl()): ?>
        <a href="<?php echo $this->helper('rss/catalog')->getTagFeedUrl() ?>" class="nobr link-rss"><?php echo $this->__('Subscribe to Feed') ?></a>
    <?php endif; ?>
    <h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
    <?php if ($messages = $this->getNoteMessages()):?>
    <p class="note-msg">
        <?php foreach ($messages as $message):?>
            <?php echo $message?><br />
        <?php endforeach;?>
    </p>
    <?php endif; ?>
    <?php echo $this->getProductListHtml() ?>
<?php else: ?>
<div class="page-title">
    <h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
<p class="note-msg">
    <?php echo ($this->getNoResultText()) ? $this->getNoResultText() : $this->__('Your search returns no results.') ?>
    <?php echo $this->getAdditionalHtml() ?>
    <?php if ($messages = $this->getNoteMessages()):?>
        <?php foreach ($messages as $message):?>
        <br /><?php echo $message?>
        <?php endforeach;?>
    <?php endif; ?>
    <?php echo $this->getLayout()->createBlock("catalogsearch/advanced_form")->setTemplate("catalogsearch/advanced-form.phtml")->toHtml(); ?>
</p>
<?php endif; ?>

Now create a new file app\design\frontend\YourPackage\YourTheme\template\catalogsearch\advanced-form.phtml

<?php $maxQueryLength= $this->helper('catalogsearch')->getMaxQueryLength();?>
<?php echo $this->getMessagesBlock()->toHtml() ?>
<form action="<?php echo $this->getUrl("catalogsearch/advanced/result/") ?>" method="get" id="form-validate">
    <div class="fieldset advanced-search">
        <h2 class="legend"><?php echo $this->__('Try Advance Search') ?></h2>
        <ul class="form-list" id="advanced-search-list">
            <?php foreach ($this->getSearchableAttributes() as $_attribute): ?>
            <?php $_code = $_attribute->getAttributeCode() ?>
            <li>
                <label for="<?php echo $_code ?>"><?php echo $this->getAttributeLabel($_attribute) ?></label>
                <?php switch($this->getAttributeInputType($_attribute)):
                    case 'number': ?>
                    <div class="input-range">
                        <input type="text" pattern="\d*" name="<?php echo $_code ?>[from]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>" class="input-text validate-number" maxlength="<?php echo $maxQueryLength;?>" />
                        <span class="separator">-</span>
                        <input type="text" pattern="\d*" name="<?php echo $_code ?>[to]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>" class="input-text validate-number" maxlength="<?php echo $maxQueryLength;?>" />
                    </div>
                    <?php break;
                    case 'price': ?>
                    <div class="input-range">
                        <input name="<?php echo $_code ?>[from]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" pattern="\d*" maxlength="<?php echo $maxQueryLength;?>" />
                        <span class="separator">-</span>
                        <input name="<?php echo $_code ?>[to]" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" pattern="\d*" maxlength="<?php echo $maxQueryLength;?>" />
                        <small>(<?php echo $this->getCurrency($_attribute); ?>)</small>
                    </div>
                    <?php break;
                    case 'select': ?>
                        <div class="input-box">
                            <?php echo $this->getAttributeSelectElement($_attribute) ?>
                        </div>
                    <?php break;
                    case 'yesno': ?>
                        <?php echo $this->getAttributeYesNoElement($_attribute) ?>
                    <?php break;
                    case 'date': ?>
                    <div class="input-range">
                        <?php echo $this->getDateInput($_attribute, 'from') ?>
                        <span class="separator">-</span>
                        <?php echo $this->getDateInput($_attribute, 'to') ?>
                    </div>
                    <?php break;
                    default: ?>
                    <div class="input-box">
                        <input type="text" name="<?php echo $_code ?>" id="<?php echo $_code ?>" value="<?php echo $this->escapeHtml($this->getAttributeValue($_attribute)) ?>" title="<?php echo $this->escapeHtml($this->getAttributeLabel($_attribute)) ?>"  class="input-text <?php echo $this->getAttributeValidationClass($_attribute) ?>" maxlength="<?php echo $maxQueryLength;?>" />
                    </div>
                <?php endswitch; ?>
            </li>
            <?php endforeach; ?>
        </ul>
        <script type="text/javascript">decorateList('advanced-search-list')</script>
    </div>
    <div class="buttons-set">
        <button type="submit" title="<?php echo $this->__('Search') ?>" class="button"><span><span><?php echo $this->__('Search') ?></span></span></button>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
    var dataForm = new VarienForm('form-validate', true);
//]]>
</script>
| improve this answer | |
0

Navigate to

app/code/core/Mage/CatalogSearch/controllers/ResultController.php

and replace this

 $query->prepare(); 

with below line

 return $this->_redirect('catalogsearch/advanced');
| improve this answer | |

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.