1

I know that it is not safe to modify the core, so i want to extend a class. My need is to add a new button. In the image below you can see where:

enter image description here

So, I created a module for that. I think the idea is that my module is triggered when I clicked on a attribute set. I have absoluty no idea how to do that. I tried smth like this: config.xml content:

   <?xml version="1.0"?>
<config>
    <modules>
        <Netgr_Gradd>
            <version>1.0.0</version>
        </Netgr_Gradd>
    </modules>
    <global>
        <blocks>
            <netgr_gradd>
                <class>Netgr_Gradd_Block</class>
            </netgr_gradd>
            <adminhtml>
                <rewrite>
                    <catalog_product_attribute_set_main>Netgr_Gradd_Block_Adminhtml_Addgroup</catalog_product_attribute_set_main>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>

</config>

After in controllers/AddgroupController.php content is :

<?php

class Netgr_Gradd_Adminhtml_AddgroupController extends Mage_Adminhtml_Controller_Action
{

    public function indexAction(){
        echo   11111;
    }
}

Here I tried to extend from the core class, the function that adds a new button, but with no result. Can anyone help me with this ?

The content of adminthml.xml is:

  <?xml version="1.0"?>
<config>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <netgr_gradd before ="Mage_Adminhtml">Netgr_Gradd_Adminhtml</netgr_gradd>
                    </modules>
                </args>
            </adminhtml>
        </routers>

    </admin>

</config>

and this is the content from Block/Adminhtml/Addgroup.php:

class Netgr_Gradd_Block_Adminhtml_Addgroup extends Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main
{

     public function  __construct() {

        parent::_prepareLayout();

        $this->_addButton('button_id', array(
            'label'     => Mage::helper('xxx')->__('Some action'),
            'onclick'   => 'jsfunction(this.id)',
            'class'     => 'go'
        ), 0, 100, 'header', 'header');
    }
}
  • so ? any idea or any suggestions ? – Attila Naghi Jul 31 '14 at 7:01
  • What is the problem? Error? What do you expect and what happens? Is your controller hit? – Fabian Blechschmidt Jul 31 '14 at 7:21
  • check my post again, i updated it :) – Attila Naghi Jul 31 '14 at 7:33
6

So it appears you are trying to rewrite a controller when you could simply rewrite the block Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main.

<config>
    <global>
        <blocks>
            <netgroup_attributegrouping>
                <class>Netgroup_Attributegrouping_Block</class>
            </netgroup_attributegrouping>
            <adminhtml>
                <rewrite>
                    <catalog_product_attribute_set_main>Netgroup_Attributegrouping_Block_Adminhtml_Addgroup</catalog_product_attribute_set_main>
                </rewrite>
            </adminhtml>
        </blocks>
    <global>
</config>

Then change your class to be class Netgroup_Attributegrouping_Block_Adminhtml_Addgroup and put it under the Block/Adminhtml folder of your extension with the filename Addgroup.php

Then add your _prepareLayout function changes and call parent::_prepareLayout()

Update for button

Now that I see you are wanting to add a button you can see in the template app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml all the calls to the blocks add button functions like getResetButtonHtml. So the steps to add a new button would be as follows:

  1. Rewrite this block to use your own template. Your template can simply be a copy of the default one,
  2. Add a new button call <?php echo $this->getYourButtonHtml() ?> into your template with the others,
  3. In your new block add the function getYourButtonHtml which will simply contain return $this->getChildHtml('your_button');
  4. Update your block's prepareLayout function to add the button,

So in the end your class should look as follows:

class Netgr_Gradd_Block_Adminhtml_Addgroup extends Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main
{

protected function _construct() {
    //This should just be a copy of catalog/product/attribute/set/main.phtml so you can edit it
    $this->setTemplate('netgroup/catalog/product/attribute/set/main.phtml');
}

public function _prepareLayout() {
    $this->setChild('your_button',
        $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
            'label'     => Mage::helper('catalog')->__('Your Button Label'),
            'onclick'   => 'your button on click',
            'class'     => 'your-button-class'
    )));
    return parent::_prepareLayout();
}

public function getYourButtonHtml() {
    return $this->getChildHtml('your_button');
}
}

Then for the template simple make a copy of app/design/adminhtml/default/default/template/catalog/product/attribute/set/main.phtml to for example app/design/adminhtml/default/default/template/netgroup/catalog/product/attribute/set/main.phtml then make a small change and add a new button html section:

<td class="form-buttons">
    <?php echo $this->getBackButtonHtml() ?>
    <?php echo $this->getResetButtonHtml() ?>
    <?php echo $this->getDeleteButtonHtml() ?>
    <?php echo $this->getSaveButtonHtml() ?>
    <?php echo $this->getYourButtonHtml() ?>
</td>
  • the xml code , i have to put into config.xml or adminhtml.xml ? – Attila Naghi Jul 31 '14 at 7:27
  • @Chester sorry into config.xml – David Manners Jul 31 '14 at 7:27
  • please check my post again, see the modification over the code – Attila Naghi Jul 31 '14 at 7:33
  • now I'm getting this erros: Fatal error: Call to a member function createBlock() on a non-object in C:\xampp\htdocs\dachim\app\code\core\Mage\Adminhtml\Block\Catalog\Product\Attribute\Set\Main.php on line 55 – Attila Naghi Jul 31 '14 at 7:39
  • @Chester Try my updated code – David Manners Jul 31 '14 at 7:44

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.