Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I need to generate in one of my custom module a link to a category edit page in the backend. So I generate the url like this:

 $url = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_category/index', array('id'=>$category->getId()));

or like this:

 $url = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_category/edit', array('id'=>$category->getId()));

I get a correct url in both cases:

ROOT/admin/catalog_category/index/id/10/key/<security-key-here>/
//and
ROOT/admin/catalog_category/edit/id/10/key/<security-key-here>/

But when the page loads, for a split second I see in the edit form the data for my category or the category I previously edited and then there is an ajax call that clears my form and I'm on add mode. ('New Root Category'). The <title> tag of the page contains the correct category name. On the left side tree, the correct category is selected.

The ajax call that clears the form is made to

`ROOT/admin/catalog_category/edit/key/<security-key-here>/?isAjax=true`

So there is no id parameter in the ajax call. I guess that's the problem.
How can I make this work?
This seams like a bug to me. I stand corrected. Based on David's answer this seams like a feature.

But I recall this working correctly in a really old version (don't remember which).
I tested on and and the result is the same.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Try adding the parameter clear to your urls.

There is a function isClearEdit that is in the class Mage_Adminhtml_Block_Catalog_Category_Tree This appears to stop the second load or at least load the correct category.

/**
 * Check if page loaded by outside link to category edit
 *
 * @return boolean
 */
public function isClearEdit()
{
    return (bool) $this->getRequest()->getParam('clear');
}

In the tree template app/design/adminhtml/default/default/template/catalog/category/tree.phtml this will add the id of the category to the url used to update the content during the call to _renderNewTree.

So when building your url use the following code.

Mage::helper('adminhtml')->getUrl('adminhtml/catalog_category/index', array('id'=>$category->getId(), 'clear'=>1));
share|improve this answer
    
What do you know...it works. So I need to generate the url like this Mage::helper('adminhtml')->getUrl('adminhtml/catalog_category/index', array('id'=>$category->getId(), 'clear'=>1)); –  Marius Aug 19 at 8:31
    
It seems to be there in at least Mage 1.6 I have no earlier versions currently :) –  David Manners Aug 19 at 8:34
    
The funny thing is that I've included this 'feature' in my module creator extension, and it works the same for any tree behaving entity that you create with it. I had no idea what the 'clear' parameter does, but included anyway...and it works. :) –  Marius Aug 19 at 8:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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