开发者

Magento: Category Dropdown Boxes in Advanced Search

I’m trying to edit my advanced search form to have 2 dropdown boxes: one for a parent category and the 2nd for its subcategories. Do I need Javascript to populate the 2nd one as I don't just want to list all the subcategories which is what I currently have:

<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开发者_Python百科->htmlEscape($this->getEstimateRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
               </div>
            </li>
        <?php //endif; ?>`


Javascript would definitely help to improve the user experience by hiding the sub-categories that don't match the parent category. Make sure that you use Prototype for the task rather than adding jQuery libraries!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜