最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > Magento > Magento教程 >

magento 后台产品页面自定义tab

时间:2014-07-11 00:35来源:未知 作者:最模板zuimoban 点击:
magento 后台产品页面自定义tab 一:app/code/local/More/Customtabs/etc/config.xml ?xml version=1.0? config modules More_CustomTabs version0.1.0/version /More_CustomTabs /modules global blocks customtabs classMore_Customtabs_Block/c

magento 后台产品页面自定义tab

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();
}
}
 
 

 

 
(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容