0

I have created an observer model to redirect the checkout page after successful order to another form. The Redirection code I have applied is working on my localhost but when I tried the same code on server it is giving the error :

 a:5:{i:0;s:140:"Cannot send headers; headers already sent in /home1/remarkc4/public_html/restauranttechpros/app/code/local/Mage/Cms/Block/Eblock.php, line 2";i:1;s:2101:"#0 /home1/remarkc4/public_html/restauranttechpros/lib/Zend/Controller/Response/Abstract.php(148): Zend_Controller_Response_Abstract->canSendHeaders(true)
 #1 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Core/Controller/Response/Http.php(106): Zend_Controller_Response_Abstract->setRedirect('http://remarkab...', 302)
 #2 /home1/remarkc4/public_html/restauranttechpros/app/code/local/Dataman/OrderInfo/Model/Observer.php(24): Mage_Core_Controller_Response_Http->setRedirect('http://remarkab...')
 #3 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Core/Model/App.php(1338): Dataman_OrderInfo_Model_Observer->getSuccessOrderInfo(Object(Varien_Event_Observer))
 #4 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Core/Model/App.php(1317): Mage_Core_Model_App->_callObserverMethod(Object(Dataman_OrderInfo_Model_Observer), 'getSuccessOrder...', Object(Varien_Event_Observer))
 #5 /home1/remarkc4/public_html/restauranttechpros/app/Mage.php(447): Mage_Core_Model_App->dispatchEvent('checkout_onepag...', Array)
 #6 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Checkout/controllers/OnepageController.php(294): Mage::dispatchEvent('checkout_onepag...', Array)
 #7 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_OnepageController->successAction()
 #8 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('success')
 #9 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
 #10 /home1/remarkc4/public_html/restauranttechpros/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
 #11 /home1/remarkc4/public_html/restauranttechpros/app/Mage.php(683): Mage_Core_Model_App->run(Array)
 #12 /home1/remarkc4/public_html/restauranttechpros/index.php(87): Mage::run('', 'store')
 #13 {main}";s:3:"url";s:55:"/restauranttechpros/index.php/checkout/onepage/success/";s:11:"script_name";s:29:"/restauranttechpros/index.php";s:4:"skin";s:7:"default";} 

Here is my code of observer:

 <?php 
 class Dataman_OrderInfo_Model_Observer
 {
 public function getSuccessOrderInfo(Varien_Event_Observer $observer)
 {
    $orderIds = $observer->getEvent()->getOrderIds();

    if (!is_array($orderIds) || (!array_key_exists(0, $orderIds))) 
    {
        return;
    }

    $order = Mage::getModel('sales/order')->load($orderIds[0]);
    $items = $order->getAllItems();
    $itemcount=count($items);        
    $ids=array();
    foreach ($items as $itemId => $item)
    {            
        $ids[]=$item->getProductId();        
    }        

    if(in_array('1207',$ids))
    {            
        Mage::app()->getResponse()->setRedirect(Mage::getUrl('customerticket'))->sendResponse();
        exit();
    }

    return true;
 }
 }
 ?> 

Please help me what am I doing wrong.

Thanks

1

Check these articles, but i think that the sendResponse is causing the error message :
https://stackoverflow.com/questions/13236912/magento-redirect-from-observer-that-always-works https://stackoverflow.com/questions/9749005/magento-redirect-customer-from-observer-method http://ka.lpe.sh/2013/07/21/magento-redirect-from-observer/

Than look at the server configuration (php.ini) and maybe your cookie configuration. Also check your general web configuration http://www.magentocommerce.com/wiki/modules_reference/english/mage_adminhtml/system_config/edit/web

These article lists the step required to move a production to development server. http://markshust.com/comment/117. http://www.islbd.com/resources/item/24-how-to-move-magento-from-one-server-to-another.html In your case is the other way around, but the steps are the same. In essence you need to update some config values. Pay attention to urls and cookies. I think that they are causing your headaches.

8
  • Thanks for the reply. I have googled a lot from last two days but nothing work for me. I don't know what is the issue on the server as the same code is working absolutely fine on my localhost. – Raina Jan 31 '14 at 10:35
  • I have followed the same steps for installation. Can you tell me any other way through which I can redirect to my desired page after order success? – Raina Jan 31 '14 at 11:38
  • For which event is your observer registered? – Evgeni Ivanov Jan 31 '14 at 11:45
  • It is for checkout_onepage_controller_success_action – Raina Jan 31 '14 at 11:51
  • I just want to check a particular product in the cart and if the order is made with that product then redirect it to some specific page instead of Success page. How can I do this? – Raina Jan 31 '14 at 11:53
0

try the below code in if condition for redirection, Hope so this will work,

if(in_array('1207',$ids))
{
    $response = $observer->getResponse();
    $response->setRedirect(Mage::getUrl('customerticket'));
    Mage::app()->getFrontController()->sendResponse();
}
3
  • Thanks for the reply but it is also not working. – Raina Jan 31 '14 at 11:06
  • check for whitespace at the end of the file(observer.php), if present remove than remove it. – Deepak Mallah Jan 31 '14 at 11:13
  • I also checked that. There is no space. – Raina Jan 31 '14 at 11:15

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.