Redirection to Admin Customer Edit (with key) from a frontend controller
-
12-12-2019 - |
Question
I'm trying to make a redirection from one of my module to Admin > Manage Customer > Edit.
Mage::app()->getResponse()->setRedirect(Mage::helper("adminhtml")->getUrl("adminhtml/customer/edit/", array("id"=>$customer_id)));
The URL called seems to be good, with a url key. But this URL leads to a 302 response and auto-redirect me to the dashboard.
In fact it seems that the generated URL is different from the real URL : the keys are not the same for both of them, which explains why I'm redirected I guess.
If I disable the keys in URL from admin, the redirection is ok.
Can you help me with this problem ? Thank you very much.
Solution
Take a look at How can I generate an admin link from a frontend controller?
Short answer: you can't, but if you create a admin controller that will act like a proxy to get the url key then do the redirect (since you can disable the validation of admin url using $_publicActions
).
class MagePal_ProxyCustomerRedirect_Adminhtml_RedirectController extends Mage_Adminhtml_Controller_Action
{
/**
* Array of actions which can be processed without secret key validation
*
* @var array
*/
protected $_publicActions = array('redirecttocustomer');
public function redirecttocustomerAction()
{
// get the customer id pass by your observer (url key)
Mage::app()->getResponse()->setRedirect(Mage::helper("adminhtml")->getUrl("adminhtml/customer/edit/", array("id"=>$customer_id)));
In your observer
Mage::app()->getResponse()->setRedirect(Mage::helper("adminhtml")->getUrl("adminhtml/redirecttocustomer/edit/", array("id"=>$customer_id)));
See Mage_Adminhtml_Controller_Action
protected function _validateSecretKey()
{
if (is_array($this->_publicActions) && in_array($this->getRequest()->getActionName(), $this->_publicActions)) {
return true;
}
if (!($secretKey = $this->getRequest()->getParam(Mage_Adminhtml_Model_Url::SECRET_KEY_PARAM_NAME, null))
|| $secretKey != Mage::getSingleton('adminhtml/url')->getSecretKey()) {
return false;
}
return true;
}