2014-04-09 64 views
0

我需要在组合框中创建3个过滤器才能正常工作,但无法创建状态并仅显示每个类别中存在的选项。如何获取过滤器页面?

示例:在本机过滤器Magento的,如果你有3个选择,但只有1个选项,Magento的只显示1我的节目3

下面我的代码示例选项:

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

我需要做一个条件,但不能捕获过滤器页面。

我试过这段代码:

​​

但他与空数组

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

回答

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> 

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