我可以通过手动编辑以下文件来添加复选框:
app/design/adminhtml/default/default/template/sales/order/view/info.phtml
但如何在不通过magento模块编辑此文件的情况下添加自定义属性(复选框)以及如何将值保存到数据库?
我已经知道如何创建模块,但我不知道如何使用magento模块创建自定义属性。
我真的需要一些建议,从哪里开始或如何开始。
答案 0 :(得分:0)
创建文件夹:Orderattribute
路径:app/code/local/Custom/
创建文件config.xml。
路径:app/code/local/Custom/Orderattribute/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Custom_Orderattribute>
<version>0.1.0</version>
</Custom_Orderattribute>
</modules>
<global>
<fieldsets>
<sales_convert_quote>
<package_attr>
<to_order>*</to_order>
</package_attr>
</sales_convert_quote>
<sales_convert_order>
<package_attr>
<to_quote>*</to_quote>
</package_attr>
</sales_convert_order>
</fieldsets>
<resources>
<orderattribute_setup>
<setup>
<module>Custom_Orderattribute</module>
<class>Mage_Sales_Model_Mysql4_Setup</class>
</setup>
</orderattribute_setup>
</resources>
<resources>
<orderattribute_setup>
<setup>
<module>Custom_Orderattribute</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</orderattribute_setup>
</resources>
<helpers>
<orderattribute>
<class>Custom_Orderattribute_Helper</class>
</orderattribute>
</helpers>
</global>
</config>
创建文件夹:
路径:app/code/local/Custom/Orderattribute/Helper
创建Helper.php文件:
路径:app/code/local/Custom/Orderattribute/Helper/Data.php
<?php
class Custom_Orderattribute_Helper_Data extends Mage_Core_Helper_Abstract {
}
创建文件夹: 路径:
app/code/local/Custom/Orderattribute/sql
创建文件夹
路径:app/code/local/Custom/Orderattribute/orderattribute_setup
创建文件mysql4-install-0.1.0.php
路径:app/code/local/Custom/Orderattribute/orderattribute_setup/mysql4-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("order", "package_attr", array("type"=>"varchar"));
$installer->addAttribute("quote", "package_attr", array("type"=>"varchar"));
$installer->endSetup();
修改此文件:
app\design\adminhtml\default\default\template\sales\order\view\info.phtml
<?php if($_order->getPackageAttr()): ?>
<?php $status='checked'; ?>
<?php endif; ?>
<tr>
<td class="label"><label><?php echo Mage::helper('sales')->__('Other Options') ?></label></td>
<td class="value"><strong> <input type="checkbox" name="option" value="My option" <?php echo $status; ?>></strong></td>
</tr>