Я работаю над добавлением атрибута affiliate_link (текстовое поле) к настраиваемому типу продукта. Вот инсталлятор сценарий, но, к сожалению, это не работает:Как программно добавлять атрибуты к типу продукта
<?php /** @var $installer Mage_Catalog_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
$installer->addAttribute(
Mage_Catalog_Model_Product::ENTITY,
'affiliate_link',
array(
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Affiliate Link',
'input' => 'text',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => true,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => 'gift',
'is_configurable' => false,
'used_in_product_listing' => false
)
);
$attributeId = $installer->getAttributeId(
'catalog_product',
'affiliate_link'
);
$defaultSetId = $installer->getAttributeSetId('catalog_product', 'default');
$installer->addAttributeGroup(
'catalog_product',
$defaultSetId,
'Affiliate Information'
);
//find out the id of the new group
$groupId = $installer->getAttributeGroup(
'catalog_product',
$defaultSetId,
'Affiliate Information',
'attribute_group_id'
);
//assign the attribute to the group and set
if ($attributeId > 0) {
$installer->addAttributeToSet(
'catalog_product',
$defaultSetId,
$groupId,
$attributeId
);
}
$installer->endSetup();?>
Код для config.xml:
<config>
<modules>
<Cueblocks_Newtype>
<version>0.1.0</version>
</Cueblocks_Newtype>
</modules>
<global>
<catalog>
<product>
<type>
<gift translate="label" module="cueblocks_newtype">
<label>Gift Product</label>
<model>cueblocks_newtype/product_type</model>
<is_qty>0</is_qty>
<composite>0</composite>
<can_use_qty_decimals>0</can_use_qty_decimals>
</gift>
</type>
</product>
</catalog>
<!-- code omitted for brevity -->
<blocks>
<cueblocks_newtype>
<class>Cueblocks_Newtype_Block</class>
</cueblocks_newtype>
</blocks>
<helpers>
<cueblocks_newtype>
<class>Cueblocks_Newtype_Helper</class>
</cueblocks_newtype>
</helpers>
<models>
<cueblocks_newtype>
<class>Cueblocks_Newtype_Model</class>
</cueblocks_newtype>
</models>
<!-- code omitted for brevity -->
<resources>
<cueblocks_newtype_setup>
<setup>
<module>Cueblocks_Newtype</module>
<class>Mage_Catalog_Model_Resource_Setup</class>
</setup>
</cueblocks_newtype_setup>
<newtype_write>
<connection>
<use>core_write</use>
</connection>
</newtype_write>
<newtype_read>
<connection>
<use>core_read</use>
</connection>
</newtype_read>
</resources>
</global>
</config>
Любая помощь будет принята с благодарностью.
Hey Asif спасибо за то, что посмотрели на это ... Лемме попробуй и вернемся к тебе. –
Не работает .... Я использую magento 1.9 version.On, в какой версии вы это пробовали? –
Интересно, что это даже не добавление новой группы атрибутов «Affiliate», которую мы пытались добавить через скрипт установщика. Возможно, это проблема с версией magento 1.9 .... Любые идеи ??? –