質問

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?

役に立ちましたか?

解決

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

1) Enable Template Path Hints: Magento Enable Template Path Hints

and here is the result:

magento layered navigation filter

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top