2

Is there any way to add a category tree with checkboxes to a form in the admin part?

The form contains two other fieldsets, and the category tree must be added as the third fieldset. All information that I have found was how to add a category tree separately, without injecting it in existing form. But here I need to render a block inside another block, or something like this.

I am curious how can I achieve this.

Gino Pane
  • 183
  • 8

1 Answers1

1

you will find here and example about how to add the category tree in a separate tab.
You can start from there.
The block that renders the category tree behaves like any other block so it can be included anywhere.
All you have to do is to change the layout file and include that block in an other block and then display it using getChildHtml.
Or you can create a form element that uses a custom renderer and this renderer should be the block in question, but this is a little complicated.

Marius
  • 197,939
  • 53
  • 422
  • 830
  • Thanks! But addTab method is used there. I don't use it, I add tabs through xml declaration. Should I skip that step? – Gino Pane Nov 04 '15 at 08:44
  • yes, you can skip that step – Marius Nov 04 '15 at 08:45
  • it seems, that quantities of subcategories are not displayed (in round brackets). – Gino Pane Nov 04 '15 at 13:11
  • Maybe, you know how to enable display of those quantities, like this: http://prntscr.com/8yx9no? – Gino Pane Nov 04 '15 at 13:29
  • it's kind of complicated. you need to add to the collection the product count and you need to change the method that displays the node. I don't remember how it's called. – Marius Nov 04 '15 at 13:30
  • Hello Marius. I am doing the same thing as in question. Can you explain the second method of renderer a little bit.? How can I do use it.? – Shashank Kumrawat Nov 04 '15 at 18:45
  • @shashank You can find here an example on how you can add a custom attribute that uses a custom renderer: http://magento.stackexchange.com/a/38445/146. It's for a different thing, but the idea is the same. – Marius Nov 04 '15 at 22:02
  • @shashank, for me it worked like that: Mage::app()->getLayout()->createBlock('your_block_name')->toHtml(). – Gino Pane Nov 05 '15 at 07:19
  • @Marius, finally, I found it - you only need to set $this->_withProductCount to true in constructor of a categories block. – Gino Pane Nov 05 '15 at 07:20
  • I have posted my question http://magento.stackexchange.com/questions/88929/add-category-tree-structure-in-custom-module-form – Shashank Kumrawat Nov 05 '15 at 07:45