1
votes

I am working on a module where I have created one menu in Magento admin using adminhtml.xml.

Now I want to link one of the menu to an external URL and set target="blank". But I'm not sure how to do it in adminhtml.xml. Here is my code.

<?xml version="1.0"?>
<config>
    <menu>
        <system>
            <children>
                <convert translate="title">
                    <children>
                        <importmagmi translate="title" module="importexport">
                            <title>MagMi Importer</title>
                            <action><url helper="https://externalurl.com"/></action>
                            <sort_order>100</sort_order>
                        </importmagmi>
                    </children>
                </convert>
            </children>
        </system>
    </menu>
</config>

When i am checking its adding current domain name before external url. ex: http://mydomainname.com/https://externalurl.com

I am wondering how to set only external URL ?

3

3 Answers

3
votes

Inside <action> tag you can put module/controller/action of your module.

Then create this action and put something like this:

public function locationAction()
{
    $this->_redirectUrl('http://www.example.com/');
}

See Mage_Core_Controller_Varien_Action::_redirectUrl for the standard redirect implementation in Magento controller actions.

1
votes

Unfortunately, this is not possible out of the box. For this to work you'd have to override Mage_Adminhtml_Block_Page_Menu class.

I'd suggest to modify the _buildMenuArray method to support a "external_url" config option in adminhtml.xml like so

if( $child->external_url ) {
    $menuArr['url'] = (string)$child->external_url;
    $menuArr['is_external'] = true;
} 
elseif ($child->action) {
    $menuArr['url'] = $this->_url->getUrl((string)$child->action, array('_cache_secret_key' => true));
} else {
    $menuArr['url'] = '#';
    $menuArr['click'] = 'return false';
}

and getMenuLevelmethod respectively

$html .= '<li ' . (!empty($item['children']) ? 'onmouseover="Element.addClassName(this,\'over\')" '
            . 'onmouseout="Element.removeClassName(this,\'over\')"' : '') . ' class="'
            . (!$level && !empty($item['active']) ? ' active' : '') . ' '
            . (!empty($item['children']) ? ' parent' : '')
            . (!empty($level) && !empty($item['last']) ? ' last' : '')
            . ' level' . $level . '"> <a ' . ($item['is_external'] ? 'target="_blank" ' : '') . 'href="' . $item['url'] . '" '
            . (!empty($item['title']) ? 'title="' . $item['title'] . '"' : '') . ' '
            . (!empty($item['click']) ? 'onclick="' . $item['click'] . '"' : '') . ' class="'
            . ($level === 0 && !empty($item['active']) ? 'active' : '') . '"><span>'
            . $this->escapeHtml($item['label']) . '</span></a>' . PHP_EOL;

Then you can add to your configuration

<?xml version="1.0"?>
<config>
    <menu>
        <system>
            <children>
                <convert translate="title">
                    <children>
                        <importmagmi translate="title" module="importexport">
                            <title>MagMi Importer</title>
                            <external_url>https://externalurl.com</external_url>                                <sort_order>100</sort_order>
                        </importmagmi>
                    </children>
                </convert>
            </children>
        </system>
    </menu>
</config>

Remember to rewrite the class and do not modify the core class.

-1
votes
<?php
$url = 'http://example.com';
$this->_redirectUrl('http://example.com');

Mage::app()->getResponse()->setRedirect($url)->sendResponse();

Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
?>