1

I need to get a grouped product url. How can I load a grouped product by a custom attribute and get its url?

1

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(); 
}
0

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.

  • getFirst() is giving error @Fabian Blechschmidt – tufanayd Jan 14 '16 at 23:24
  • check the collection mit be getFirstItem or something alike – Fabian Blechschmidt Jan 15 '16 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.