wis*_*tal 12 attributes filter magento categories
我专门为网站创建了一个自定义导航模块,但我真的希望能够按特定类别列出可过滤属性.所以我的主要导航是:
然后,当用户将鼠标悬停在一个类别上时,他们会看到一个带有一些可过滤选项的扩展菜单,例如:
按制造商查看:
我能够获得商店的所有可过滤属性,但我希望此列表仅提供每个类别的可过滤属性,例如类别1可能有不同的制造商到类别2.然后我需要缓存这些结果,因为这将不经常改变.
小智 16
Joe给出的答案是一个很好的起点,但属性还没有返回任何选项.经过很多挫折后,我用以下代码解决了这个问题.希望它可以帮助你们所有人.
$layer = Mage::getModel("catalog/layer");
foreach($categories as $categoryid) {
$category = Mage::getModel("catalog/category")->load($categoryid);
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
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 = $this->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
foreach($result->getItems() as $option) {
echo $option->getLabel().'<br/>';
echo $option->getValue();
}
}
Run Code Online (Sandbox Code Playgroud)
您唯一需要做的就是使用getValue()函数创建正确的链接.
此代码已在Magento 1.5中测试过