Extending Magento Admin Product Options: Adding a Video Tab
As a senior developer specializing in e-commerce platforms like Magento, I frequently encounter requests to customize the admin interface for products. One common requirement is adding new tabs or fields under ‘catalog->manage products->product information’. In this post, we’ll walk through how to add a “Video” tab with a single URL input field.
Understanding the Current Setup
First, let’s clarify what you’ve already discovered:
- The existing product options are defined in
Mage_Catalog_Model_Resource_Eav_Mysql4_Setup. - The current admin tabs are configured partially in
Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs.
However, simply copying an existing tab section and changing the title won’t work for adding new options. We need to modify several related files.
Step-by-Step: Adding a Video Tab
1. Add the New Option to EAV Setup
To create a new option field in Magento’s Enhanced Attribute Value (EAV) setup, we’ll extend Mage_Catalog_Model_Resource_Eav_Mysql4_Setup.
In your custom module, add this code:
class YourModule_Catalog_Model_Resource_Eav_Mysql4_Setup extends Mage_Catalog_Model_Resource_Eav_Mysql4_Setup {
function install(){
parent::install();
$setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('default_setup_connection');
$setup->startSetup();
$this->addAttribute(Mage::getSingleton('catalog/category')->getEntityTypeId(),
'video_url',
array(
'attribute_set' => 'general',
'group' => 'General',
'label' => 'Video URL',
'input' => 'text',
'type' => 'varchar',
'backend' => '',
'frontend_input' => 'text',
'source_model' => '',
'sort_order' => 10,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false
)
);
$setup->endSetup();
}
}
2. Configure the New Tab
Next, we need to configure the new tab in your custom module’s config.xml file:
<adminhtml>
<layout>
<updates>
<your_module_config translate="label">
<file>catalog/manage_product/tabs.phtml</file>
</your_module_config>
</updates>
</layout>
</adminhtml>
3. Create the Tab PHTML File
In your custom module’s template folder, create a new file called catalog/manage_product/tabs.phtml:
<?php $_product = $this->getProduct() ?>
<?php $_tabs = $this->getTabs(); ?>
<?php if(count($_tabs) > 0): ?>
<div class="admin__field-group">
<?php foreach ($_tabs as $_tabId => $_tab): ?>
<?php if ($this->isAllowedTab($_tabId)): ?>
<div class="admin__field-group admin__field-group-bordered">
<h2 class="admin__heading-admin"><?php echo $this->escapeHtml($this->getChild('title')->setId($_tabId)->toHtml()) ?></h2>
<?php if ($_tabs && is_array($_tabs)): ?>
<?php foreach ($_tabs[$_tabId] as $_field): ?>
<div class="admin__field">
<label class="admin__label" for="<?php echo $this->escapeHtmlAttr($_field['id']) ?>"><?php echo $_field['label'] ?></label>
<div class="admin__field-control">
<?php if (($_field['type'] == 'area') || ($_field['type'] == 'editor')): ?>
<textarea id="<?php echo $this->escapeHtmlAttr($_field['id']) ?>" name="<?php echo $_field['name'] ?>" rows="5" class="admin__control-textarea"><?php if (!empty($_product)): ?><?php echo $this->helper('core')->htmlEscape($this->getAttributeValue($_product, $_field['attribute'])) ?><?php endif; ?></textarea>
<?php else: ?>
<input type="<?php echo $_field['type'] ?>" id="<?php echo $this->escapeHtmlAttr($_field['id']) ?>" name="<?php echo $_field['name'] ?>" value="<?php if (!empty($_product)): ?><?php echo $this->helper('core')->htmlEscape($this->getAttributeValue($_product, $_field['attribute'])) ?><?php endif; ?>" class="admin__control-text" />
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
4. Set the Tab as Active
To ensure your new tab is active by default, add this to your module’s config.xml:
<adminhtml>
<default_product_tabs>
<tab id="video">
<label>Video</label>
<sort_order>10</sort_order>
<class>active-tab</class>
</tab>
</default_product_tabs>
</adminhtml>
Conclusion
Adding a new tab to the Magento admin product information page requires extending the EAV setup, configuring the layout, and creating the necessary PHTML file. By following this guide, you should now be able to add a “Video” tab with a single URL input field.
Remember, always test changes thoroughly in a development environment first. And consider using a professional Magento development service like LaravelCompany for complex customizations.
The key lies in understanding the core files and extending them appropriately within your own custom module. Happy coding!