私のウェブサイトには、2つのメニュートップバーがあります。1つはヘッダーセクションにあり、もう1つはユーザーがスクロールの特定のポイントに到達したときにのみ表示されます(ここでは単純なjQueryコードを使用しました)。ここでの問題は、両方のトップバーにSearch Form Miniが含まれていることですが、最初にレンダリングされたバー(私の場合は「#hiddenMenu」トップバー)でのみ、ajaxライブ検索が機能します。
理解していただくために、header.phtmlファイルは次のとおりです。
<div id="hiddenMenu">
<?php echo $this->getChildHtml('topMenu') ?>
<?php echo $this->getChildHtml('topBar') ?>
</div>
<div class="header-container">
<div class="quick-access">
<?php echo $this->getChildHtml('topLinks') ?>
</div>
<div class="header">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
<?php else:?>
<h1 class="logo"><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a>
<?php endif?></h1>
</div>
<div id="menu">
<?php echo $this->getChildHtml('topMenu') ?>
<?php echo $this->getChildHtml('topBar') ?>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
ご覧のとおり、search.mini.formはgetChildHtml('topBar')によって呼び出されるため、2つの違いは配置場所だけです。しかし、search.mini.formの2回目の出現では、何らかの理由で、ajaxライブ検索が機能しません。
私のform.mini.phtmlファイルは元のファイルのままです:
<?php $catalogSearchHelper = $this->helper('catalogsearch'); ?>
<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
<div class="form-search">
<div class="search-mini">
<input id="search" placeholder="Busque" type="text" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" class="input-text" />
<button type="submit" title="<?php echo $this->__('Go') ?>" class="button"><img src="<?php echo $this->getSkinUrl('images/ico-search.png') ?>"></button>
</div>
<div id="search_autocomplete" class="search-autocomplete"></div>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', 'Search');
searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
//]]>
</script>
</div>
</form>
何か案が?