2011-11-02 135 views
1

今天下午,我一直试图在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表出现在所有?有什么明显的我失踪了吗?

干杯家伙,

汤姆

+0

在你的安装脚本顶部扔一个die(),刷新缓存,然后点击你网站的任何页面(只需要Mage :: run()来触发)。看看你是否死了。 – benmarks

+1

...并且不要忘记为你的模块删除core_setup表中的条目,否则不会执行新的安装。 – tecmec

+0

欢迎回复chaps。 Ben - 我在我的安装脚本中添加了一个die(),但这些站点正常工作。我想这几乎证实了我的想法,它实际上并没有被加载进去。 Danny - 我没有看到'core_setup'表?但是,它不会出现在'core_resources'中,其余的_setup条目是用于其他模块的。 – Tom

回答

1

只是一掠而过它,我注意到,你的config/xml文件有以下几点:

<ncategoryattributes_setup_write> 

尝试删除 'N'。

+0

是的,发现,它总是那些让你过去的小事情不是它! – Tom