您需要在此添加新的文件(安裝腳本)和文件名應該是,
mysql4-upgrade-0.0.2-0.0.1.php
所以,現在你可以添加你的安裝腳本一樣,
$installer = $this;
$installer->startSetup();
$entity = $installer->getEntityTypeId('customer');
if(!$installer->attributeExists($entity, 'attribute_2')) {
$installer->removeAttribute($entity, 'attribute_2');
}
$installer->addAttribute($entity, 'attribute_2', array(
'type' => 'text',
'label' => 'Attribute 2',
'input' => 'text',
'visible' => TRUE,
'required' => FALSE,
'default_value' => '',
'adminhtml_only' => '0'
));
$forms = array(
'adminhtml_customer',
'customer_account_edit'
);
$attribute = Mage::getSingleton('eav/config')->getAttribute($installer->getEntityTypeId('customer'), 'attribute_2');
$attribute->setData('used_in_forms', $forms);
$attribute->save();
$installer->endSetup();
而你需要也更新config.xml文件。因此,它應該是,
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Custom_Customerattribute>
<version>0.0.2</version>
</Custom_Customerattribute>
</modules>
<global>
<resources>
<customerattribute_setup>
<setup>
<module>Custom_Customerattribute</module>
<class>Custom_Customerattribute_Model_Mysql4_Setup</class>
</setup>
....
</customerattribute_setup>
</resources>
</global>
</config>
欲瞭解更多信息,請here。如果您有任何疑問,請在這裏留言。
更新: 對不起。文件名應該是這樣的,
mysql4-upgrade-0.0.2-0.0.1.php
core_resource
表包含模塊條目。現在0.0.2
也被更新。所以magento不會查找你的模塊(更新)的XML文件加載。所以你需要的文件名又變成mysql4-upgrade-0.0.3-0.0.2.php
或刪除數據庫中的該條目和重命名你的模塊版本,以新鮮的像mysql4-upgrade-0.0.0.php
更新2:
在這裏,我賦予了新的代碼,我檢查我在當地的做工精細,
應用程序/代碼/本地/包/ MODULENAME的/ etc/config.xml中
<?xml version="1.0"?>
<config>
<modules>
<Packagename_Modulename>
<version>0.0.0</version>
</Packagename_Modulename>
</modules>
<global>
<helpers>
<modulename>
<class>Packagename_Modulename_Helper</class>
</modulename>
</helpers>
<models>
<modulename>
<class>Packagename_Modulename_Model</class>
<resourceModel>modulename_mysql4</resourceModel>
</modulename>
</models>
<resources>
<customerattribute1415104755_setup>
<setup>
<module>Packagename_Modulename</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customerattribute1415104755_setup>
<customerattribute1415104755_write>
<connection>
<use>core_write</use>
</connection>
</customerattribute1415104755_write>
<customerattribute1415104755_read>
<connection>
<use>core_read</use>
</connection>
</customerattribute1415104755_read>
</resources>
</global>
</config>
應用程序/代碼/本地/包/模塊名/助手/Data.php
<?php
class Packagename_Modulename_Helper_Data extends Mage_Core_Helper_Abstract
{
}
應用程序/代碼/本地/包/ MODULENAME/SQL/customerattribute1415104755_setup/mysql4安裝-0.0.0。PHP
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "myattrbute1", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-1",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute1");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->addAttribute("customer", "myattrbute2", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-2",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute2");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->addAttribute("customer", "myattrbute3", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-3",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute3");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->addAttribute("customer", "myattrbute4", array(
"type" => "varchar",
"backend" => "",
"label" => "My attribute-4",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "myattrbute4");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
;
$attribute->save();
$installer->endSetup();
最後啓用, 應用程序的/ etc /模塊的模塊/ Packagename_Modulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Packagename_Modulename>
<active>true</active>
<codePool>local</codePool>
<version>0.0.0</version>
</Packagename_Modulename>
</modules>
</config>
謝謝,但這仍然無法正常工作。我已經刷新所有緩存之前和之後,清除緩存和緩存存儲。正如你所說的那樣也稱爲安裝文件 - 'mysql4-install-0.0.1-0.0.2.php'和'mysql4-install-0.0.2.php'沒有運氣 – 2014-11-04 10:38:11
對不起。文件名應該像這樣mysql4-install-0.0.2-0.0.1.php。我已經更新了我的答案,請檢查它。 – Elavarasan 2014-11-04 10:46:50
更新了文件名,但仍然無法使用。我查看了'core_resource'數據庫表,並可以看到該模塊的更新的0.0.2版本。在網上看看它看起來像刪除,然後再次運行會解決,它確實,不知道爲什麼?! – 2014-11-04 11:08:54