我一直在试图找到强制属性显示为下拉菜单而不是选项块但却没有运气的方法。代码电流看起来像这样:Magento - 将属性选择更改为高级搜索中的下拉列表
case 'select': ?>
<div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div>
<?php endswitch; ?>
有谁知道如何使它看起来像一个下拉列表呢?
在此先感谢
我一直在试图找到强制属性显示为下拉菜单而不是选项块但却没有运气的方法。代码电流看起来像这样:Magento - 将属性选择更改为高级搜索中的下拉列表
case 'select': ?>
<div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div>
<?php endswitch; ?>
有谁知道如何使它看起来像一个下拉列表呢?
在此先感谢
对不起,我的英语...我是法国人;-)
在管理控制台中,你可以选择你的属性类型
确保您的属性被声明为一个列表。在我的Magento版本中,它是属性管理面板中代码和范围之后的第三个信息。
PoyPoy
感谢您的回复。我刚刚检查过两次,它被设置为下拉菜单。这是否还有其他原因? – Jason 2011-03-09 17:51:16
我今天早些时候有同样的问题和奇怪的是,我不得不属性(下拉)具有相同的属性,但一个显示在下拉菜单和其他多选择菜单高级搜索。
我用不同的设置进行了一些测试,结果证明,在高级搜索中,每个属性都是一个列表(下拉和多选),并且它有多于两个选项显示为多选。
我看了一下存储在/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php中的Mage_CatalogSearch_Block_Advanced_Form,我看到了这个条件2被检查的位置。 magento核心团队这样做是为了确保'yesno'或布尔列表显示为下拉菜单。
在上述文件中,从线173起(上Magento的当前版本) 是下面的代码:
public function getAttributeSelectElement($attribute)
{
$extra = '';
$options = $attribute->getSource()->getAllOptions(false);
$name = $attribute->getAttributeCode();
// 2 - avoid yes/no selects to be multiselects
if (is_array($options) && count($options)>2) {
. . .
如果更改与5号的最后一行数二,高级搜索将显示每个属性少于6个选项的下拉菜单。
我做了什么对自己是我添加了一个新的方法,getAttributeDropDownElement(),波纹管getAttributeSelectElement(),看起来像这样:
public function getAttributeDropDownElement($attribute)
{
$extra = '';
$options = $attribute->getSource()->getAllOptions(false);
$name = $attribute->getAttributeCode();
// The condition check bellow is what will make sure that every
// attribute will be displayed as dropdown
if (is_array($options)) {
array_unshift($options, array('value'=>'', 'label'=>Mage::helper('catalogsearch')->__('All')));
}
return $this->_getSelectBlock()
->setName($name)
->setId($attribute->getAttributeCode())
->setTitle($this->getAttributeLabel($attribute))
->setExtraParams($extra)
->setValue($this->getAttributeValue($attribute))
->setOptions($options)
->setClass('multiselect')
->getHtml();
}
你需要做的下一件事是一个小的,如果内声明(见下图),它将检查属性的名称并基于该名称调用getAttributeSelectElement()或我们的新方法getAttributeDropDownElement()。我离开这个工作给你:)
case 'select': ?>
<div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div>
<?php endswitch; ?>
希望这是有帮助的。
P.S.为坏的英语道歉 - 不是我的母语!
Magento有一个用于生成Mage_Core_Block_Html_Select类(/app/code/core/Mage/Core/Block/Html/Select.php)的选择类。
在您的设计模板目录模板/ catalogsearch/advanced/form上。PHTML,更换
echo $this->getAttributeSelectElement($_attribute);
随着
echo $this->getLayout()->createBlock('core/html_select')
->setOptions($_attribute->getSource()->getAllOptions(true))
->setName($_attribute->getAttributeCode())
->setClass('select')
->setId($_attribute->getAttributeCode())
->setTitle($this->getAttributeLabel($_attribute))
->getHtml();
哪个文件是这? – 2011-03-06 06:40:35
template/catalogsearch/advanced/form.phtml – Jason 2011-03-09 19:30:32