首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >马根托。向订单添加订单备注属性

问马根托。向订单添加订单备注属性
EN

Stack Overflow用户
提问于 2011-11-16 21:09:08
回答 2查看 3.2K关注 0票数 0

我想将客户注释添加到我的订单实体中。目前我的设置脚本如下所示:

代码语言:javascript
复制
    <?php

$installer = $this;
/* @var $installer Mage_Sales_Model_Mysql4_Setup */

$installer->startSetup();

    $newFields = array(
        'k_customerordercomment' => array(
            'type'              => 'text',
            'label'                => 'Comments'
        ),
    );

    $entities = array('order');

    $setup = new Mage_Eav_Model_Entity_Setup('core_setup');

    foreach($newFields as $attributeName => $attributeDefs) {
        foreach ($entities as $entity) {
            $setup->addAttribute($entity, $attributeName, array(
                'position'             => 1,
                'type'              => $attributeDefs['type'],
                'label'                => $attributeDefs['label'],
                'global'            => 1,
                'visible'           => 1,
                'required'          => 0,
                'user_defined'      => 1,
                'searchable'        => 0,
                'filterable'        => 0,
                'comparable'        => 0,
                'visible_on_front'  => 1,
                'visible_in_advanced_search' => 0,
                'unique'            => 0,
                'is_configurable'   => 0,
                'position'          => 1,
            ));                
        }
    }



        $installer->getConnection()->addColumn(
        $installer->getTable('sales_flat_order'),
        'k_customerordercomment',
        'text NOT NULL DEFAULT ""'
    );

    $c = array (
        'backend_type'    => 'text',     // MySQL-Datatype
        'frontend_input'  => 'textarea', // Type of the HTML form element
        'is_global'       => '1',
        'is_visible'      => '1',
        'is_required'     => '0',
        'is_user_defined' => '0',
        'frontend_label'  => 'Customer Order Comment',
    );
    $setup->addAttribute('order', 'k_customerordercomment', $c);

    $installer->endSetup();

我在eav_attribute中获得条目,在sales_flat_order中添加列。问题是我不能通过setdata或setKCustomerordercomment来设置注释的值

但是,如果我在DB中设置值,然后从数据库加载order,我可以看到输入值。

怎么啦?

Magento 1.6

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-11-17 21:52:02

这就是对我有效的方法,我不知道为什么,也不知道为什么。但它是有效的。

代码语言:javascript
复制
<?php

$installer = $this;
/* @var $installer Mage_Sales_Model_Mysql4_Setup */

$installer->startSetup();

$newFields = array(
    'customerordercomment' => array(
        'type'              => 'text',
        'label'                => 'Comments'
    ),
);

$entities = array('order');

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

foreach($newFields as $attributeName => $attributeDefs) {
    foreach ($entities as $entity) {
        $setup->addAttribute($entity, $attributeName, array(
            'position'             => 1,
            'type'              => $attributeDefs['type'],
            'label'                => $attributeDefs['label'],
            'global'            => 1,
            'visible'           => 1,
            'required'          => 0,
            'user_defined'      => 1,
            'searchable'        => 0,
            'filterable'        => 0,
            'comparable'        => 0,
            'visible_on_front'  => 1,
            'visible_in_advanced_search' => 0,
            'unique'            => 0,
            'is_configurable'   => 0,
            'position'          => 1,
        ));                
    }
}



    $installer->getConnection()->addColumn(
    $installer->getTable('sales_flat_order'),
    'customerordercomment',
    'text NOT NULL DEFAULT ""'
);

$c = array (
  'backend_type'    => 'text',     // MySQL-Datatype
  'frontend_input'  => 'textarea', // Type of the HTML form element
  'is_global'       => '1',
  'is_visible'      => '1',
  'is_required'     => '0',
  'is_user_defined' => '0',
  'frontend_label'  => 'Customer Order Comment',
);
$setup->addAttribute('order', 'customerordercomment', $c);

$installer->endSetup();
票数 0
EN

Stack Overflow用户

发布于 2011-11-16 21:54:52

因为1.4版订单不使用eav srtukture。使用属性类型"static“,而不是文本和其他设置类。

‘'type'=>'static’

代码语言:javascript
复制
/* @var $installer Mage_Sales_Model_Mysql4_Setup */

$installer = $this;
$installer->startSetup();

$installer->addAttribute('order', 'field_name', array('type'=>'static', 'visible' => true, 'required' => false, 'is_user_defined' => true, 'note' => 'Field comment'));

$installer->endSetup();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8152186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档