0

I created the custom tab in Catalog Product. It is my layout/labels.xml

<adminhtml_catalog_product_edit>
    <reference name="product_tabs">
         <action method="addTab"><name>labels</name><block>productlabels/adminhtml_products_edit_tabs_labels</block></action>
    </reference> 
</adminhtml_catalog_product_edit>

And Tab.

class Vendor_ModuleName_Block_Adminhtml_Products_Edit_Tabs_Labels 
extends Mage_Adminhtml_Block_Widget_Form implements 
Mage_Adminhtml_Block_Widget_Tab_Interface
{
protected function _prepareForm()
{
    //$model = Mage::registry('product_labels');
    $model = Mage::getModel('productlabels/block')->getCollection()->addFieldToFilter('product_page_image', ["notnull" => 'product_page_image'])->getData();
    $form = new Varien_Data_Form();
    $fieldset = $form->addFieldSet('label_form', array(
        'legent' => Mage::helper('productlabels')->__('Labels'),));

    foreach ($model as $value) {
        $fieldset->addField('label_' . $value['id_label'], 'checkbox', array(
            'label' => $value['title'],
            'name' => $value['id_label'],
            'value' => 1,
            'after_element_html' => '<p style="margin-top: 5px"><img style="max-width: 200px" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . $value['product_page_image'] . '"></p>',
        ));
    }

    $form->setValues($model);
    $this->setForm($form);
    return parent::_prepareForm();
}

public function canShowTab()
{
    return true;
}

public function getTabLabel()
{
    return $this->__('Product Labels');
}

public function getTabTitle()
{
    return $this->__('Product Labels');
}

public function isHidden()
{
    return false;
}

How can i save data from this tab in DB?. I try create in Namespace/Module/controllers/Catalog/ProductController.php saveAction(), but it remove native action.

  • you need to override the core controller Mage/Adminhtml/controllers/Catalog/ProductController.php – Piyush Mar 19 '18 at 8:59
  • i can`t extend this class – Petro Chaikivskyi Mar 19 '18 at 9:00
  • you have to or you can use observer for event product save – Piyush Mar 19 '18 at 9:30
0

Instead of overriding controller action, you should use events and observer feature of Magento.

Please try to observe catalog_product_save_before event and write an observer function to save the data.

0

How can i save data from this tab in DB?. I try create in Namespace/Module/controllers/Catalog/ProductController.php saveAction(), but it remove native action.

If this happens you will have to override properly. Correct class name for override would be Mage_Adminhtml_Catalog_ProductController. To extend original method code you should call saveAction from parent class.

public function saveAction()
{
     // your custom code goes here

     parent::saveAction();
}

Beware! Overriding core classes is considered a bad technique and will potentially increase further code maintenance. Use Event Observers whenever it is possible.

  • Warning: include(Mage\Adminhtml\Catalog\ProductController.php): failed to open stream: No such file or directory in D:\xampp\htdocs\lib\Varien\Autoload.php on line 94 – Petro Chaikivskyi Mar 19 '18 at 10:01
  • magento can not autoload the class of the rewritten controller. require_once "Mage/Adminhtml/Catalog/controllers/ProductController.php"; is needed on top of rewritten class – Vladimir Samsonov Mar 19 '18 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.