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/
$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');
}