Magento: How to get category page URLs for different store types?

I am trying to get the url of a category page url for different kinds of store. Basically I have 3 stores installed in my Magento installation. Now I want to implement hrefhang tags on category pages. But I cannot access the urls of categories of other kinds of storage when I am in the default storage and vice versa.

I have a category object from which I am getting,

$category = Mage::registry('current_category');

      

Any ideas?

+3


source to share


2 answers


My solution, works well



/**
 * @var $store_id  - The numeric ID of the store view to get the URL from.
 * @var $store_url - Base URL of the store
 */

 $store_url   = Mage::app()->getStore($store_id)
                ->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);

 $objcategory = Mage::registry('current_category');
 $categoryId  = $objcategory->getId();
 $caturlkey   = Mage::getModel('catalog/category')
                    ->setStoreId($store_id)->load($categoryId)->getUrlKey();

 $altUrl      = $store_url.$caturlkey;

      

+4


source


It seems the best way to get category URLs in a different store than the current one is to use MagentosMage_Core_Model_App_Emulation

. Here's an example of how you could do it:



/**
 * @var $categoryId - The numeric category ID you want to get the URL of.
 * @var $altStoreId - The numeric ID of the other store view to get the URL from.
 */
$env = Mage::getSingleton('core/app_emulation')->startEnvironmentEmulation($altStoreId);
$category = Mage::getModel('catalog/category')->load($categoryId);
$altUrl = $category->getUrl();
Mage::getSingleton('core/app_emulation')->stopEnvironmentEmulation($env);

      

+6


source







All Articles