运行Magento 1.9.0.2,我正在尝试通过模块在地址表单中添加2个新的复选框字段。
问题:未执行数据库脚本(请注意第一行的die()
函数)
症状:
core_resources
table {base_dir}/var/log/
为777,没有生成日志问题:我错过了什么?
以下是{base_dir}/app/code/local/Tdg/Check/etc/config.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Tdg_Check>
<version>1.0.1</version>
</Tdg_Check>
</modules>
<admin>
<fieldsets>
<customer_dataflow>
<chk_commercial><billing>1</billing><shipping>1</shipping></chk_commercial>
<chk_residential><billing>1</billing><shipping>1</shipping></chk_residential>
</customer_dataflow>
</fieldsets>
</admin>
<global>
<models>
<check>
<class>Tdg_Check_Model</class>
</check>
</models>
<resources>
<check_setup>
<setup>
<module>Tdg_Check</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</check_setup>
<check_write>
<connection>
<use>core_write</use>
</connection>
</check_write>
<check_read>
<connection>
<use>core_read</use>
</connection>
</check_read>
</resources>
<fieldsets>
<sales_copy_order_billing_address>
<chk_commercial><to_order>*</to_order></chk_commercial>
<chk_residential><to_order>*</to_order></chk_residential>
</sales_copy_order_billing_address>
<sales_copy_order_shipping_address>
<chk_commercial><to_order>*</to_order></chk_commercial>
<chk_residential><to_order>*</to_order></chk_residential>
</sales_copy_order_shipping_address>
<sales_convert_quote_address>
<chk_commercial><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></chk_commercial>
<chk_residential><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></chk_residential>
</sales_convert_quote_address>
<sales_convert_order_address>
<chk_commercial><to_quote_address>*</to_quote_address></chk_commercial>
<chk_residential><to_quote_address>*</to_quote_address></chk_residential>
</sales_convert_order_address>
<customer_address>
<chk_commercial><to_quote_address>*</to_quote_address></chk_commercial>
<chk_residential><to_quote_address>*</to_quote_address></chk_residential>
</customer_address>
<checkout_onepage_billing>
<chk_commercial><to_customer>*</to_customer></chk_commercial>
<chk_residential><to_customer>*</to_customer></chk_residential>
</checkout_onepage_billing>
</fieldsets>
</global>
</config>
SQL Update文件{base_dir}/app/code/Tdg/Check/sql/check_setup/mysql4-install-1.0.1.php
:
<?php
die('Installing Module');
/* @var $installer Mage_Customer_Model_Entity_Setup */
$installer = $this;
$installer->startSetup();
/* @var $addressHelper Mage_Customer_Helper_Address */
$addressHelper = Mage::helper('customer/address');
$store = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);
/* @var $eavConfig Mage_Eav_Model_Config */
$eavConfig = Mage::getSingleton('eav/config');
// update customer address user defined attributes data
$attributes = array(
'chk_commercial' => array(
'label' => 'Chk Commercial',
'type' => 'int',
'input' => 'checkbox',
'default' => 0,
'is_user_defined' => 1,
'is_system' => 0,
'is_visible' => 1,
'sort_order' => 140,
'is_required' => 1,
'multiline_count' => 0,
'validate_rules' => array(
'max_text_length' => 1,
'min_text_length' => 1
),
),
'chk_residential' => array(
'label' => 'Chk Residential',
'type' => 'int',
'input' => 'checkbox',
'default' => 0,
'is_user_defined' => 1,
'is_system' => 0,
'is_visible' => 1,
'sort_order' => 141,
'is_required' => 1,
'multiline_count' => 0,
'validate_rules' => array(
'max_text_length' => 1,
'min_text_length' => 1
),
),
);
foreach ($attributes as $attributeCode => $data) {
$attribute = $eavConfig->getAttribute('customer_address', $attributeCode);
$attribute->setWebsite($store->getWebsite());
$attribute->addData($data);
$usedInForms = array(
'adminhtml_customer_address',
'customer_address_edit',
'customer_register_address'
);
$attribute->setData('used_in_forms', $usedInForms);
$attribute->save();
}
$installer->run("
ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD COLUMN `chk_commercial` VARCHAR(1) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`;
ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD COLUMN `chk_commercial` VARCHAR(1) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`;
ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD COLUMN `chk_residential` VARCHAR(1) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`;
ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD COLUMN `chk_residential` VARCHAR(1) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`;
");
$installer->endSetup();
?>
最后,它是模块定义文件Tdg_Check.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Tdg_Check>
<active>true</active>
<codePool>local</codePool>
</Tdg_Check>
</modules>
</config>
答案 0 :(得分:1)
存储在代码字段中的Magento模块条目如下: yourmodulename_setup
检查core_resource表的代码字段中的check_setup等记录。
因此,对于再次运行安装脚本,您必须在模块中找到模块记录并删除该记录。 它会自动再次运行脚本。