I'm building a website, and installed Magento in the /shop/ subdirectory. I'd like to integrate the top categories into the menu of my non-Magento site, so you can navigate directly into the category. For this I need the category names and url's.
Magento's categories are:
- Templates
- Color
- Theme
- General
- Other products
I first needed to get a list of categories below the Templates top-level, so I wrote the following code. It's my first try with integrating with Magento, so be gentle :-) :
<?php
require_once dirname(__FILE__).'/shop/app/Mage.php';
umask(0);
Mage::app('default');
$helper = Mage::helper('catalog/category');
$collection = $helper->getStoreCategories();
foreach ($collection as $catalogArray) {
if ($catalogArray->getName() == "Templates") {
foreach (explode(",", $catalogArray->getChildren()) as $category) {
$_category = Mage::getModel('catalog/category')->load($category);
if($_category->getIsActive()) {
$caturl = $_category->getUrl();
$catname = $_category->getName();
}
echo "<pre>";
var_dump($caturl);
echo "</pre>";
echo "<pre>";
var_dump($catname);
echo "</pre>";
}
}
}
?>
This correctly gets the names and categories, but the URL's it returns are absolute full URL's, such as "http://example.com/shop/templates/theme.html".
Firstly, how do I retrieve relative URL's from Magento?
Secondly, the generated URL seems to only be correct if I set the web/unsecure/base_url setting to the http://example.com/shop/. If I set this to {{base_url}} instead (which we prefer during development since we use virtual-hosting based svn working copies), the /shop/ part is missing, i.e.: "http://example.com/templates/theme.html".
Any idea why?