dig*_*aki 1 attributes magento
我正在使用以下链接中列出的代码:
一切正常,直到这一点:
// Just add a default group.
else
{
$this->logInfo("Creating default group [{$this->groupName}] for set.");
$modelGroup = Mage::getModel('eav/entity_attribute_group');
$modelGroup->setAttributeGroupName($this->groupName);
$modelGroup->setAttributeSetId($id);
// This is optional, and just a sorting index in the case of
// multiple groups.
// $modelGroup->setSortOrder(1);
$model->setGroups(array($modelGroup));
}
Run Code Online (Sandbox Code Playgroud)
我不确定在哪里需要设置对象引用 - 我试图将其作为一个可以自动化的单独文件 - 我正在运行此文件
require_once 'app/Mage.php';
Mage::app();
Run Code Online (Sandbox Code Playgroud)
任何帮助都将非常感谢
Ver*_*ton 12
您需要在模块config.xml中有一个块,看起来像这样
<resources>
<namespace_module_setup><!-- becomes folder under sql dir -->
<setup>
<module>Namespace_Module</module>
<class>Mage_Eav_Model_Entity_Setup</class>
</setup>
</namespace_module_setup>
</resources>
Run Code Online (Sandbox Code Playgroud)
这将允许您将安装程序代码放在XML中的目录中.您需要确保安装程序文件中列出的版本与<version>1.2.0</version>您的模块匹配,否则Magento将无法运行您的安装程序.要添加属性Set,您可以使用以下数据,我从未使用它,但entityTypeId分别定义它是客户,运输,类别,产品实体,每个分别为1,2,3,4.
/**
* Add Attribute Set
*
* @param mixed $entityTypeId
* @param string $name
* @param int $sortOrder
* @return Mage_Eav_Model_Entity_Setup
*/
public function addAttributeSet($entityTypeId, $name, $sortOrder = null)
{
$data = array(
'entity_type_id' => $this->getEntityTypeId($entityTypeId),
'attribute_set_name' => $name,
'sort_order' => $this->getAttributeSetSortOrder($entityTypeId, $sortOrder),
);
$setId = $this->getAttributeSet($entityTypeId, $name, 'attribute_set_id');
if ($setId) {
$this->updateAttributeSet($entityTypeId, $setId, $data);
} else {
$this->_conn->insert($this->getTable('eav/attribute_set'), $data);
$this->addAttributeGroup($entityTypeId, $name, $this->_generalGroupName);
}
return $this;
}
Run Code Online (Sandbox Code Playgroud)
这是用于向集合添加属性的代码,只需更改属性集数据即可
//app/code/local/Namespace/Module/sql/Namespace_Module_setup/mysql4-install-1.0.0.php
$installer = $this;
/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer->startSetup();
$data= array (
'attribute_set' => 'Default',
'group' => 'General',
'label' => 'Some Label',
'visible' => true,
'type' => 'varchar', // multiselect uses comma-sep storage
'input' => 'text',
'system' => true,
'required' => false,
'user_defined' => 1, //defaults to false; if true, define a group
);
$installer->addAttribute('catalog_product','attriute_code',$data)
$installer->endSetup();
Run Code Online (Sandbox Code Playgroud)
以上是模块的属性安装的工作示例.
有一个更容易的单线程.只需为您的安装脚本扩展Mage_Eav_Model_Entity_Setup,并在安装程序中使用以下内容:
$installer = $this;
/* @var $installer Mage_Eav_Model_Entity_Setup */
$installer->startSetup();
$installer->addAttributeSet(Mage_Catalog_Model_Product::ENTITY, 'New Attribute Set Name');
$installer->endSetup();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16242 次 |
| 最近记录: |