Magento的。添加订单评论属性以订购

时间:2011-11-16 13:09:08

标签: magento

我想将客户评论添加到我的订单实体。目前我的设置脚本如下:

    <?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();

我在sales_flat_order中添加了eav_attribute和column中的条目。 问题是我无法通过setdata或setKCustomerordercomment

设置注释值

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

有什么问题?

Magento 1.6。

2 个答案:

答案 0 :(得分:0)

由于1.4版订单不使用eav srtukture。 使用属性类型“static”而不是文本和其他安装类。

'类型'=&GT; '静止'

/* @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();

答案 1 :(得分:0)

这对我有用,我不知道为什么以及怎么做。但它确实有效。

<?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();