dongqiang5541 2016-12-27 09:52
浏览 38
已采纳

在magento admin中的产品编辑中不保存自定义选项卡数据

I have created a custom tab in Magento but while saving the product data is not reflected in database.

I have created below from with input field.

<div class="input-field">
    <label for="custom_field">Custom Field</label>
    <input class="input-text" name="custom_field" id="custom_field" />
</div>

I have wrote below code in Observer.

public function saveProductTabData(Varien_Event_Observer $observer)
{
    if (!self::$_singletonFlag) {
        self::$_singletonFlag = true;   
        $product = $observer->getEvent()->getProduct();
        try {
            $customFieldValue =  $this->_getRequest()->getPost('custom_field');
            $product->setNewAttribute($customFieldValue); 
            #$product->custom_field = $customFieldValue;
            $product->save();
        }
        catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
    }
}

I have followed all steps of this site https://fishpig.co.uk/magento/tutorials/custom-tabs-magento-product-admin/

  • 写回答

1条回答 默认 最新

  • duanji4870 2016-12-27 14:00
    关注
    $setup->addAttribute('catalog_product', 'custom_field', array(
    'entity_model' => 'catalog/product',
    'label' => 'custom',
    'group' => 'General',
    'input' => 'text',
    'type' => 'text',
    'is_html_allowed_on_front' => false,
    'backend' => 'catalog/product_attribute_backend_price',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => false,
    'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
    'required' => false,
    'user_defined' => true,
    'unique' => false,
    'visible_on_front' => false,
    'note' => 'custom'
    ));
    
    use this function in tab.php block
    public function getProduct()
    {
    return Mage::registry('product');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算