自定义选项卡未显示在目录产品信息中
Custom Tabs does not show up in catalog product information
我正在尝试在目录中添加自定义选项卡,我正在关注 FishPig's tutorial。
所以我想达到这样的效果
我已按照教程中的所有说明进行操作,但仍然无法正确完成。
我已经禁用了捕获并启用了调试。我已经检查了日志,但我没有收到任何与此模块相关的错误。
我的代码
app/etc/modules/Fishpig_Customtabs.xml
<config>
<modules>
<Fishpig_Customtabs>
<active>true</active>
<codePool>local</codePool>
</Fishpig_Customtabs>
</modules>
</config>
app/code/local/Fishpig/Customtabs/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Fishpig_CustomTabs>
<version>0.1.0</version>
</Fishpig_CustomTabs>
</modules>
<global>
<blocks>
<customtabs>
<class>Fishpig_Customtabs_Block</class>
</customtabs>
</blocks>
<models>
<customtabs>
<class>Fishpig_Customtabs_Model</class>
</customtabs>
</models>
</global>
<adminhtml>
<layout>
<updates>
<customtabs>
<file>customtabs.xml</file>
</customtabs>
</updates>
</layout>
<events>
<catalog_product_save_after>
<observers>
<fishpig_save_product_data>
<type>singleton</type>
<class>customtabs/observer</class>
<method>saveProductTabData</method>
</fishpig_save_product_data>
</observers>
</catalog_product_save_after>
</events>
</adminhtml>
</config>
app/code/local/Fishpig/Customtabs/Block/Adminhtml/Catalog/Product/Tab.php
<?php
class Fishpig_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');
}
/**
* Retrieve the label used for the tab relating to this block
*
* @return string
*/
public function getTabLabel()
{
return $this->__('My Custom Tab');
}
/**
* Retrieve the title used by this tab
*
* @return string
*/
public function getTabTitle()
{
return $this->__('Click here to view your custom tab content');
}
/**
* Determines whether to display the tab
* 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;
}
/**
* AJAX TAB's
* If you want to use an AJAX tab, uncomment the following functions
* Please note that you will need to setup a controller to recieve
* the tab content request
*
*/
/**
* Retrieve the class name of the tab
* Return 'ajax' here if you want the tab to be loaded via Ajax
*
* return string
*/
# public function getTabClass()
# {
# return 'my-custom-tab';
# }
/**
* Determine whether to generate content on load or via AJAX
* If true, the tab's content won't be loaded until the tab is clicked
* You will need to setup a controller to handle the tab request
*
* @return bool
*/
# public function getSkipGenerateContent()
# {
# return false;
# }
/**
* Retrieve the URL used to load the tab content
* Return the URL here used to load the content by Ajax
* see self::getSkipGenerateContent & self::getTabClass
*
* @return string
*/
# public function getTabUrl()
# {
# return null;
# }
}
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
<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/Fishpig/Customtabs/Model/Observer.php
class Fishpig_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();
}
}
还是不行。我是 magento 的新手,我不知道出了什么问题。有人可以指出我的错误或示例代码吗?
由于以下几点,您的扩展将无法使用
1.禁用 Magento 编译器功能
Magento 编译器可通过系统 > 工具 > 编译找到。编译器收集 Magento 的文件并在 /includes/src 下存储压缩副本。每次文件更改时,都必须通过单击 'Run Compilation Process' 刷新编译器。这既会刷新压缩文件,也会启用编译器。
确保在继续之前禁用了编译器。
2。检查 read/write 权限:
虽然通常没有必要,但在某些情况下您可能需要验证复制文件的权限。在 Unix/Linux 系统上,您应该将文件设置为服务器可读
3。刷新缓存
一旦您禁用了编译器并复制了文件,就可以刷新 Magento 缓存了。转到系统 > 缓存管理并刷新所有缓存,包括 CSS、图像和外部缓存。
3。注销 Magento 并重新登录
现在需要注销 Magento 的管理员,然后重新登录。这是为权限系统启用任何新权限所必需的。
**4 确认扩展合并**
必须确认你的新扩展是否与另一个控制器冲突?
为了在新产品和编辑产品中注册自定义标签
我将代码更改为
app/design/adminhtml/default/default/layout/customtabs.xml
<?xml version="1.0"?>
<layout>
<adminhtml_catalog_product_new>
<reference name="product_tabs">
<action method="addTab">
<name>my_custom_tab</name>
<block>customtabs/adminhtml_catalog_product_tab</block>
</action>
</reference>
</adminhtml_catalog_product_new>
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<action method="addTab">
<name>my_custom_tab</name>
<block>customtabs/adminhtml_catalog_product_edit</block>
</action>
</reference>
</adminhtml_catalog_product_edit>
</layout>
并在 Tab.php
之外添加了另一个名为 Edit.php
的块
我正在尝试在目录中添加自定义选项卡,我正在关注 FishPig's tutorial。
所以我想达到这样的效果
我已按照教程中的所有说明进行操作,但仍然无法正确完成。
我已经禁用了捕获并启用了调试。我已经检查了日志,但我没有收到任何与此模块相关的错误。
我的代码
app/etc/modules/Fishpig_Customtabs.xml
<config>
<modules>
<Fishpig_Customtabs>
<active>true</active>
<codePool>local</codePool>
</Fishpig_Customtabs>
</modules>
</config>
app/code/local/Fishpig/Customtabs/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Fishpig_CustomTabs>
<version>0.1.0</version>
</Fishpig_CustomTabs>
</modules>
<global>
<blocks>
<customtabs>
<class>Fishpig_Customtabs_Block</class>
</customtabs>
</blocks>
<models>
<customtabs>
<class>Fishpig_Customtabs_Model</class>
</customtabs>
</models>
</global>
<adminhtml>
<layout>
<updates>
<customtabs>
<file>customtabs.xml</file>
</customtabs>
</updates>
</layout>
<events>
<catalog_product_save_after>
<observers>
<fishpig_save_product_data>
<type>singleton</type>
<class>customtabs/observer</class>
<method>saveProductTabData</method>
</fishpig_save_product_data>
</observers>
</catalog_product_save_after>
</events>
</adminhtml>
</config>
app/code/local/Fishpig/Customtabs/Block/Adminhtml/Catalog/Product/Tab.php
<?php
class Fishpig_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');
}
/**
* Retrieve the label used for the tab relating to this block
*
* @return string
*/
public function getTabLabel()
{
return $this->__('My Custom Tab');
}
/**
* Retrieve the title used by this tab
*
* @return string
*/
public function getTabTitle()
{
return $this->__('Click here to view your custom tab content');
}
/**
* Determines whether to display the tab
* 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;
}
/**
* AJAX TAB's
* If you want to use an AJAX tab, uncomment the following functions
* Please note that you will need to setup a controller to recieve
* the tab content request
*
*/
/**
* Retrieve the class name of the tab
* Return 'ajax' here if you want the tab to be loaded via Ajax
*
* return string
*/
# public function getTabClass()
# {
# return 'my-custom-tab';
# }
/**
* Determine whether to generate content on load or via AJAX
* If true, the tab's content won't be loaded until the tab is clicked
* You will need to setup a controller to handle the tab request
*
* @return bool
*/
# public function getSkipGenerateContent()
# {
# return false;
# }
/**
* Retrieve the URL used to load the tab content
* Return the URL here used to load the content by Ajax
* see self::getSkipGenerateContent & self::getTabClass
*
* @return string
*/
# public function getTabUrl()
# {
# return null;
# }
}
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
<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/Fishpig/Customtabs/Model/Observer.php
class Fishpig_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();
}
}
还是不行。我是 magento 的新手,我不知道出了什么问题。有人可以指出我的错误或示例代码吗?
由于以下几点,您的扩展将无法使用
1.禁用 Magento 编译器功能
Magento 编译器可通过系统 > 工具 > 编译找到。编译器收集 Magento 的文件并在 /includes/src 下存储压缩副本。每次文件更改时,都必须通过单击 'Run Compilation Process' 刷新编译器。这既会刷新压缩文件,也会启用编译器。
确保在继续之前禁用了编译器。
2。检查 read/write 权限:
虽然通常没有必要,但在某些情况下您可能需要验证复制文件的权限。在 Unix/Linux 系统上,您应该将文件设置为服务器可读
3。刷新缓存
一旦您禁用了编译器并复制了文件,就可以刷新 Magento 缓存了。转到系统 > 缓存管理并刷新所有缓存,包括 CSS、图像和外部缓存。
3。注销 Magento 并重新登录
现在需要注销 Magento 的管理员,然后重新登录。这是为权限系统启用任何新权限所必需的。
**4 确认扩展合并**
必须确认你的新扩展是否与另一个控制器冲突?
为了在新产品和编辑产品中注册自定义标签
我将代码更改为
app/design/adminhtml/default/default/layout/customtabs.xml
<?xml version="1.0"?>
<layout>
<adminhtml_catalog_product_new>
<reference name="product_tabs">
<action method="addTab">
<name>my_custom_tab</name>
<block>customtabs/adminhtml_catalog_product_tab</block>
</action>
</reference>
</adminhtml_catalog_product_new>
<adminhtml_catalog_product_edit>
<reference name="product_tabs">
<action method="addTab">
<name>my_custom_tab</name>
<block>customtabs/adminhtml_catalog_product_edit</block>
</action>
</reference>
</adminhtml_catalog_product_edit>
</layout>
并在 Tab.php
Edit.php
的块