自定义选项卡数据不保存在magento中的产品编辑admin
问题描述:
我已经在Magento中创建了自定义选项卡,但保存产品数据时未反映在数据库中。自定义选项卡数据不保存在magento中的产品编辑admin
我在下面用输入栏创建了。
<div class="input-field">
<label for="custom_field">Custom Field</label>
<input class="input-text" name="custom_field" id="custom_field" />
</div>
我在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());
}
}
}
我按照这个网站的所有步骤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');
}
+0
谢谢你,它正在工作 –
试试这个$产品 - > setCustomField( “值”); – faizanbeg
我试过这段代码'$ product-> setCustomField($ customFieldValue);'但它不起作用。 –
请将商店ID设置为管理商店ID。这是 Mage :: app() - > getStore() - > setId(0); 还有产品对象的自定义字段值,如 $ product-> setCustomField($ customFieldValue) – khasru