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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料