Hey everyone so I have two stores.

They sell almost all different products except a few, this is where the issue comes into play.

We sell a product called "Single Hearts" which I display in both stores. However in my second store I run the following code:

$store = Mage::app()->getStore();
$storeName = $store->getName();
$categoryId = $store->getRootCategoryId();

$categories = Mage::getModel('catalog/category')->load($categoryId);
$categoryChildren = $categories->getChildren();
$categoryArray = explode(',', $categoryChildren);

TLDR for the code above finds all the product categories for that given store

Then I sift through the categories and create links for a nifty Nav Bar I'm currently creating.

         foreach ($categoryArray as $category) {
             $rootCategory = Mage::getModel('catalog/category')->load($category);
             $rootCategoryUrl = $rootCategory->getUrl();
            <li><a href="<?php echo $rootCategoryUrl ?>">Name</a></li>
   <?php } ?>


The problem arises when I share products across stores! As you can guess it's because when I run the line $rootCategory->getUrl(); it grabs the url from the first store. So when someone in my second store clicks the link it tries to send them to my first store and there is an error. Any quick solution to this? Or am I going to have to get crafty?

1 Answer 1


Wow simple mistake. I just had to use getUrlPath() instead of getUrl(). The wonders of just var_exporting and looking through the object! Hope this helps anyone else who has this problem though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.