Magento: textbox instead of multi select in layered navigation

本小妞迷上赌 提交于 2020-01-14 06:30:12

问题


Is there a possibility in Magento to have a multi-select attribute, for which I would use a textbox in layered navigation instead of showing all items from multi-select?

I have an attribute where I will have hundreds of options and need to use it in layered navigation.

When customer uses invalid value, an error should show up.


Edit: After the help from FlorinelChis I have folowing code in filter.phtml:

<ol>
<?php foreach ($this->getItems() as $_item): ?>
  <?php
  $attributeModel = $this->getAttributeModel();    
  $attribute_code =  $attributeModel->getAttributeCode();
  ?>
    <li>
      <?php if ($attribute_code != 'available_zip'): ?>
        <?php if ($_item->getCount() > 0): ?>
        <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
        <?php else: echo $_item->getLabel() ?>
        <?php endif; ?>
        <?php if ($this->shouldDisplayProductCount()): ?>
        (<?php echo $_item->getCount() ?>)
        <?php endif; ?>
      <?php endif; ?>
    </li>
<?php endforeach ?>
</ol>
  <?php
    if ($attribute_code == 'available_zip'): 
          $cat =  Mage::registry('current_category')->getUrlPath() ;
          $url = Mage::getBaseUrl();
          /*$sendUrl = $this->urlEscape($_item->getUrl()).'+'.$url.$cat.'?'.$attribute_code.'='.$_item->getValue();*/
        echo '<form action="" method="get">';
        echo '<input type="text" size="5" maxlength="5" name="'.$attribute_code.'" />';
        echo '<button type="submit">OK</button>';
        echo '</form>';
  endif; ?>

I have one more thing now: how to send the form with attribute id instead of value?


回答1:


First, let's find out how Magento displays the filters in left hand navigation

1) Enable Template Path Hints:

and here is the result:

2) Let's take a look at app/design/frontend/base/default/template/catalog/layer/filter.phtml (you should copy this file in your theme folder structure)

3) The block ($this in the template file is an instance of Mage_Catalog_Block_Layer_Filter_Attribute which extends Mage_Catalog_Block_Layer_Filter_Abstract)

4) You can see that in Mage_Catalog_Block_Layer_Filter_Abstract a getName() method exists, so you could rely on this function to identify when you attribute is displayed. Don't! The label can change and your code won't be useful any more. Back to our template file, you can get the attribute_code (which is reliable)

//$this is instance of Mage_Catalog_Block_Layer_Filter_Attribute 
$attributeModel = $this->getAttributeModel();    
$attribute_code =  $attributeModel->getAttributeCode();

5) On your template you can have a check based on attribute code, so you display either the standard list or your custom html code with a textarea instead of a huge list.



来源:https://stackoverflow.com/questions/14480558/magento-textbox-instead-of-multi-select-in-layered-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!