php - Magento:如何将制造国属性复制到另一个属性中?

标签 php magento attributes

我只是想知道,有什么方法可以将 Magento 内置的 country_of_manufacturer 的值(基本上是所有国家/地区的列表)复制到新属性中吗?

我知道这是一个有趣的问题,而我们可以只使用内置属性。但我需要将该值用于另一个属性(即 country_region)。那我该怎么做呢?

附言请不要投票,因为我已经搜索了很多但找不到答案。也不确定我还能怎么做。 :/

最佳答案

您要做的是将新属性配置为使用 catalog/product_attribute_source_countryofmanufacture 源模型(参见 Mage_Catalog_Model_Product_Attribute_Source_Countryofmanufacture::getAllOptions() [link]。此模型从目录表中获取选项。

理想情况下,您可以在模块的升级脚本中创建和配置此属性。您需要必要的配置才能为您的模块运行升级脚本,然后您可以将其用作脚本的基础:

$installer = Mage::getResourceModel('catalog/setup','default_setup');
/* @var $installer Mage_Catalog_Model_Resource_Setup */

$installer->startSetup();

$installer->addAttribute(
    Mage_Catalog_Model_Product::ENTITY,
    'your_attr_code',
    array(
        'type'      => 'varchar',
        'input'  => 'select',
        'source'    => 'catalog/product_attribute_source_countryofmanufacture',
        // other settings as desired...
    )
);

$installer->endSetup();

您还可以在管理中创建一个“下拉”属性,在 eav_attribute 表中找到它,然后编辑它的 source_model 列以获得列出的源模型。对于适当的设置,要么运行此 sql 语句...

SELECT * FROM eav_attribute WHERE attribute_code = 'country_of_manufacture';`

...或look at how the country_of_manufacture attribute is created in the first place.

关于php - Magento:如何将制造国属性复制到另一个属性中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949172/

相关文章:

magento - 在 Windows 下本地开发和测试 Magento 扩展的好的工作流程是什么?

php - Magento 购物车总计汇总

javascript - 根据多个值或参数过滤 JSON 对象数组

基于类的 css3 属性选择器

php - 有没有办法通过 PHP 页面修改 node.js 代码?

php - 连接 mysql 表

php - 用 PHP 发送电子邮件的更灵活的方式

php - 多文件上传不保存

php - 在 magento 中应用增值税规则

jQuery 选择器 : Select element with specific class and 'title' attribute