Magento.向订单添加订单注释属性 [英] Magento. Add order comment attribute to order

查看:132
本文介绍了Magento.向订单添加订单注释属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to add customer comments to my order entity. Currently my setup script looks like:

    <?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设置注释的值

I get entries in eav_attribute and column added in sales_flat_order. The problem is that I can't set values of comments by setdata or setKCustomerordercomment

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

But if i set value in DB and then load order from database I can see entered value.

怎么了?

Magento 1.6.

Magento 1.6.

推荐答案

这对我有用,我不知道为什么以及如何.但这有效.

This is what worked for me, I don't know why and how. But it works.

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

这篇关于Magento.向订单添加订单注释属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆