duanbin4847 2016-04-06 08:44
浏览 51
已采纳

Magento如何在管理面板中保存自定义字段

In Manage Products -> Edit a product -> Images I've added 2 new columns (which are located in the catalog_product_entity_media_gallery_value table).

Those 2 columns are filled every time there is a media import and each field only show the value (you can't enter a new value). It's also used on the frontend. I've modified in my own theme the correct admin template file and created a new product.js to display the 2 new fields. So far everything is working as intended.

But whenever a user tries to modify something in the Images section, let say the label of an image or the position, my 2 custom fields are not saved and Magento give them the NULL value.

Because the 2 new columns are not input fields, I thought Magento would not update it, but looks like it does. I've been trying to find where the label and position are saved for the Images section so that I can add my custom values but I can't find it. Could somebody point me in the right direction?

Or would it be better to listen to the catalog_product_save_after event and create an observer to save my custom values?

Any help would be great, thank you.

  • 写回答

1条回答 默认 最新

  • doushou6480 2016-04-08 12:58
    关注

    Finally found it, I missed it during my previous searches. I'll answer it myself just in case it can help someone else. Code is in the Mage_Catalog_Model_Product_Attribute_Backend_Media class, inside the afterSave function. All you have to do is to rewrite it.

    Config.xml should contain the following :

    <models>
        <catalog_resource>
            <rewrite>
                <product_attribute_backend_media>
                    Namespace_Module_Model_Resource_Product_Attribute_Backend_Media
                </product_attribute_backend_media>
            </rewrite>
        </catalog_resource>
    </models>
    

    And class should be : Namespace_Module_Model_Product_Attribute_Backend_Media extends Mage_Catalog_Model_Product_Attribute_Backend_Media

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真