Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the Url of a product from its SKU in Magento

Tags:

magento

The question is simple. If I know the sku of my product and nothing else, how can I retrieve the url to that item. This is commonly useful for third party integration where the unique id at the remote service wont match a product id. Or maybe you want to make a search box to search by sku only.

like image 414
ajameswolf Avatar asked Mar 05 '13 22:03

ajameswolf


People also ask

How do I find the URL SKU?

Check the URL of the loaded page. You will see a URL with the following format: https://{account-name}.vtexcommercestable.com.br/admin/Site/SkuForm.aspx?IdSku={number} The SKU Id will be the number displayed in the place of {number}

How do I find the URL of a product?

You can be assigned Product URL to any page in store for a redirect to Product page. If you want to get Only Url Key value, You can access by $product->getUrlKey() method. You can product full URL by getProductUrl() method.


1 Answers

You can just do this:

$sku = 'ecco'; // SKU you want to load. 'ecco' is a sku in the Magento demo data

$url =  Mage::getModel('catalog/product')->loadByAttribute('sku',$sku)->getProductUrl();
echo $url;
like image 171
seanbreeden Avatar answered Oct 20 '22 20:10

seanbreeden