我正在努力解决一个问题,希望您能提供帮助。
我需要更改我的产品页面上的默认产品选项卡,但我无法在后端更改它,只能设置不同的属性。
我已将其缩小到一个 catalog.xml 文件,但我不知道控制选项卡的确切代码在哪里。
我尝试稍微修改一下代码,但没有任何效果。我的 Magento 安装也很慢,这让我很生气......
有任何想法吗?
提前致谢...
我建议您覆盖本地模块中的核心文件,而不是直接更改核心文件。这是一个示例如何覆盖Mage_Adminhtml_Catalog_Product_Edit_Tabs.php
创建一个模块 例如MyNameSpace_ModuleName inside app/code/local/
要注册一个模块,请创建app/etc/modules/MyNameSpace_ModuleName.xml
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ModuleName>
<codePool>local</codePool>
<active>true</active>
</MyNameSpace_ModuleName>
</modules>
</config>
MyNameSpace/ModuleName/etc/config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<MyNameSpace_ModuleName>
<version>0.1.0</version>
</MyNameSpace_ModuleName>
</modules>
<global>
<blocks>
<adminhtml>
<rewrite>
<cataolg_product_edit_tabs>MyNameSpace_ModuleName_Block_Adminhtml_catalog_product_edit_tabs</cataolg_product_edit_tabs>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
MyNameSpace/ModuleName/Block/Adminhtml/catalog/product/edit/tabs.php
class MyNameSpace_ModuleName_Block_Adminhtml_Catalog_Product_Edit_Tabs extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs
{
protected $_attributeTabBlock = 'adminhtml/catalog_product_edit_tab_attributes';
public function __construct()
{
parent::__construct();
$this->setId('product_info_tabs');
$this->setDestElementId('product_edit_form');
$this->setTitle(Mage::helper('catalog')->__('Product Information'));
}
protected function _prepareLayout()
{
$product = $this->getProduct();
if (!($setId = $product->getAttributeSetId())) {
$setId = $this->getRequest()->getParam('set', null);
}
if ($setId) {
$groupCollection = Mage::getResourceModel('eav/entity_attribute_group_collection')
->setAttributeSetFilter($setId)
->setSortOrder()
->load();
foreach ($groupCollection as $group) {
$attributes = $product->getAttributes($group->getId(), true);
// do not add groups without attributes
foreach ($attributes as $key => $attribute) {
if( !$attribute->getIsVisible() ) {
unset($attributes[$key]);
}
}
if (count($attributes)==0) {
continue;
}
$this->addTab('group_'.$group->getId(), array(
'label' => Mage::helper('catalog')->__($group->getAttributeGroupName()),
'content' => $this->_translateHtml($this->getLayout()->createBlock($this->getAttributeTabBlock(),
'adminhtml.catalog.product.edit.tab.attributes')->setGroup($group)
->setGroupAttributes($attributes)
->toHtml()),
));
}
if (Mage::helper('core')->isModuleEnabled('Mage_CatalogInventory')) {
$this->addTab('inventory', array(
'label' => Mage::helper('catalog')->__('Inventory'),
'content' => $this->_translateHtml($this->getLayout()
->createBlock('adminhtml/catalog_product_edit_tab_inventory')->toHtml()),
));
}
/**
* Don't display website tab for single mode
*/
if (!Mage::app()->isSingleStoreMode()) {
$this->addTab('websites', array(
'label' => Mage::helper('catalog')->__('Websites'),
'content' => $this->_translateHtml($this->getLayout()
->createBlock('adminhtml/catalog_product_edit_tab_websites')->toHtml()),
));
}
$this->addTab('categories', array(
'label' => Mage::helper('catalog')->__('Categories'),
'url' => $this->getUrl('*/*/categories', array('_current' => true)),
'class' => 'ajax',
));
$this->addTab('related', array(
'label' => Mage::helper('catalog')->__('Related Products'),
'url' => $this->getUrl('*/*/related', array('_current' => true)),
'class' => 'ajax',
));
$this->addTab('upsell', array(
'label' => Mage::helper('catalog')->__('Up-sells'),
'url' => $this->getUrl('*/*/upsell', array('_current' => true)),
'class' => 'ajax',
));
$this->addTab('crosssell', array(
'label' => Mage::helper('catalog')->__('Cross-sells'),
'url' => $this->getUrl('*/*/crosssell', array('_current' => true)),
'class' => 'ajax',
));
$storeId = 0;
if ($this->getRequest()->getParam('store')) {
$storeId = Mage::app()->getStore($this->getRequest()->getParam('store'))->getId();
}
$alertPriceAllow = Mage::getStoreConfig('catalog/productalert/allow_price');
$alertStockAllow = Mage::getStoreConfig('catalog/productalert/allow_stock');
if (($alertPriceAllow || $alertStockAllow) && !$product->isGrouped()) {
$this->addTab('productalert', array(
'label' => Mage::helper('catalog')->__('Product Alerts'),
'content' => $this->_translateHtml($this->getLayout()
->createBlock('adminhtml/catalog_product_edit_tab_alerts', 'admin.alerts.products')->toHtml())
));
}
if( $this->getRequest()->getParam('id', false) ) {
if (Mage::helper('catalog')->isModuleEnabled('Mage_Review')) {
if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/reviews_ratings')){
$this->addTab('reviews', array(
'label' => Mage::helper('catalog')->__('Product Reviews'),
'url' => $this->getUrl('*/*/reviews', array('_current' => true)),
'class' => 'ajax',
));
}
}
if (Mage::helper('catalog')->isModuleEnabled('Mage_Tag')) {
if (Mage::getSingleton('admin/session')->isAllowed('admin/catalog/tag')){
$this->addTab('tags', array(
'label' => Mage::helper('catalog')->__('Product Tags'),
'url' => $this->getUrl('*/*/tagGrid', array('_current' => true)),
'class' => 'ajax',
));
$this->addTab('customers_tags', array(
'label' => Mage::helper('catalog')->__('Customers Tagged Product'),
'url' => $this->getUrl('*/*/tagCustomerGrid', array('_current' => true)),
'class' => 'ajax',
));
}
}
}
/**
* Do not change this tab id
* @see Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs_Configurable
* @see Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tabs
*/
if (!$product->isGrouped()) {
$this->addTab('customer_options', array(
'label' => Mage::helper('catalog')->__('Custom Options'),
'url' => $this->getUrl('*/*/options', array('_current' => true)),
'class' => 'ajax',
));
}
}
else {
$this->addTab('set', array(
'label' => Mage::helper('catalog')->__('Settings'),
'content' => $this->_translateHtml($this->getLayout()
->createBlock('adminhtml/catalog_product_edit_tab_settings')->toHtml()),
'active' => true
));
}
return parent::_prepareLayout();
}
}
您可以在 _preparelayout() 函数中添加新选项卡。以同样的方式,您还可以覆盖其他文件并可以更改您想要更改的任何内容。
为了正确反映更改,请确保您已清理缓存。
您可以在此块文件 app\code\core\Mage\Adminhtml\Block\Catalog\Product\Edit\Tabs.php 中找到选项卡
如果您正在查看此选项卡,您可以找到选项卡的特定操作
例如相关产品,它有这种 url $this->getUrl('*/*/related', array('_current' => true)),
,这个 url 依次调用这个 adminhtml_catalog_product_related 动作,这个动作在 catalog.xml 中指定。
<adminhtml_catalog_product_related>
<block type="core/text_list" name="root" output="toHtml">
<block type="adminhtml/catalog_product_edit_tab_related" name="catalog.product.edit.tab.related"/>
<block type="adminhtml/widget_grid_serializer" name="related_grid_serializer">
<reference name="related_grid_serializer">
<action method="initSerializerBlock">
<grid_block_name>catalog.product.edit.tab.related</grid_block_name>
<data_callback>getSelectedRelatedProducts</data_callback>
<hidden_input_name>links[related]</hidden_input_name>
<reload_param_name>products_related</reload_param_name>
</action>
<action method="addColumnInputName">
<input_name>position</input_name>
</action>
</reference>
</block>
</block>
</adminhtml_catalog_product_related>
这样您就可以轻松找到要更改的内容。