按类别划分的Magento品牌:显示品牌链接
我正在为Magento的一个客户建立一个网络商店。 他经常与非常特定的品牌打交道,所以我想制作特定的品牌页面(用于SEO目的) 我遵循了这里提到的建议:根据品牌进行分类。 一切都很好,我可以访问我的页面,比如按类别划分的Magento品牌:显示品牌链接,magento,magento-1.4,Magento,Magento 1.4,我正在为Magento的一个客户建立一个网络商店。 他经常与非常特定的品牌打交道,所以我想制作特定的品牌页面(用于SEO目的) 我遵循了这里提到的建议:根据品牌进行分类。 一切都很好,我可以访问我的页面,比如example.com/brands/brandname 但现在,在产品视图中,我想链接到该品牌页面。 如何获得该产品的类别列表,甚至是特定的子类别。 我考虑过按他们的家长id(我的品牌页面本身)过滤类别。但我不知道该怎么做。 我找到了som信息,但似乎对我的Magento(1.4.1.1)
example.com/brands/brandname
但现在,在产品视图中,我想链接到该品牌页面。
如何获得该产品的类别列表,甚至是特定的子类别。
我考虑过按他们的家长id(我的品牌页面本身)过滤类别。但我不知道该怎么做。
我找到了som信息,但似乎对我的Magento(1.4.1.1)不起作用
或者,我在Magento 1.4.1中尝试了这段代码,该代码显示了产品所属类别/IE的列表/url,受您提供的链接启发,该代码正常工作,将其放在块中以允许模板显示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();
}
}
}
公共函数getProductUrl($productId){
$product=Mage::getModel('catalog/product')->load(productId);
$CurrentCATID=$product->GetCategoryID();
如果($currentCATID){
$categoryCollection=Mage::getResourceModel('catalog/category_collection')->addAttributeToSelect('name'))
->addAttributeToSelect('url')
->addAttributeToFilter('entity_id',$currentCatIds)
->addIsActiveFilter();
foreach($categoryCollection->getItems()作为$item){
/*echo$item->getName();
echo$item->getUrl();
回声“
”*/
如果($item->getUrl())返回$item->getUrl();
}
}
}
我添加了以下行:->addAttributeToFilter('parent_id',71)
只筛选出“brands”(对我来说是71)下的类别。谢谢你的建议!