我需要创建自定义订单属性。我试过下面的代码。运行后,代码属性不会在sales_flat_order
表中显示为新列。
<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('order', 'newfield1', array(
'type' => 'int',
'global' => 0,
'visible' => 0,
'required' => 0,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'visible_in_advanced_search' => 0,
'unique' => 0,
'is_configurable' => 0,
'default' => 0,
));
$installer->endSetup();
但是有一条记录是在'eav_attribute'表下创建的。但是当我尝试使用下面的代码向该属性添加值时,它会产生系统错误;
$order = Mage::getModel('sales/order')->load(200);
$order->setNewfield1('dadhuh');
$order->save();
错误: 注意:会话已经启动 - 忽略第125行的C:\ xampp \ htdocs \ abcproject \ app \ code \ core \ Mage \ Core \ Model \ Session \ Abstract \ Varien.php中的session_start()
任何人都可以帮我解决这个问题。任何人都可以告诉我这里我做错了什么。
谢谢
答案 0 :(得分:0)
检查此.try以在系统上创建相同的目录,这将创建名为&#34; customfield &#34;
的新销售订单属性应用程序/代码/本地/ Knkm / Orderattribute的/ etc / config.xml中
<?xml version="1.0"?>
<config>
<modules>
<Knkm_Orderattribute>
<version>0.1.0</version>
</Knkm_Orderattribute>
</modules>
<global>
<helpers>
<orderattribute>
<class>Knkm_Orderattribute_Helper</class>
</orderattribute>
</helpers>
<models>
<orderattribute>
<class>Knkm_Orderattribute_Model</class>
<resourceModel>orderattribute_mysql4</resourceModel>
</orderattribute>
</models>
<resources>
<salesattribute1446018370_setup>
<setup>
<module>Knkm_Orderattribute</module>
<class>Mage_Sales_Model_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</salesattribute1446018370_setup>
<salesattribute1446018370_write>
<connection>
<use>core_write</use>
</connection>
</salesattribute1446018370_write>
<salesattribute1446018370_read>
<connection>
<use>core_read</use>
</connection>
</salesattribute1446018370_read>
</resources>
</global>
</config>
应用程序/代码/本地/ Knkm / Orderattribute /助手/ Data.php
<?php
class Knkm_Orderattribute_Helper_Data extends Mage_Core_Helper_Abstract
{
}
/app/code/local/Knkm/Orderattribute/sql/salesattribute1446018370_setup/mysql4-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("order", "customfield", array("type"=>"varchar"));
$installer->endSetup();
应用程序的/ etc /模块/ Knkm_Orderattribute.xml
<?xml version="1.0"?>
<config>
<modules>
<Knkm_Orderattribute>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Knkm_Orderattribute>
</modules>
</config>
希望这能完成你的工作。
感谢
答案 1 :(得分:0)
试试这个,
<?php require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'varchar'
'backend_type' => 'varchar',
'frontend_input' => 'varchar',
'is_user_defined' => true,
'label' => 'custom_label',
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'default' => ''
);
$installer->addAttribute('order', 'custom_attribute', $attribute);
$installer->addAttribute('quote', 'custom_attribute', $attribute);
$installer->endSetup();
echo 'success';