1

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?

6

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.

  • I just realized that I should not leave $storeId null because in such case Magento will take current store which is admin when inside backend. – JohnyFree Dec 11 '14 at 15:47

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.