【问题标题】:Magento: Custom attributes option's new value fieldMagento:自定义属性选项的新值字段
【发布时间】:2013-12-02 16:55:59
【问题描述】:

我想在 admin 的 Manage Attribute Options 菜单的 Attribute option 中添加一个自定义字段。像管理员中位置列旁边的 value 列。我附上了一张图片。

我做了什么...(Magento 1.8)

  1. eav_attribute_option 字段之后在eav_attribute_option 表中创建了一个名为value 的新字段。

  2. 更改了magento\app\design\adminhtml\default\default\template\eav\attribute\options.phtml 此文件以在 Position 列旁边显示 Value 列。

  3. 更改了此文件 magento\app\code\core\Mage\Eav\Block\Adminhtml\Attribute\Edit\Options\Abstract.php 中的 getOptionValues() 方法,以从数据库中获取我的自定义 value 列的数据并显示在管理端。它以管理员形式显示 db 的默认值。

    但是当我想从管理面板保存数据时,数据并没有保存在数据库中。

我一直在尝试找到实际处理写入数据库的模型或控制器,以确保我的新字段也保存。

任何帮助将不胜感激。

(我会发布一张图片让您理解,但我不能,因为我需要 10 分才能做到。)

【问题讨论】:

    标签: magento options custom-attributes


    【解决方案1】:

    知道了!

    更新:Mage/Eav/Model/Resource/Entity/Attribute.php

    在函数中:_saveOption(Mage_Core_Model_Abstract $object)

    改变:

    $sortOrder = !empty($option[’order’][$optionId]) ? $option[’order’][$optionId] : 0; 
    if (!$intOptionId) { 
    $data = array( 
    ‘attribute_id’ => $object->getId(), 
    ‘sort_order’ => $sortOrder, 
    ); 
    $adapter->insert($optionTable, $data); 
    $intOptionId = $adapter->lastInsertId($optionTable); 
    } else { 
    $data = array(’sort_order’ => $sortOrder); 
    $where = array(’option_id =?’ => $intOptionId); 
    $adapter->update($optionTable, $data, $where); 
    }
    

    为此:

    $sortOrder = !empty($option[’order’][$optionId]) ? $option[’order’][$optionId] : 0; 
    $yourAttribute = (isset($option[’your_attr_field’]) && !empty($option[’your_attr_field’][$optionId])) ? $option[’your_attr_field’][$optionId] : ‘’; 
    if (!$intOptionId) { 
    $data = array( 
    ‘attribute_id’ => $object->getId(), 
    ‘sort_order’ => $sortOrder, 
    ‘your_attr_field’ => $yourAttribute 
    ); 
    $adapter->insert($optionTable, $data); 
    $intOptionId = $adapter->lastInsertId($optionTable); 
    } else { 
    $data = array(’sort_order’ => $sortOrder, ‘your_attr_field’ => $yourAttribute); 
    $where = array(’option_id =?’ => $intOptionId); 
    $adapter->update($optionTable, $data, $where); 
    }
    

    我可以使用一些帮助来以“Magento 方式”进行所有这些更改

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多