magento 自定义订单属性
我正在尝试为从后端(管理员)面板创建的订单添加一些自定义属性到 magento 1.5.1.0 的结帐(销售)页面。 我尝试了这段代码,我可以在 eav_attribute 表中看到我的新属性,但是当我从后端下订单时,我看不到我的新属性。 我错过了什么..?
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('5', 'testattr', array(
'label' => 'testlabel',
'type' => 'varchar',
'input' => 'text',
'visible' => true,
'required' => false,
'position' => 5,
));
$eavConfig = Mage::getSingleton('eav/config');
$attribute = $eavConfig->getAttribute('5', 'testattr');
$attribute->setData('used_in_forms', array('checkout_register', 'adminhtml_checkout'));
$attribute->save();
谢谢..
i'm trying to add some custom attributes to the checkout(sales) page of magento 1.5.1.0 for orders created from the backend (administrator) panel.
I tried this code and i can see my new attribute in the eav_attribute table, but i can't see my new attribute when i make an order from the backend.
What am i missing..?
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('5', 'testattr', array(
'label' => 'testlabel',
'type' => 'varchar',
'input' => 'text',
'visible' => true,
'required' => false,
'position' => 5,
));
$eavConfig = Mage::getSingleton('eav/config');
$attribute = $eavConfig->getAttribute('5', 'testattr');
$attribute->setData('used_in_forms', array('checkout_register', 'adminhtml_checkout'));
$attribute->save();
Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
订单实体与普通实体不同,它们使用平面表而不是 EAV,这意味着仅分配属性是不够的。您必须更改平面表(我在这里尝试过)或创建其他表格,然后将它们连接到平面表格。事后看来,我应该采取第二种选择,它更安全。
我一直在仔细研究订单模板,可能存在通过较少使用的块来解决问题的方法。首先,让我们在
layout/local.xml
文件中进行更改,以便安全地防止升级覆盖;礼物选项块是以开放式方式构建的,因此添加它相对容易。显然,将
YOUR/TEMPLATE.phtml
替换为您将创建的文件的路径。插入的模板需要具有名称类似于order[testattr]
的输入字段,并且这些应该直接复制到数据库表中(根据Mage_Adminhtml_Model_Sales_Order_Create
>,如果我正确阅读源代码)。礼品选项块已在订单的Order entities are awkwardly not like normal entities, they use a flat table instead of EAV, which means that it's not enough to just assign an attribute. You must alter the flat table (which I tried here) or create additional tables then join them to the flat table. With hindsight I see I should have taken the second option, it's safer.
I've been looking a bit closer at the order template and there might a hackish sort of workaround via a lesser used block. To start with let's make changes in a
layout/local.xml
file so it's safe from overwriting by upgrades;The gift options block is constructed in an open-ended way so adding to it is relatively easy. Obviously replace
YOUR/TEMPLATE.phtml
with the path of a file you will create. The template being inserted needs to have input fields with names likeorder[testattr]
and those should be copied directly to the database table (according toMage_Adminhtml_Model_Sales_Order_Create
, if I am reading the source code right). The gift options block already creates a<fieldset>
inside the order's<form>
so only the input fields are needed.感谢 Clockworkgeek 的回复。我通过使用一些额外的地址属性找到了解决方案,因为它更容易(尽管我必须搜索很多)。
所以解决方案是..
然后根据这篇文章编辑文件。
Magento:在结帐中保存自定义地址属性
Thanks clockworkgeek for your replies. I found the solution by using some extra address attributes instead because it was a lot more easier (i had to search a lot though).
so the solution is..
and then edit the files according to this post.
Magento: save custom address attribute in checkout