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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀