Magento – Category url always has wrong store in path

categoryoverridesurl

How can i get a category url rewritten for a specific store in magento?

I have 2 stores: us and uk.

Store codes: en_gb and en_us.

If i load a category in code

$store = Mage::getModel('core/store')->load(3);  // 3 is the uk store
$categoryUrl = Mage::getModel('catalog/category')->load($store->getRootCategoryId())->setStoreId($store->getId());

The url that comes back always has the default website code in the path i.e. and also never the seo friendly url. It is the category/view url

http://mysite/us/catalog/category/view/ukbase/id/3

EDIT:

By setting the store in the script the correct country is added to the url:

 Mage::app()->setCurrentStore($store);

Why is this needed?

Also it still doesnt give the seo friendly url

Best Answer

Magento uses the current store to build the full category url so setting the current store will force it to use the right base URL.

A question posted earlier today might give some more info.

Related Topic