今天下午,我一直試圖在Magento中創建一個模塊,它只是爲類別添加更多屬性。Magento模塊的安裝問題 - 爲類別添加屬性
我會通過我創建至今的腳本運行...
應用程序的/ etc /模塊/ Comp_Categoryattributes.xml
<?xml version="1.0"?>
<config>
<modules>
<Comp_Categoryattributes>
<active>true</active>
<codePool>local</codePool>
</Comp_Categoryattributes>
</modules>
</config>
應用程序/代碼/本地/比較/ Categoryattributes /等/ config.xml中
<?xml version="1.0"?>
<config>
<modules>
<Comp_Categoryattributes>
<version>0.1.0</version>
</Comp_Categoryattributes>
</modules>
<global>
<models>
<categoryattributes>
<class>Comp_Categoryattributes_Model</class>
<resourceModel>categoryattributes_mysql4</resourceModel>
</categoryattributes>
<categoryattributes_mysql4>
<class>Comp_Categoryattributes_Model_mysql4</class>
</categoryattributes_mysql4>
</models>
<resources>
<categoryattributes_setup>
<setup>
<module>Comp_Categoryattributes</module>
<class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</categoryattributes_setup>
<ncategoryattributes_setup_write>
<connection>
<use>core_write</use>
</connection>
</categoryattributes_setup_write>
<categoryattributes_setup_read>
<connection>
<use>core_read</use>
</connection>
</categoryattributes_setup_read>
</resources>
</global>
</config>
然後最後,http://inchoo.net/ecommerce/magento/how-to-add-new-custom-category-attribute-in-magento/ 應用程序/代碼這個禮節/本地/比較/ Categoryattributes/SQL/categoryattributes_setup/mysq L4安裝-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();
$entityTypeId = $installer->getEntityTypeId('catalog_category');
$attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('catalog_category', 'twitter_user', array(
'type' => 'int',
'label' => 'Twitter Username',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => 0
));
$installer->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'twitter_user',
'11' //last Magento's attribute position in General tab is 10
);
$attributeId = $installer->getAttributeId($entityTypeId, 'twitter_user');
$installer->run("
INSERT INTO `{$installer->getTable('catalog_category_entity_int')}`
(`entity_type_id`, `attribute_id`, `entity_id`, `value`)
SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1'
FROM `{$installer->getTable('catalog_category_entity')}`;
");
//this will set data of your custom attribute for root category
Mage::getModel('catalog/category')
->load(1)
->setImportedCatId(0)
->setInitialSetupFlag(true)
->save();
//this will set data of your custom attribute for default category
Mage::getModel('catalog/category')
->load(2)
->setImportedCatId(0)
->setInitialSetupFlag(true)
->save();
$installer->endSetup();
?>
該模塊出現在後端罰款禁用模塊輸出範圍,但我沒有看到categoryattribute_setup在core_resource表出現在所有?有什麼明顯的我失蹤了嗎?
乾杯傢伙,
湯姆
在你的安裝腳本頂部扔一個die(),刷新緩存,然後點擊你網站的任何頁面(只需要Mage :: run()來觸發)。看看你是否死了。 – benmarks
...並且不要忘記爲你的模塊刪除core_setup表中的條目,否則不會執行新的安裝。 – tecmec
歡迎回復chaps。 Ben - 我在我的安裝腳本中添加了一個die(),但這些站點正常工作。我想這幾乎證實了我的想法,它實際上並沒有被加載進去。 Danny - 我沒有看到'core_setup'表?但是,它不會出現在'core_resources'中,其餘的_setup條目是用於其他模塊的。 – Tom