如何在Magento中获取原始(所有商店视图)当前类别名称?

Kov*_*NET 2 php magento

如何在Magento中获取"原始"类别名称,其中我已经为当前商店视图翻译了类别名称.我想在All Store视图中输入类别名称,因为我想将原始(英文)名称发送给GA进行跟踪 - 当我在类别页面时,我需要这个名称.

我可以通过这种方式获得本地化的类别名称:

<?php 
$currentCategory = Mage::registry('current_category');
$name = $currentCategory->getName();
?>
Run Code Online (Sandbox Code Playgroud)

但无法在没有额外调用数据库的情况下找到获取未翻译名称的方法.

Fab*_*ler 5

如上所述,这将需要额外的数据库请求.以下应该有效:

$defaultStoreCategory = Mage::getModel('catalog/category');
$defaultStoreCategory->setStoreId(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
$defaultStoreCategory->load($currentCategory->getId());

$name = $defaultStoreCategory->getName();
Run Code Online (Sandbox Code Playgroud)

  • 您的代码仍然为我提供了本地化的类别名称,但是如果我省略对“getResource()”的调用并直接在模型上调用“setStoreId()”(如下面建议的@magento-code),那么它就可以工作 (2认同)