| magento 后台产品页面自定义tab 
	 
	一:app/code/local/More/Customtabs/etc/config.xml 
	<?xml version="1.0"?> 
	<config> 
	<modules> 
	<More_CustomTabs> 
	<version>0.1.0</version> 
	</More_CustomTabs> 
	</modules> 
	<global> 
	<blocks> 
	<customtabs> 
	<class>More_Customtabs_Block</class> 
	</customtabs> 
	</blocks> 
	<models> 
	<customtabs> 
	<class>More_Customtabs_Model</class> 
	</customtabs> 
	</models> 
	</global> 
	<adminhtml> 
	<layout> 
	<updates> 
	<customtabs> 
	<file>customtabs.xml</file> 
	</customtabs> 
	</updates> 
	</layout> 
	<events> 
	<catalog_product_save_after> 
	<observers> 
	<More_save_product_data> 
	<type>singleton</type> 
	<class>customtabs/observer</class> 
	<method>saveProductTabData</method> 
	</More_save_product_data> 
	</observers> 
	</catalog_product_save_after> 
	</events> 
	</adminhtml> 
	</config> 
	二:app/etc/modules/More_Customtabs.xml 
	<?xml version="1.0"?> 
	<config> 
	<modules> 
	<More_Customtabs> 
	<active>true</active> 
	<codePool>local</codePool> 
	</More_Customtabs> 
	</modules> 
	</config> 
	三:app/code/local/More/Customtabs/Block/Adminhtml/Catalog/Product/Tab.php 
	<?php 
	class More_Customtabs_Block_Adminhtml_Catalog_Product_Tab 
	extends Mage_Adminhtml_Block_Template 
	implements Mage_Adminhtml_Block_Widget_Tab_Interface { 
	/** 
	* Set the template for the block 
	* 
	*/ 
	public function _construct() 
	{ 
	parent::_construct(); 
	$this->setTemplate('customtabs/catalog/product/tab.phtml'); 
	} 
	/** 
	* 获取用于有关此块标签的标签 
	* 
	* @return string 
	*/ 
	public function getTabLabel() 
	{ 
	return $this->__('My Custom Tab'); 
	} 
	/** 
	* 通过此选项卡用于检索标题 
	* 
	* @return string 
	*/ 
	public function getTabTitle() 
	{ 
	return $this->__('Click here to view your custom tab content'); 
	} 
	/** 
	* 决定是否显示标签 
	* Add logic here to decide whether you want the tab to display 
	* 
	* @return bool 
	*/ 
	public function canShowTab() 
	{ 
	return true; 
	} 
	/** 
	* Stops the tab being hidden 
	* 
	* @return bool 
	*/ 
	public function isHidden() 
	{ 
	return false; 
	} 
	/** 
	* Short description. 
	* @param type $varname description 
	* @return type description 
	* @access public or private 
	* @static makes the class property accessible without needing an instantiation of the class 
	*/ 
	public function getColorId() 
	{ 
	//$collection = Mage::getModel('customtabs/customtabs')->getProduct(); 
	//$pid=$collection->getProductId(); 
	$pid = Mage::registry('current_product')->getId(); 
	//$collection->getSelect()->where(array('id',$id)); 
	$collection= Mage::getModel('customtabs/customtabs')->getCollection(); 
	$collection->addFieldToFilter('pid',array('in'=>$pid)); 
	$select=$collection->getSelect(); 
	return $select; 
	} // end func 
	} 
	四:app/design/adminhtml/default/default/layout/customtabs.xml 
	<?xml version="1.0"?> 
	<layout> 
	<adminhtml_catalog_product_edit> 
	<reference name="product_tabs"> 
	<action method="addTab"> 
	<name>my_custom_tab</name> 
	<block>customtabs/adminhtml_catalog_product_tab</block> 
	</action> 
	</reference> 
	</adminhtml_catalog_product_edit> 
	</layout> 
	五:app/design/adminhtml/default/default/template/customtabs/catalog/product/tab.phtml 
	<?php 
	/** 
	* Custom tab template 
	*/ 
	?> 
	<div class="input-field"> 
	<label for="custom_field">Custom Field</label> 
	<input type="text" class="input-text" name="custom_field" id="custom_field" /> 
	</div> 
	六:app/code/local/More/Customtabs/Model/Observer.php 
	<?php 
	class More_Customtabs_Model_Observer 
	{ 
	/** 
	* Flag to stop observer executing more than once 
	* 
	* @var static bool 
	*/ 
	static protected $_singletonFlag = false; 
	/** 
	* This method will run when the product is saved from the Magento Admin 
	* Use this function to update the product model, process the 
	* data or anything you like 
	* 
	* @param Varien_Event_Observer $observer 
	*/ 
	public function saveProductTabData(Varien_Event_Observer $observer) 
	{ 
	if (!self::$_singletonFlag) { 
	self::$_singletonFlag = true; 
	$product = $observer->getEvent()->getProduct(); 
	try { 
	/** 
	* Perform any actions you want here 
	* 
	*/ 
	$customFieldValue =  $this->_getRequest()->getPost('custom_field'); 
	/** 
	* Uncomment the line below to save the product 
	* 
	*/ 
	$product->save(); 
	} 
	catch (Exception $e) { 
	Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); 
	} 
	} 
	} 
	/** 
	* Retrieve the product model 
	* 
	* @return Mage_Catalog_Model_Product $product 
	*/ 
	public function getProduct() 
	{ 
	return Mage::registry('product'); 
	} 
	/** 
	* Shortcut to getRequest 
	* 
	*/ 
	protected function _getRequest() 
	{ 
	return Mage::app()->getRequest(); 
	} 
	} 
 | 




 ecshop仿苏宁易购带团购2
							人气:1325
							ecshop仿苏宁易购带团购2
							人气:1325
						 ecshop精仿麦包包2011白金版
							人气:1109
							ecshop精仿麦包包2011白金版
							人气:1109
						 黑色衣服鞋子外贸商城|
							人气:755
							黑色衣服鞋子外贸商城|
							人气:755
						 ecshop也买茶模板|ecshop茶叶
							人气:979
							ecshop也买茶模板|ecshop茶叶
							人气:979
						 shopex仿爱情鸟模板
							人气:425
							shopex仿爱情鸟模板
							人气:425
						 ecshop网易保健品绿色商城
							人气:417
							ecshop网易保健品绿色商城
							人气:417