【问题标题】:Magento: textbox instead of multi select in layered navigationMagento:文本框而不是分层导航中的多选
【发布时间】:2013-01-06 23:34:14
【问题描述】:

Magento 中是否有可能具有多选属性,为此我会在分层导航中使用文本框而不是显示多选中的所有项目?

我有一个属性,我将有数百个选项,需要在分层导航中使用它。

当客户使用无效值时,应显示错误。


编辑:在 FlorinelChis 的帮助下,我在 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; ?>

我现在还有一件事: 如何发送带有属性 id 而不是 value 的表单?

【问题讨论】:

  • 从您的问题中不清楚您现在的属性类型是什么?是多选还是文本字段?
  • 我有一个多选属性。但我想在分层导航中使用文本框(这样我就不会从那里的列表中列出数百行)。

标签: magento attributes multi-select layered-navigation


【解决方案1】:

首先,让我们看看 Magento 如何在左侧导航中显示过滤器

1) 启用模板路径提示:

结果如下:

2)我们来看看app/design/frontend/base/default/template/catalog/layer/filter.phtml(你应该把这个文件复制到你的主题文件夹结构中)

3) 块(模板文件中的$this 是扩展Mage_Catalog_Block_Layer_Filter_Abstract 的Mage_Catalog_Block_Layer_Filter_Attribute 的一个实例)

4) 您可以看到Mage_Catalog_Block_Layer_Filter_Abstract 中存在一个getName() 方法,因此您可以依靠此函数来识别您的属性何时显示。别!标签可以更改,您的代码将不再有用。 回到我们的模板文件,可以得到attribute_code(靠谱)

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

5) 在您的模板上,您可以根据属性代码进行检查,因此您可以使用文本区域而不是巨大的列表显示标准列表或自定义 html 代码。

【讨论】:

  • 帮助很大!谢谢!我可以再问你一个想法吗?很可能很容易解决 - 但是当我为属性创建一个表单(而不是那个多选)时,表单的打印次数与属性的行数一样多。当然是因为filter.phtml中使用了foreach。但是如何防止这种情况(不要为属性的每一行都遍历循环?如果我将表单放在循环后面,它会为每个属性显示。
  • 现在它在那里......我有两个问题(在底部描述)
  • if ($attribute_code = 'available_zip'): - 真的吗? = 是干什么用的? == 是为了什么? php 中的 === 是什么?我开始为分配时间来解释这一点感到抱歉。
  • 不知道该说什么 - 我真的很抱歉打扰了这个愚蠢的错误!但更困扰我的是 - 如何发送带有属性 id 而不是值的表单
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-20
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多