I have an external php file that I call using ajax on Magento register page. This php code should help validate if the value of a text input field is valid. See php code:
require_once ('app/Mage.php');
Mage::app()->getStore();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$request = Mage::app()->getRequest();
$customer = Mage::getModel('customer/customer');
$inviteCode = $request->getParam('code');
if (($inviteCode) && ($inviteCode != '')) {
$websiteId = Mage::app()->getWebsite()->getId();
$customerId = $customer->setWebsiteId($websiteId)->loadByEmail($inviteCode)->getId();
if ($customerId && ($customerId != '')) {
$account = Mage::getModel('affiliateplus/account')->getCollection()->addFieldToFilter('customer_id', $customerId)->getFirstItem();
if ($account && ($account->getAccountId())) {
$result = "Valid Invite Code";
}
}
}
//echo json_encode($result);
echo ($account );
I have a multiple website installation. This code sits in a addon domain hosted in a subfolder yyy.
$websiteIdshould return "5" (xxx.com/yyy), but it keeps returning "1" (xxx.com).- If I manually set
$websiteIdto "5",$accountreturns empty value
The code works fine in a model function. Any help would be appreciated.
Thanks.
First, you need to locate the
app/Mage.phpfile and require it in your php file. require_once 'app/Mage.php';Add Below code in your php file: