简体   繁体   English

Magento-按品牌获取包含产品的所有类别

[英]Magento - get all categories containing products by brand

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. Add custom category attribute allmanufacturers(http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/). 添加自定义类别属性allmanufacturers(http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/)。

  2. 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. 运行一个cron,它将检查每个类别的所有产品,并检查其制造商,并在此allmanufacturers中的客户属性中填充一个(,)分隔的制造商值。

Now in your code you just need to check "custom category attribute -- allmanufacturers" value for specific manufacturer and populate left column. 现在,在您的代码中,您只需要检查特定制造商的“自定义类别属性-allmanufacturers”值,然后填充左列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM