如何获取过滤器页面?

时间:2014-04-09 12:23:25

标签: php magento filter

我需要在combobox中创建3个过滤器才能正常工作,但无法制作条件并仅显示每个类别中存在的选项。

示例:在原生滤镜magento中,如果您有3个选项但只选择了1个选项,则magento在我的节目3中仅显示1个选项。

在我的代码示例下面:

<?php
$attr1='filtro1';
$attributeInfo1 = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attr1)->getFirstItem();
$attributeId1 = $attributeInfo1->getAttributeId();
$attribute1 = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId1);
$attributeOptions1 = $attribute1->getSource()->getAllOptions(false); 
?>
<select onchange="submit()" name="filtro1">
<option value="">Selecione um...</option>
<?php
    foreach($attributeOptions1 as $filtro1){?>
        <option <?php if($_GET['filtro1'] == $filtro1['value']){echo 'selected="selected"';} ?>value="<?php echo $filtro1['value'];?>">
            <?php echo $filtro1['label'];?>
        </option>
<?php       
    }
?>
</select>

我需要制作条件,但无法捕获过滤器页面。

我试过这段代码:

<?php
$_filters = Mage::getSingleton('Mage_Catalog_Block_Layer_State');
foreach ($_filters as $_filter){
    print_r($_filter);
}
?>

但他带着空数组返回

Array ( ) catalog/layer/state.phtmlArray ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( ) Array ( )

1 个答案:

答案 0 :(得分:0)

无法解决,在新代码下面进行解决方法:

<?php
$category_id = Mage::registry('current_category')->getId();
$category = new Mage_Catalog_Model_Category();
$category->load($category_id);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
$cont = 0;
foreach ($collection as $_product){             
    $filtrated1 .= $_product->getData('filter1');
    $cont++;
    if($cont == 1){
        $filtrated1 .= ',';
    }
}           
$filtrated1 = array_unique(explode(',',$filtrated1));

$attr1='filter1';
$attributeInfo1 = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attr1)->getFirstItem();
$attributeId1 = $attributeInfo1->getAttributeId();
$attribute1 = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId1);
$attributeOptions1 = $attribute1->getSource()->getAllOptions(false); 
?>

<select onchange="submit()" name="filter1">
    <option value="">Selecione um...</option>
    <?php
        foreach($attributeOptions1 as $filter1){
            foreach($filtrated1 as $show1){
                if($filter1['value'] == $show1){?>
                    <option <?php if($_GET['filter1'] == $filter1['value']){echo 'selected="selected"';} ?>value="<?php echo $filter1['value'];?>">
                        <?php echo $filter1['label'];?>
                    </option>
                    <?php
                    break;  
                }
            }
        }
    ?>
</select>

基本上我列出了选择它们的产品和选项,并没有显示是否或条件。