【问题标题】:Magento - get all categories containing products by brandMagento - 按品牌获取包含产品的所有类别
【发布时间】:2013-01-19 11:48:37
【问题描述】:

我花了一些时间试图弄清楚这一点,但无济于事。如果我有一系列页面显示由制造商过滤的产品集合,并且我想要在每个页面的左栏中进行一些导航,其中包含包含当前制造商产品的类别列表,如何我要在不使用一些非常慢的代码的情况下填充它? (有几千种产品)。

我可以将与此类似的内容放在一个循环中,遍历每个类别,查看是否有针对每个类别返回的制造商的任何结果,但考虑到有几百个类别,这会相当慢。

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

如果有人有更好的想法,我将非常感激。

【问题讨论】:

    标签: php magento e-commerce


    【解决方案1】:
    1. 添加自定义类别属性 allmanufacturers(http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/)。

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

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

    【讨论】:

    • 谢谢。您是对的,通过 cron 作业执行此操作是正确的方法,但我可能会使用将每个品牌与相关类别联系在一起的索引表。干杯!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    相关资源
    最近更新 更多