`
shuishui8310
  • 浏览: 150074 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

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

PHP 
阅读更多

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


 

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

 

public function getGroupTreeJson()
    {
        $items = array();
        $setId = $this->_getSetId();
        /* @var $groups Mage_Eav_Model_Mysql4_Entity_Attribute_Group_Collection */
        $groups = Mage::getModel('eav/entity_attribute_group')
            ->getResourceCollection()
            ->setAttributeSetFilter($setId)
            ->load();
        $configurable = Mage::getResourceModel('catalog/product_type_configurable_attribute')
            ->getUsedAttributes($setId);
        /* @var $node Mage_Eav_Model_Entity_Attribute_Group */
        foreach ($groups as $node) {
            $item = array();
            //Alex
            $item['text']       = $this->__($node->getAttributeGroupName());
            $item['id']         = $node->getAttributeGroupId();
            $item['cls']        = 'folder';
            $item['allowDrop']  = true;
            $item['allowDrag']  = true;
            $nodeChildren = Mage::getResourceModel('catalog/product_attribute_collection')
                ->setAttributeGroupFilter($node->getId())
                ->addVisibleFilter()
                ->checkConfigurableProducts()
                ->load();
            if ($nodeChildren->getSize() > 0) {
                $item['children'] = array();
                foreach ($nodeChildren->getItems() as $child) {
                    /* @var $child Mage_Eav_Model_Entity_Attribute */
                    $attr = array(
                    //Alex
                        'text'              => $this->__($child->getFrontendLabel()),
                        'id'                => $child->getAttributeId(),
                        'cls'               => (!$child->getIsUserDefined()) ? 'system-leaf' : 'leaf',
                        'allowDrop'         => false,
                        'allowDrag'         => true,
                        'leaf'              => true,
                        'is_user_defined'   => $child->getIsUserDefined(),
                        'is_configurable'   => (int)in_array($child->getAttributeId(), $configurable),
                        'entity_id'         => $child->getEntityAttributeId()
                    );
                    $item['children'][] = $attr;
                }
            }
            $items[] = $item;
        }
        return Mage::helper('core')->jsonEncode($items);
    }

public function getAttributeTreeJson()
    {
        $items = array();
        $setId = $this->_getSetId();
        $collection = Mage::getResourceModel('catalog/product_attribute_collection')
            ->setAttributeSetFilter($setId)
            ->load();
        $attributesIds = array('0');
        /* @var $item Mage_Eav_Model_Entity_Attribute */
        foreach ($collection->getItems() as $item) {
            $attributesIds[] = $item->getAttributeId();
        }
        $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
            ->setAttributesExcludeFilter($attributesIds)
            ->addVisibleFilter()
            ->load();
        foreach ($attributes as $child) {
            $attr = array(
            //Alex
                'text'              => $this->__($child->getFrontendLabel()),
                'id'                => $child->getAttributeId(),
                'cls'               => 'leaf',
                'allowDrop'         => false,
                'allowDrag'         => true,
                'leaf'              => true,
                'is_user_defined'   => $child->getIsUserDefined(),
                'is_configurable'   => false,
                'entity_id'         => $child->getEntityId()
            );
            $items[] = $attr;
        }
        if (count($items) == 0) {
            $items[] = array(
                'text'      => Mage::helper('catalog')->__('Empty'),
                'id'        => 'empty',
                'cls'       => 'folder',
                'allowDrop' => false,
                'allowDrag' => false,
            );
        }
        return Mage::helper('core')->jsonEncode($items);
    }

 

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

修改后效果如下


 

  • 大小: 23.9 KB
  • 大小: 23.3 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics