Magento的 - 获得按类别过滤属性 [英] Magento - get filterable attributes by category

查看:235
本文介绍了Magento的 - 获得按类别过滤属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义的导航模块专门用于一个网站,但我真的希望能够通过一个特定的类别,列出筛选的属性。因此,例如我的主导航是:

I have created a custom navigation module specifically for a website, but I really want to be able to list filterable attributes by a specific category. So for instance my main navigation is:


        
  • 类别1

  •     
  • 2类

  •     
  • 3类别等。

我然后,当用户将鼠标放在一类,他们是那么psented具有扩展菜单有一些过滤选项例如$ P $:

I then that when a user mouses over a category, they are then presented with an expanded menu with a few filterable options e.g.:

查看制造商:


        
  • 制造商1

  •     
  • 制造商2

  •     
  • 制造商3等。

我能够得到的所有店铺过滤属性,但我想在此清单中只有每个类别的可筛选属性拉,如例如第1类可以有不同的生产厂家2类。然后,我需要缓存这些结果因为这不会经常发生变化。

I am able to get all filterable attributes for the store, but I want this list to pull in only the filterable attributes per category, as for instance Category 1 may have different manufacturers to Category 2. I then need to cache these results as this will not change often.

推荐答案

这给了乔是一个很好的起点,但属性不返回任何选项还没有答案。很多的挫折后,我解决了以下code中的问题。希望它可以帮助你们的。

The answer that Joe gave was a good starting point, but the attributes didn't returned any options yet. After a lot of frustrations I solved the problem with the following code. Hope it helps all of you out.

$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();
        }
}

你需要自己做的唯一的事情就是创建一个使用的getValue正确的链接()函数。

The only thing you'll need to do yourself is create the correct link using the getValue() functions.

这code已经在Magento 1.5进行了测试。

This code has been tested in Magento 1.5

这篇关于Magento的 - 获得按类别过滤属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆