【问题标题】:How to get the filters page?如何获取过滤器页面?
【发布时间】:2014-04-09 12:23:24
【问题描述】:

我需要在组合框中创建 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 ( )

【问题讨论】:

    标签: php magento filter


    【解决方案1】:

    无法解决,做一个变通办法,在新代码下面:

    <?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>
    

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

    【讨论】:

      猜你喜欢
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-08-27
      • 2014-01-02
      • 1970-01-01
      • 2020-05-03
      • 2019-12-06
      • 2014-03-28
      相关资源
      最近更新 更多