本文共 2682 字,大约阅读时间需要 8 分钟。
给分类增加一个属性的步骤
1:
<?xml version="1.0"?>
<config> <modules> <Tw_Attribute> <active>true</active> <codePool>community</codePool> </Tw_Attribute> </modules> </config>2
<?xml version="1.0"?>
<config> <modules> <Tw_Attribute> <version>0.0.1</version> </Tw_Attribute> </modules> <global> <resources> <attribute_setup> <setup> <module>Tw_Attribute</module> <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </attribute_setup> <attribute_write> <connection> <use>core_write</use> </connection> </attribute_write> <attribute_read> <connection> <use>core_read</use> </connection> </attribute_read> </resources> </global> </config>3
<?php
/** * aheadWorks Co. * * NOTICE OF LICENSE * * This source file is subject to the EULA * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://ecommerce.aheadworks.com/LICENSE-L.txt * * @category AW * @package AW_Blog * @copyright Copyright (c) 2009-2010 aheadWorks Co. (http://www.aheadworks.com) * @license http://ecommerce.aheadworks.com/LICENSE-L.txt */ class Tw_Attribute_Helper_Data extends Mage_Core_Helper_Abstract { }4
\sql\attribute_setup\mysql4-install-0.0.1.php
<?php
$installer = $this; $installer->startSetup(); $entityTypeId = $installer->getEntityTypeId('catalog_category'); $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId); $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); $installer->addAttribute('catalog_category', 'productimg', array( 'type' => 'varchar', 'label' => 'Product Img', 'input' => 'text', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 'visible' => true, 'required' => false, 'user_defined' => false, 'default' => '' )); $installer->addAttributeToGroup( $entityTypeId, $attributeSetId, $attributeGroupId, 'productimg', '11' //last Magento's attribute position in General tab is 10 ); $attributeId = $installer->getAttributeId($entityTypeId, 'productimg'); $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();OK。
转载地址:http://mpcli.baihongyu.com/