Программным способом Я строю пользовательские веб-сервисы для мобильных приложений,Magento получить Многослойный фильтр из коллекции
Я хочу, чтобы загрузить фильтр по сбору продуктов программно.
В настоящее время я получаю фильтр по всей категории, но когда мы применяем какой-либо фильтр, он снова даст такую же опцию фильтра.
Ниже приведен код, который я использовал для категории фильтра
$layer = Mage::getModel("catalog/layer");
$_category = Mage::getModel("catalog/category")->load($category_id);
$layer->setCurrentCategory($_category);
$attributes = $layer->getFilterableAttributes();
/* custom for filters
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection->setItemObjectClass('catalog/resource_eav_attribute');
$collection->setAttributeSetFilter(array(4));
$collection->addStoreLabel(Mage::app()->getStore()->getId());
$collection->setOrder('position', 'ASC');
$collection->addFieldToFilter('additional_table.is_filterable', array('gt' => 0));
$attributes = $collection->load();
*/
// print_r($attributes->getData());exit();
$attributeCollection =array();
$i=0;
$attributeCollection = array();
foreach ($attributes as $attribute) {
if($attribute->getAttributeCode() == 'price') {
$filterBlockName = 'catalog/layer_filter_price';
}elseif($attribute->getBackendType() == 'decimal'){
$filterBlockName = 'catalog/layer_filter_decimal';
}else{
$filterBlockName = 'catalog/layer_filter_attribute';
}
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
$attributeCollection[$i]['Code'] = $attribute->getAttributeCode();
$attributeCollection[$i]['Label'] = $attribute->getStoreLabel();
$j=0;
$attributeOptionCollection =array();
foreach($result->getItems() as $option) {
if($attribute->getAttributeCode()=='price'){
$attributeOptionCollection[$j]['Label'] = strip_tags($option->getLabel());
}else{
$attributeOptionCollection[$j]['Label'] = $option->getLabel();
}
$attributeOptionCollection[$j]['Value'] = $option->getValue();
$attributeOptionCollection[$j]['Type'] = $option->getFrontend();
$j++;
}
$attributeCollection[$i]['Options'] = $attributeOptionCollection;
$i++;
}
// print_r($attributeCollection);exit();
// echo "<pre>";
$counter = 0;
$availableSortOptions = $_category->getavailablesortbyoptions();
foreach ($availableSortOptions as $key=>$options) {
$optinsList[$counter]['Code'] = $key;
$optinsList[$counter]['Label'] =$options;
$counter++;
// print_r($options);
}
$information['Filters'] = $attributeCollection;
Пожалуйста, подсказывают, как я проследовать
БУДУ проверить и получить результат –