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 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line