magento -- 修改代码让后台属性组合里的属性显示中文

piaoling  2011-07-18 14:13:35

Magento后台属性组合管理里的各个属性显示的是属性的code,也就是说,即便给每个属性加上了中文的标签(label),这里显示的依然是大片的英文,对一个不懂技术的后台管理者来说,这样多的英文时他们不愿意看到的,所以要想办法变一下。

 

打开/app/code/local/Mage/Adminhtml/Block/Catalog/Product/Attribute/Set/Main.php文件,找到几个用来显示的代码,替换成如下所示

 

  1. public function getGroupTreeJson()  
  2.     {  
  3.         $items = array();  
  4.         $setId = $this->_getSetId();  
  5.         /* @var $groups Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection */  
  6.         $groups = Mage::getModel('eav/entity_attribute_group')  
  7.             ->getResourceCollection()  
  8.             ->setAttributeSetFilter($setId)  
  9.             ->load();  
  10.         $configurable = Mage::getResourceModel('catalog/product_type_configurable_attribute')  
  11.             ->getUsedAttributes($setId);  
  12.         /* @var $node Mage_Eav_Model_Entity_Attribute_Group */  
  13.         foreach ($groups as $node) {  
  14.             $item = array();  
  15.             //Alex   
  16.             $item['text']       = $this->__($node->getAttributeGroupName());  
  17.             $item['id']         = $node->getAttributeGroupId();  
  18.             $item['cls']        = 'folder';  
  19.             $item['allowDrop']  = true;  
  20.             $item['allowDrag']  = true;  
  21.             $nodeChildren = Mage::getResourceModel('catalog/product_attribute_collection')  
  22.                 ->setAttributeGroupFilter($node->getId())  
  23.                 ->addVisibleFilter()  
  24.                 ->checkConfigurableProducts()  
  25.                 ->load();  
  26.             if ($nodeChildren->getSize() > 0) {  
  27.                 $item['children'] = array();  
  28.                 foreach ($nodeChildren->getItems() as $child) {  
  29.                     /* @var $child Mage_Eav_Model_Entity_Attribute */  
  30.                     $attr = array(  
  31.                     //Alex   
  32.                         'text'              => $this->__($child->getFrontendLabel()),  
  33.                         'id'                => $child->getAttributeId(),  
  34.                         'cls'               => (!$child->getIsUserDefined()) ? 'system-leaf' : 'leaf',  
  35.                         'allowDrop'         => false,  
  36.                         'allowDrag'         => true,  
  37.                         'leaf'              => true,  
  38.                         'is_user_defined'   => $child->getIsUserDefined(),  
  39.                         'is_configurable'   => (int)in_array($child->getAttributeId(), $configurable),  
  40.                         'entity_id'         => $child->getEntityAttributeId()  
  41.                     );  
  42.                     $item['children'][] = $attr;  
  43.                 }  
  44.             }  
  45.             $items[] = $item;  
  46.         }  
  47.         return Mage::helper('core')->jsonEncode($items);  
  48.     }  
  49.   
  50. public function getAttributeTreeJson()  
  51.     {  
  52.         $items = array();  
  53.         $setId = $this->_getSetId();  
  54.         $collection = Mage::getResourceModel('catalog/product_attribute_collection')  
  55.             ->setAttributeSetFilter($setId)  
  56.             ->load();  
  57.         $attributesIds = array('0');  
  58.         /* @var $item Mage_Eav_Model_Entity_Attribute */  
  59.         foreach ($collection->getItems() as $item) {  
  60.             $attributesIds[] = $item->getAttributeId();  
  61.         }  
  62.         $attributes = Mage::getResourceModel('catalog/product_attribute_collection')  
  63.             ->setAttributesExcludeFilter($attributesIds)  
  64.             ->addVisibleFilter()  
  65.             ->load();  
  66.         foreach ($attributes as $child) {  
  67.             $attr = array(  
  68.             //Alex   
  69.                 'text'              => $this->__($child->getFrontendLabel()),  
  70.                 'id'                => $child->getAttributeId(),  
  71.                 'cls'               => 'leaf',  
  72.                 'allowDrop'         => false,  
  73.                 'allowDrag'         => true,  
  74.                 'leaf'              => true,  
  75.                 'is_user_defined'   => $child->getIsUserDefined(),  
  76.                 'is_configurable'   => false,  
  77.                 'entity_id'         => $child->getEntityId()  
  78.             );  
  79.             $items[] = $attr;  
  80.         }  
  81.         if (count($items) == 0) {  
  82.             $items[] = array(  
  83.                 'text'      => Mage::helper('catalog')->__('Empty'),  
  84.                 'id'        => 'empty',  
  85.                 'cls'       => 'folder',  
  86.                 'allowDrop' => false,  
  87.                 'allowDrag' => false,  
  88.             );  
  89.         }  
  90.         return Mage::helper('core')->jsonEncode($items);  
  91.     }  

 

$child->getFrontendLabel()即获取该属性的标签值,而不是原来的code值

修改后效果如下

from:http://blog.csdn.net/shuishui8310/article/details/6308961

类别 :  magento(258)  |  浏览(3829)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: