Php Magento模块的设置问题-向类别添加属性
今天下午,我一直在尝试在Magento中创建一个模块,它只是向类别添加了更多属性 我将浏览到目前为止我创建的脚本 app/etc/Modules/Comp_Categoryattributes.xmlPhp Magento模块的设置问题-向类别添加属性,php,magento,module,Php,Magento,Module,今天下午,我一直在尝试在Magento中创建一个模块,它只是向类别添加了更多属性 我将浏览到目前为止我创建的脚本 app/etc/Modules/Comp_Categoryattributes.xml <?xml version="1.0"?> <config> <modules> <Comp_Categoryattributes> <active>true</active>
<?xml version="1.0"?>
<config>
<modules>
<Comp_Categoryattributes>
<active>true</active>
<codePool>local</codePool>
</Comp_Categoryattributes>
</modules>
</config>
app/code/local/Comp/Categoryattributes/sql/Categoryattributes\u setup/mysql4-install-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();
?>
浏览一下,我注意到您的config/xml文件包含以下内容:
<ncategoryattributes_setup_write>
尝试删除“n”。只需浏览一下,我注意到您的config/xml文件具有以下内容:
<ncategoryattributes_setup_write>
尝试删除“n”。在安装脚本顶部抛出一个骰子(),刷新缓存,并点击站点的任何页面(只需启动Mage::run()。看看你是否死了。。。。不要忘记删除模块的core_设置表中的条目,否则不会执行新的安装。Ben-我已经在安装脚本中添加了一个die(),但是这些站点正常工作。我想这几乎证实了我的想法,它实际上并没有被加载。Danny-我没有看到core\u设置
表?但是,它不会出现在核心资源中,其他的安装条目都是针对其他模块的。在安装脚本的顶部抛出一个die(),刷新缓存,然后点击站点的任何页面(只需要Mage::run()即可启动)。看看你是否死了。。。。不要忘记删除模块的core_设置表中的条目,否则不会执行新的安装。Ben-我已经在安装脚本中添加了一个die(),但是这些站点正常工作。我想这几乎证实了我的想法,它实际上并没有被加载。Danny-我没有看到core\u设置
表?但是,它没有出现在核心资源中,其他的设置条目都是为其他模块设置的。是的,注意到了,总是有一些小事情让你迷惑不解,不是吗!是的,斑点,总是一些小事情让你绊倒,不是吗!