Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento-将属性选择更改为Adv Search中的下拉列表_Search_Magento_Attributes_Drop Down Menu - Fatal编程技术网

Magento-将属性选择更改为Adv Search中的下拉列表

Magento-将属性选择更改为Adv Search中的下拉列表,search,magento,attributes,drop-down-menu,Search,Magento,Attributes,Drop Down Menu,我一直在试图找到一种方法,强制属性显示为下拉列表,而不是选项块,但没有成功。当前代码如下所示: case 'select': ?> <div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div> <?php endswitch; ?> public function getAttributeDropDo

我一直在试图找到一种方法,强制属性显示为下拉列表,而不是选项块,但没有成功。当前代码如下所示:

case 'select': ?>
    <div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div>
    <?php endswitch; ?>
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();
}
案例“选择”:?>
有人知道如何让它看起来像一个下拉列表吗


提前谢谢

对不起我的英语……我是法国人;-)

在管理面板中,您可以选择属性的类型

确保将属性声明为列表。在我的Magento版本中,它是属性管理面板中代码和范围之后的第三个信息


PoyPoy

我今天早些时候也遇到了同样的问题,最奇怪的是我的属性(下拉)具有相同的属性,但一个显示下拉菜单,另一个在高级搜索中显示多选菜单

我使用不同的设置进行了一些测试,结果表明,在高级搜索中,作为列表(下拉和多选)且具有2个以上选项的每个属性都显示为多选

我查看了存储在/app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php中的Mage\u CatalogSearch\u Block\u Advanced\u表单,我看到了检查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) {
    . . .
如果将最后一行的数字2改为数字5,则advanced search将在每个选项少于6个的属性上显示下拉菜单

我自己做的是添加了一个新方法getAttributeDropDownElement(),下面是getAttributeSelectElement(),如下所示:

case 'select': ?>
    <div class="input-box"> <?php echo $this->getAttributeSelectElement($_attribute) ?> </div>
    <?php endswitch; ?>
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();
}
接下来需要做的事情是在表单的开关中使用一个小if语句(请参见下文),它将检查属性的名称,并在此基础上调用getAttributeSelectElement()或我们的新方法getAttributeDropDownElement()。我把这份工作留给你:)

案例“选择”:?>

Magento有一个用于生成选择的类,可用作Mage\u Core\u Block\u Html\u Select类(/app/code/Core/Mage/Core/Block/Html/Select.php)


在设计模板目录template/catalogsearch/advanced/form.phtml中,替换

echo $this->getAttributeSelectElement($_attribute);


谢谢你的回复。我刚仔细检查过,它被设置为下拉。发生这种情况还有其他原因吗?template/catalogsearch/advanced/form.phtml