【问题标题】:How to add a note for an attribute in magento?如何在magento中为属性添加注释?
【发布时间】:2012-11-12 15:59:27
【问题描述】:

我使用管理面板在 Magento 中创建了一个新的产品属性。但我找不到该属性的注释(即应在输入字段下方显示为有关它的额外信息的文本。)

是我遗漏了什么,还是无法在管理面板中实现?

这是一个属性注释的示例:

我正在使用 Magento 1.7 CE。

【问题讨论】:

    标签: magento attributes


    【解决方案1】:

    通过管理面板是不可能的。

    顺便说一句,您确实应该以编程方式添加属性。 (如果你的数据库崩溃,你就完蛋了)。

    你需要修改eav_attribute表的“note”列。

    您可以在升级脚本中使用updateAttribute() 命令对其进行修改。示例:

    $installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'color', 'note','my comment');
    

    【讨论】:

    【解决方案2】:

    嗯,这可能有点晚了,但无论如何,我今天遇到了类似的问题,并通过以下直观的方式解决了它:

    首先我的问题: 如何在扩展搜索页面中按自定义顺序获取属性?

    为此,我在这里找到了一些东西: http://www.magentocommerce.com/boards/viewthread/11782/ - 他们告诉: 您可能会使用 mysql 表中的自定义未使用字段“note”:“eav_attribute” 因此你可以改变 app\code\core\Mage\CatalogSearch\Model\Advanced.php 订购者 即

    来自:->setOrder('main_table.attribute_id', 'asc')

    至:->setOrder('main_table.note', 'asc')

    但是,你仍然有问题,如何正确编辑这些东西,而不是直接在 mysql-client 中编辑任何东西;从现在开始,我遇到了你的问题,我的解决方案:

    模型:获取/设置

    • 在 app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php 中
    • grep:类 Mage_Eav_Model_Entity_Attribute_Abstract ex
    • 添加:搜索后最佳:“n getName”

    /** * Get attribute note * * @return string */ public function getNote() { return $this->_getData('note'); } /** * Set attribute note * * @param string $name * @return Mage_Eav_Model_Entity_Attribute_Abstract */ public function setNote($note) { return $this->setData('note', $note); }

    控制器:设置

    • 在 app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php 中
    • (好吧,这是一条捷径,我认为您可以在某处为“note_text”添加一些属性,但我没有来自 magento 的计划)
    • 搜索:“默认值”并扩展:
    • 来自:

    $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']); if ($defaultValueField) { $data['default_value'] = $this->getRequest()->getParam($defaultValueField); }

    • 到:

    $defaultValueField = $model->getDefaultValueByInput($data['frontend_input']); if ($defaultValueField) { $data['default_value'] = $this->getRequest()->getParam($defaultValueField); $data['note'] = $this->getRequest()->getParam('note_text'); }

    查看

    • 在 ./app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php 中
    • 之后:

      $fieldset->addField('default_value_text', 'text', array(

    • 添加:

      $fieldset->addField('note_text', 'text', array( 'name' => 'note_text', 'label' => Mage::helper('eav')->__('Note Value'), 'title' => Mage::helper('eav')->__('Note Value'), 'value' => $attributeObject->getDefaultValue(), ));

    最后我通过以下方式初始化了 mysql 表中的 note-field:

    update eav_attribute set note=lpad(attribute_id,10,'0000000000') where attribute_id not in(84,100);
    

    id 为 84 和 100 的属性已经有了一些注释。

    【讨论】:

    • 直接编辑magento核心文件不是一个好主意。比西的回答真是个好主意。
    猜你喜欢
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    • 1970-01-01
    相关资源
    最近更新 更多