[英]How to get the filters page?
我需要在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 ( )
無法解決,請采用新代碼下方的解決方法:
<?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>
基本上,我列出了產品和選擇它們的選項,但沒有顯示是否或條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.