I need to get a grouped product url. How can I load a grouped product by a custom attribute and get its url?
Try this
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('custom_attribute_code')
->addAttributeToFilter('custom_attribute_code','your_value')
->addUrlRewrite();
$product = $collection->getFirstItem();
if($product->getId()) {
$product->getProductUrl();
}
OR
if($product->getId()) {
$product->getUrl();
}
You can just use a collection to load a product collection, filter by your attribute and then get the url.
$product = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('custom_attribute','value')
->addUrlRewrite()
->getFirst()
$product->getUrl()
Afaik you can add a categoryId as parameter to addUrlRewrite
if you want a special url.
-
-
check the collection mit be getFirstItem or something alike – Fabian Blechschmidt Jan 15 '16 at 10:42