1

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

2

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.

| improve this answer | |
1

You can also try using the getUrlModel method below:

$store_code = 'something';
$store_id = 2;
$category_id = 234;
$category = Mage::getModel('catalog/category')->setStoreId($store_id)->load($category_id);

$url = $category->getUrlModel()
    ->getUrlInstance()
    ->getDirectUrl($requestPath, array("_store"=>$store_code, "_nosid"=>true));
| improve this answer | |

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.