I'm setting up a webshop for a client in Magento. He works a lot with very specific brands, so I wanted to make specific brands pages (for SEO pur开发者_StackOverflowposes).
I followed the suggestion mentioned here: Mangento Shop By Brand to make categories out of brands.
It all works great, I can access my pages like example.com/brands/brandname
.
But now, when in a products view, I want to link to that brand page. How can I get a list of the categories for that product, or even the specific subcategory. I thought about filtering categories by their parent_id (my brands page itself). But haven't got a clue how to go about doing it. I found som info here but doesn't seem to work for my Magento (1.4.1.1)
It seems to do the work: Aitoc commercial module to shop by brand
Or I tried this code with Magento 1.4.1 which display the list/url of category/ies that the product belongs to, inspired of the link you provided and it works, put it in a block to allow the template to display the 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();
}
}
}
精彩评论