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');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 adb连接不到手机是怎么回事?
  • ¥15 vs2022无法联网
  • ¥15 TCP的客户端和服务器的互联
  • ¥15 VB.NET操作免驱摄像头
  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目