我试图获取不同商店视图的类别页面的页面URL密钥。基本上我在Magento安装中设置了3个商店。现在我想在我的类别页面中实现hrefhang标签。 但是当我在默认商店中时,我无法访问其他商店视图的类别URL键,反之亦然。
我有类别对象,我来自
Selenium
有什么想法吗?
答案 0 :(得分:6)
将类别网址在当前不同的商店下获取的最佳方法似乎是make use of Magento’s Mage_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);
答案 1 :(得分:4)
我的解决方案,效果很好
/**
* @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;
答案 2 :(得分:0)
您可以执行以下操作(在环境仿真中应该花费更少的钱):
$currentStore = Mage::app()->getStore();
Mage::app()->setCurrentStore(Mage::app()->getStore($yourAltStoreId));
$categoryLink = Mage::getModel('catalog/category')->load($yourCategoryId)->getUrl();
Mage::app()->setCurrentStore($currentStore);