Question

Based on this answer, you can fetch baseurl from backend with his code:

Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);

This won't work properly, if settings 'Add Store Code to Urls' is set to 'Yes' (details about that). In this case, it will add 'admin' into url.

I noticed that also

Mage::getModel('catalog/product')->load(1)->getProductUrl()

won't display proper url, it will add admin into url on fresh Magento installation.

Is that Magento bug? Is there any other proper way to get frontend base url from backend?

Was it helpful?

Solution

Try it like this:

$storeId = 1; //the store you need the base url:
$homeUrl = Mage::getUrl('', array('_store' => $storeId));

For a product url do this:

$url = Mage::getModel('catalog/product')->setStoreId($storeId)->load(1)->getProductUrl();

$storeId is the same as above.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top