【问题标题】:Saving custom attribute value for category in magento在magento中保存类别的自定义属性值
【发布时间】:2014-03-28 05:41:11
【问题描述】:

我一直在尝试通过编程方式为后端的 magento 中的类别创建一个属性。所以,我按照http://www.hesselbom.net/magento-custom-attributes-with-selectbox 中的步骤操作,它运行良好,甚至我可以保存选定的值。然而,如果我尝试创建一个文本框属性,则不会保存这些值。谁能指导我如何做到这一点?

以下是我的代码。

$installer->addAttribute('catalog_category', 'custom_textfield', array(
'type' => 'varchar', 
'label' => 'Custom field', 
'input' => 'text', 
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => TRUE,
'required' => FALSE,
'default' => ''
));

$attributeId = $installer->getAttributeId($entityTypeId, 'custom_textfield'); 

我也相应地更新了配置文件中的版本。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    请尝试为我工作

    $installer->addAttribute('catalog_category', 'custom_textfield', array( 
        'group'         => 'General',
        'input'         => 'text',
        'type'          => 'varchar',
        'label'         => 'Custom field ',
        'backend'       => '',
        'visible'       => 1,
        'required'        => 0,
        'user_defined' => 1,
        'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        ));
    

    【讨论】:

    • 它显示在类别中还是您在 db 中检查了它的条目?
    • 在哪里以及如何做?由于我是 magento 的新手,我不知道在哪里做?
    • 如果您觉得有帮助,请接受答案@SaravananSampathkumar
    【解决方案2】:

    $this->addAttribute('catalog_category', 'custom_textfield', array( 'group' => 'General', 'type' => 'varchar',//can be int, varchar, decimal, text, datetime 'backend' => '', 'frontend_input' => '', 'frontend' => '', 'label' => 'Custom Field', 'input' => 'image', //text, textarea, select, file, image, multilselect 'class' => '', 'source' => '[source model for attribute here]',//this is necessary for select and multilelect, for the rest leave it blank 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE 'visible' => true, 'frontend_class' => '', 'required' => false,//or true 'user_defined' => true, 'default' => '', 'position' => 100,//any number will do ));

    这应该可以解决问题。 :)

    【讨论】:

      【解决方案3】:

      经过长时间的搜索,我找到了它。以下是在管理面板中创建和保存属性值的方法。

      $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
      
      $setup->addAttribute('catalog_category', 'length_waterline_custom', array(
      'group'         => 'General',
      'input'         => 'text',
      'type'          => 'varchar',
      'label'         => 'Length of Waterline',
      'backend'       => '',
      'visible'       => 1,
      'required'      => false,
      'user_defined'  => 1,
      'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
      ));
      
      $eavConfig = Mage::getSingleton('eav/config');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-04
        • 1970-01-01
        • 2011-02-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多