magento - 如何为自定义属性类型选择创建自定义源模型?

标签 magento

我尝试搜索此内容,但没有找到任何内容。以编程方式创建具有选择类型的自定义产品属性时,Magento 始终将 eav/entity_attribute_source_table 指定为源模型。

此默认源模型有 2 个问题:

  1. 除了必须手动逐一键入数据列表之外,我无法使用从其他地方以编程方式获取的数据自动填充该字段。

  2. 虽然我已经指定了“default”或“default_value”(我可以在数据库中看到该值存在),但该字段的第一行仍然显示为空。

如何将默认的 source_model 更改为我自己的源模型以选择类型?

谢谢

最佳答案

您要查找的关键是在 SQL 设置中传递 source 值。确保您的 $installerEAV setup object .

您将在设置脚本中执行以下操作:

$installer = $this;

$installer->starSetup();

// Setup customer multiselect attribute
$attr = array(
    'backend'      => 'eav/entity_attribute_backend_array',
    'input'        => 'multiselect',
    'label'        => 'Permissions',
    'note'         => 'Used for group-based frontend permissions.',
    'required'     => false,
    'sort_order'   => '1000',
    'source'       => 'eav/entity_attribute_source_table', // Change it here
    'user_defined' => true
);
$installer->addAttribute('customer', 'permissions', $attr);

// Add options for permissions
$options = array(
    'attribute_id' => $installer->getAttributeId('customer', 'permissions'),
    'value' => array(
        'place_order'    => array('Can Place Orders'),
        'view_catalog'   => array('Can View the Catalog'),
    )
);
$installer->addAttributeOption($options);

$installer->endSetup();

最终,我相信源模型可以是任何提供 toOptionArray() 函数的东西。

关于magento - 如何为自定义属性类型选择创建自定义源模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19411526/

相关文章:

magento - 为 Magento 新闻通讯设置 Google Analytics 目标

php - 尝试在 Magento 中使用 Cyber​​source 模块时出现 SOAP 错误

php - 按特价百分比获取 Magento 产品系列

php - 当我访问一个 php 文件时,在屏幕上获取所有 magento 类别及其 id 的列表

php - Magento 1.9 使用 SQL(MySQL) 创建类别和产品

php - 在 Magento 中找不到 Varien_Data_Form_Element_Int

javascript - 添加到购物车和前端问题中的产品选项字段 - Magento

magento - Magento 中分组产品的所有附加属性

Magento:使用自定义电子邮件模板更改发送状态

magento - 本地 XML 覆盖 Magento 扩展的默认配置