0

I want to remove "Add new" Button from Admin Grid conditionally. Condition is if it has flag for adding then button will display otherwise not

Kindly help.

Thanks.

1 Answer 1

1

I will try to shed light on how the Add New button in the Catalog -> Product grid is displayed and what can be maybe done about it.

If you open file

/app/code/core/Mage/Adminhtml/Block/Catalog/Product

you will notice that this class extends

Mage_Adminhtml_Block_Widget_Container

This Container class provides the method

_addButton()

which as its first parameter accepts string: the button ID.

So, take a look at the method prepareLayout and you will notice

$this->_addButton('add_new', array(
        'label'   => Mage::helper('catalog')->__('Add Product'),
        'onclick' => "setLocation('{$this->getUrl('*/*/new')}')",
        'class'   => 'add'
    ));

After this the button id is: add_new

The Container class also provides a method

_removeButton()

which accepts only one attribute: the button ID

This given, you should probably override the block that defines the button.

In more details, override the _prepareLayout method and use the _addButton conditionally in the first place (so you don't have to remove at all).

Or in other cases, where applicable, just call

$this->_removeButton($button_id)

In my example it would be

$this->_removeButton("add_new")

Of course, you can enclose this code in IF statement with whatever condition you need.

1
  • You are very welcome! :)
    – Marjan
    Sep 6, 2018 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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