Question

I will make an AJAX request in Magento block that call an action in my own module controller. But the response of this request is 302, and redirect on the admin sign in page if i'm not sign in. This request is on the front and don't need admin sign in.

My javascript code :

var xmlhttp;
if(typeof XMLHttpRequest !== 'undefined') xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://mac-4.local:8888/magento_sample_1.4.2/index.php/disponibilityshippingicon/disponibility/setcustomeraddressinsession/", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send('city=' + jsonAddress['city'] + '&cp=' + jsonAddress['cp'] + '&country=' + jsonAddress['country']);

My controler code :

class ColisWeb_DisponibilityShippingIcon_DisponibilityController extends Mage_Adminhtml_Controller_Action
{

public function setcustomeraddressinsessionAction() {
    $params = $this->getRequest()->getParams();
    Mage::log("ColisWeb - Addresse du visiteur non poussé en session : " . $params['city'] . $params['cp'] . $params['country'], Zend_log::INFO);
    if (isset($params['city'], $params['cp'], $params['country'])) {

        //new Mage_Customer_Model_Address();
        $address =  Mage::getModel('customer/address');
        $address->setCity($params['city']);
        $address->setPostCode($params['cp']);

        $session = Mage::getSingleton('core/session');
        $session->setData('addressColisweb', $address);
        $session->setData('cityAddressColisweb', $params['city']);
        $session->setData('postCodeAddressColisweb', $params['cp']);
        $session->setData('contryAddressColisweb', $params['country']);


    }
    else {


    }


    $this->getResponse()->setHeader('Content-type', 'application/json', true) ;
    $result = array( 'status' => '200');
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));   
}

}
?>

My version of Magento is 1.4.2

I hope somebody can help me.

Thanks for your help!

Was it helpful?

Solution

Your controller extends Mage_Adminhtml_Controller_Action - it should be Mage_Core_Controller_Front_Action instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top