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

bla*_*der 3 php attributes magento

我只是想知道,有没有什么办法可以将Magento内置的country_of_manufacturer的价值复制到一个新的属性中?

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

PS请不要投票,因为我搜索了很多,但找不到答案.而且不确定我还能做到这一点.:/

ben*_*rks 6

您要做的是配置新属性以使用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();
Run Code Online (Sandbox Code Playgroud)

您还可以在管理员中创建"下拉列表"属性,在eav_attribute表格中找到它,然后编辑其source_model列以获得列出的源模型.要进行适当的设置,请运行此sql语句...

SELECT * FROM eav_attribute WHERE attribute_code = 'country_of_manufacture';`
Run Code Online (Sandbox Code Playgroud)

...或者首先查看country_of_manufacture属性的创建方式.