【问题标题】:Magento brands by categories: show brand linkMagento 品牌分类:显示品牌链接
【发布时间】:2011-10-11 10:53:58
【问题描述】:

我正在为 Magento 的客户建立一个网上商店。 他经常与非常特定的品牌合作,所以我想制作特定品牌的页面(出于 SEO 目的)。

我按照这里提到的建议:Mangento Shop By Brand 将品牌分类。 一切都很好,我可以访问我的页面,例如example.com/brands/brandname

但是现在,在产品视图中,我想链接到该品牌页面。 如何获取该产品的类别列表,甚至是特定的子类别。 我考虑过按其 parent_id 过滤类别(我的品牌页面本身)。但不知道如何去做。 我找到了 som info here 但似乎不适用于我的 Magento (1.4.1.1)

【问题讨论】:

    标签: magento magento-1.4


    【解决方案1】:

    它似乎做的工作:Aitoc commercial module to shop by brand

    或者我用 Magento 1.4.1 尝试了这段代码,它显示了产品所属的类别/ies 的列表/url,受您提供的链接的启发,它可以工作,将它放在一个块中以允许模板显示网址:

    public function getProductUrl($productId){
        $product = Mage::getModel('catalog/product')->load(productId);
        $currentCatIds = $product->getCategoryIds();
        if ($currentCatIds) {
            $categoryCollection = Mage::getResourceModel('catalog/category_collection')->addAttributeToSelect('name')
                ->addAttributeToSelect('url')
                ->addAttributeToFilter('entity_id', $currentCatIds)
                ->addIsActiveFilter();
            foreach ($categoryCollection->getItems() as $item) {
                /*echo $item->getName();
                echo $item->getUrl();
                echo '<br>';*/
                if($item->getUrl()) return $item->getUrl();
            }
        }
    }
    

    【讨论】:

    • 我添加了以下行:-&gt;addAttributeToFilter('parent_id', 71) 仅过滤掉“品牌”下的类别(对我来说是 71)。感谢您的建议!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-29
    • 2018-03-11
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多