Magento:高级搜索中的类别下拉框

时间:2011-02-19 20:41:18

标签: search magento drop-down-menu categories

我正在尝试编辑我的高级搜索表单,其中2个下拉框一个用于父类别,第二个用于子类别。我是否需要使用javascript来填充第二个,因为我不想列出所有子类别,这是我真正拥有的:

提前致谢

<li>
  <select name="model" id="category_search_field1">
    <option value="">-- Model --</option>
    <?php foreach ($this->getStoreCategories() as $_category): ?>
      <?php if($_category->hasChildren()): ?>
        <?php foreach ($_category->getChildren() as $subcategory):
          if($subcategory->getIsActive()) : ?>
            <option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option>
       <?php endif; endforeach; ?>
      <?php endif; ?
    <?php endforeach ?>
  </select>
</li>

<li>
<label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
                <div class="input-box">
                    <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
                        <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                    </select>
                   <script type="text/javascript">
                   //<![CDATA[
                       $('region_id').setAttribute('defaultValue',  "<?php echo $this->getEstimateRegionId() ?>");
                   //]]>
                   </script>
                   <input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getEstimateRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
               </div>
            </li>
        <?php //endif; ?>`

1 个答案:

答案 0 :(得分:1)

通过隐藏与父类别不匹配的子类别,Javascript肯定有助于改善用户体验。确保您使用Prototype来完成任务,而不是添加jQuery库!