Magento:如何获取不同商店视图的类别页面URL键?

Tha*_*anu 3 php url magento

我正在尝试获取不同商店视图的类别页面的页面URL密钥.基本上我在Magento安装中设置了3个商店.现在我想在我的类别页面中实现hrefhang标签.但是当我在默认存储区时,我无法访问其他商店视图的类别URL键,反之亦然.

我有类别对象,我来自,

$category = Mage::registry('current_category');
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

fan*_*ice 6

看起来在不同的商店下获取类别URL的最佳方式是使用MagentoMage_Core_Model_App_Emulation.这是一个如何做到这一点的例子:

/**
 * @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);
Run Code Online (Sandbox Code Playgroud)

  • 它可以工作,但它的执行时间比Thanu的解决方案多20倍 (2认同)