Magento-按品牌获取包含产品的所有类别 [英] Magento - get all categories containing products by brand

查看:78
本文介绍了Magento-按品牌获取包含产品的所有类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间试图解决这个问题,但无济于事.如果我有一系列页面显示了按制造商筛选的产品集合,并且我想在每个页面的左列中进行导航,例如包含当前制造商所包含产品的类别列表,该如何处理?我可以不使用一些极其缓慢的代码来填充它吗? (有数千种产品.)

I've spent a bit of time trying to figure this out but to no avail. If I had a series of pages that displayed a collection of products filtered by manufacturer, and I wanted some navigation in, say, the left column on each of these pages, which contained a list of categories containing products by the current manufacturer, how would I go about populating this without resorting to some horribly slow code? (There are a few thousand products).

我可以在循环中放入类似的内容,遍历每个类别,查看每个类别返回的制造商是否有任何结果,但是考虑到有数百个类别,这将相当缓慢.

I could put something similar to this in a loop, iterating through each category, seeing if there are any results for a manufacturer returned for each category, but this will be rather slow, considering there are a couple of hundred categories.

$category           = $currentCategory;
$layer              = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
$manufacturers = array();
foreach ($attributes as $attribute) {
    if ($attribute->getAttributeCode() == 'manufacturer') {
        $filterBlockName = 'catalog/layer_filter_attribute';
        $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
        foreach($result->getItems() as $option) {
            $manufacturers[$option->getValue()] = $option->getLabel();
        }
    }
}

如果有人有更好的主意,我将不胜感激.

I'd be very grateful if anyone has any better ideas.

推荐答案

  1. 添加自定义类别属性所有制造商(http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/).

  1. Add custom category attribute allmanufacturers(http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/).

运行一个cron,将检查每个类别的所有产品,并检查其制造商,并在此allmanufacturers的客户属性中填充一个(,)分隔的制造商值.

Run a cron that will go through all products for each category check its manufacturer and in this allmanufacturers customer attribute populate a (,) separated manufacturer value.

现在,在您的代码中,您只需要检查特定制造商的自定义类别属性-allmanufacturers"值并填充左列.

Now in your code you just need to check "custom category attribute -- allmanufacturers" value for specific manufacturer and populate left column.

这篇关于Magento-按品牌获取包含产品的所有类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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