I have an observer that listens for when a customer is successfully registered! Using the Magento Event: customer_register_success
I have a custom table called "am_perm" I'm able to manually go into my database and write the SQL query:
INSERT INTO `am_perm`(`uid`, `cid`) VALUES (25, 139)
and it works perfectly! However in my event observer it does not work!
Here is my code in the event listener the params passed in are:
$userId = 25 & $customerId = 139
public function assignDealer(Varien_Event_Observer $observer)
{
function assignOneCustomer($userId, $customerId)
{
try {
$userId = intVal($userId);
$customerId = intVal($customerId);
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$themeTable = $resource->getTableName('am_perm');
$sql = "INSERT INTO `am_perm`(`uid`, `cid`) VALUES ($userId, $customerId)";
$writeConnection->query($sql);//insert
return true;
}
catch(Exception $e){
die($e);
}
}
$registerParams = Mage::app()->getRequest()->getParams();
$paramMerchantCode = $registerParams['merchant_code'];
if (isset($paramMerchantCode)) {
$customerId = $observer->getCustomer()->getId();
$merchantIdArray = array();
//Grab the Admin_Role Table from SQL
$model = Mage::getModel('admin/role');
//Grab all roles with Merchant but only need the first one for ID
//Table will be massive unless we use relational database ID versus primary ID
$role = $model->getCollection()->addFieldToFilter('role_name', ['eq' => "Merchant"])->getFirstItem();
//Loop through database and grab all ID's for Merchants and place into $mcArray
if ($roleId = $role->getId()) {
$dealerArray = $model->getCollection()->addFieldToFilter('parent_id', ['eq' => $roleId]);
foreach ($dealerArray as $currentDealer) {
array_push($merchantIdArray, $currentDealer['user_id']);
}
}
//Look up Merchants and compare code to Merchant Code
//If Code matches we store the $merchantId
foreach ($merchantIdArray as $id) {
$adminUser = Mage::getModel('admin/user')->load($id);
$userMerchantCode = $adminUser->getData("merchant_code");
if (strtolower($paramMerchantCode) == strtolower($userMerchantCode)) {
$uid = $id;
}
}
if ($uid && $customerId) {
Mage::getModel('amperm/perm')->assignOneCustomer($uid, $customerId);
}
}
}
It never catches the Exception $e but it also never saves to my database? What am I missing?