我在为Magento的一位客户开网店。他与非常具体的品牌工作很多,所以我想让特定的品牌页面(为了搜索引擎优化的目的)。
我遵循了这里提到的建议:Mangento Shop By Brand将品牌分类。这一切都很好用,我可以像example.com/brands/brandname一样访问我的页面。
但是现在,在产品视图中,我想要链接到该品牌页面。如何才能获得该产品的类别列表,甚至是特定的子类别。我想过根据他们的parent_id (我的品牌页面本身)来过滤类别。但却不知道该怎么做。我找到了一些信息here,但似乎不适用于我的Magento (1.4.1.1)
发布于 2011-10-20 22:17:14
它似乎做到了这一点:Aitoc commercial module to shop by brand
或者我尝试了Magento 1.4.1的代码,它显示了产品所属的类别的列表/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();
}
}
}https://stackoverflow.com/questions/7724872
复制相似问题