0

Here is button for controller action

$block->addButton('generate_label', array(
            'label'     => Mage::helper('sales')->__('Generate label'),
            'onclick'   => "setLocation('{$block->getUrl('*/logistics/labelNormal')}')",//if message use: "confirmSetLocation('{$message}', '{$block->getUrl('*/yourmodule/crazy')}')",
            'class'     => 'go'
        ));

This is the controller action where i am trying to redirect to previous page.

public function labelNormalAction() {   //label action

        $order_id = $this->getRequest()->getParam('order_id');

        $this->createLabelAction($order_id,false);

        $this->_redirectReferer();
        return;
    }
  • also tried $refererUrl = $this->getRequest()->getServer('HTTP_REFERER'); but its not return url – Surendra Kumar Ahir Jul 19 '17 at 9:00
1

Solution: Use current url as paramter (get paramter ) when $this->_redirectReferer() not workin

$currentUrl = urlencode(Mage::helper('core/url')->getCurrentUrl());
if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
    $message = Mage::helper('sales')->__('Are you sure you want to do this?');
    $block->addButton('generate_label', array(
        'label'     => Mage::helper('sales')->__('Generate label'),
        'onclick'   => "setLocation('{$block->getUrl('*/logistics/labelNormal')}?current_url=$currentUrl')",//if message use: "confirmSetLocation('{$message}', '{$block->getUrl('*/yourmodule/crazy')}')",
        'class'     => 'go'
    ));
}

get current url form request and set redirect

 public function labelNormalAction() {   //label action

    $order_id = $this->getRequest()->getParam('order_id');
    $redirectUrl = urldecode($this->getRequest()->getParam('current_url'));

    $this->createLabelAction($order_id,false);

    if($redirectUrl) {
     $this->getResponse()->setRedirect($redirectUrl);
        return $this;
    } else {
      $this->_redirectReferer();
      return;

    }

}
  • only use this solution when $this->_redirectReferer(); not work – Surendra Kumar Ahir Jul 19 '17 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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