I'm trying to make an AJAX call from the sales order create index in the Magento backend. My url is formed by this function and is returning a 404.
This is the URL it is forming http://127.0.0.1/wsi/index.php/admin/autocustomerlookup/address/checkEmailExists/key/e7dc1ffa2f80b1892da02f80688a29c4/
<?php echo Mage::helper('adminhtml')->getUrl('autocustomerlookup/address/checkEmailExists');?>
I'm basing my work on this Git repo https://github.com/zhukandrey/Atwix_EmailAjax/
I can't figure out why it isn't working, I am certain there is some error with my controller or my routing, trying to make the call from the Magento backend. But I'm stumped!
<config>
<modules>
<TwilitGrotto_AutoCustomerLookup>
<version>1.0.0.0</version>
</TwilitGrotto_AutoCustomerLookup>
</modules>
<global>
<helpers>
<twilitgrotto_autocustomerlookup>
<class>TwilitGrotto_AutoCustomerLookup_Helper</class>
</twilitgrotto_autocustomerlookup>
</helpers>
</global>
<adminhtml>
<layout>
<updates>
<twilitgrotto>
<file>twilitgrotto_autocustomerlookup_layout.xml</file>
</twilitgrotto>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<adminhtml>
<twilitgrotto_autocustomerlookup>
<use>admin</use>
<args>
<module>TwilitGrotto_AutoCustomerLookup</module>
<modules>
<TwilitGrotto_AutoCustomerLookup after="Mage_Adminhtml">
TwilitGrotto_AutoCustomerLookup
</TwilitGrotto_AutoCustomerLookup>
</modules>
<frontName>autocustomerlookup</frontName>
</args>
</twilitgrotto_autocustomerlookup>
</adminhtml>
</routers>
</admin>
</config>
function handleEmailEvent(){ var email = document.getElementById("email"); var url = document.getElementById('check_email_address_exists').innerHTML; makeRequest(url, $F(email) ); } function makeRequest(url, emailAddress){ var httpRequest = new XMLHttpRequest(); console.log(url); if ( !httpRequest) { console.log('httpRequest failed'); return false; } httpRequest.open( 'POST', url ); httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); httpRequest.send('emailAddress=' + encodeURIComponent(email)); console.log(httpRequest); }
class TwilitGrotto_AutoCustomerLookup_AddressController extends Mage_Adminhtml_Controller_Action{ public function checkEmailExistsAction(){ $emailAddress = $this->getRequest()->getParam('emailAddress'); $result = Mage::helper('twilitgrotto_autocustomerlookup')->checkEmailExists($emailAddress); $this->getResponse()->setBody($result); } }
class TwilitGrotto_AutoCustomerLookup_Helper_Data extends Mage_Core_Helper_Data{ public function checkEmailExists($emailAddress) { $emailAddressCheck = Mage::getModel('customer/customer') ->getCollection() ->addAttributeToSelect('email') ->addAttributeToFilter('email', $emailAddress)->load(); if(!$emailAddressCheck->getSize()) { $result = 'ok'; } else { $result = 'error'; } return $result; } }
Edited to add entire config.xml
public function isAllowed() { return true; }
method :D