/**
  * Creates a new API user, copied from the maintainer data
  * that was actually created.
  *
  * @return Faett_Channel_Model_Customer The user created before
  */
 public function _afterSave()
 {
     // try to load an API user with the email of the created user
     $maintainer = Mage::getModel('channel/maintainer')->loadByEmail($this->getEmail());
     // check if already an API user with the email exists
     if (!$maintainer->userExists()) {
         // if not, copy the user's data
         $maintainer->setFirstname($this->getFirstname());
         $maintainer->setLastname($this->getLastname());
         $maintainer->setUsername($this->hashPassword($this->getEmail()));
         $maintainer->setEmail($this->getEmail());
         // save with password copied from user
         $maintainer->saveWithCopiedPassword($this);
         // check if the default role ID is set
         if ($defaultRoleId = $this->_getDefaultRole()) {
             // set the role ID
             $maintainer->setRoleId($defaultRoleId);
             // check if the API user already has this role
             // (should usally never happen)
             if (!$maintainer->roleUserExists()) {
                 // add the user to the role
                 $maintainer->add();
             }
         }
     }
     // invoke the _afterSave() method of the parent class
     return parent::_afterSave();
 }
 protected function _afterSave()
 {
     parent::_afterSave();
     if (!$this->hasDataChanges()) {
         return $this;
     }
     $this->_updatePasswordHistory();
     return $this;
 }
 protected function _afterSave()
 {
     $oAttribute = Mage::getModel('aitcheckoutfields/aitcheckoutfields');
     if (Mage::registry('aitoc_customer_to_save') && !Mage::registry('aitoc_customer_saved')) {
         $customerId = $this->getId();
         $oAttribute->saveCustomerData($customerId);
         $oAttribute->clearCheckoutSession('register');
         Mage::unregister('aitoc_customer_to_save');
         Mage::register('aitoc_customer_saved', true);
         Mage::dispatchEvent('aitcfm_customer_save_after', array('customer' => $this, 'checkoutfields' => $this->getCustomFields()));
     }
     $oAttribute->clearCheckoutSession('register');
     return parent::_afterSave();
 }
Beispiel #4
0
 /**
  * Processing object after save data
  * (override from an abstract parent)
  *
  * @return Mage_Core_Model_Abstract
  */
 protected function _afterSave()
 {
     //If the customer is new (hence not having an id before) get applicable rules,
     //and create a transfer for each one
     $isNew = false;
     if ($this->isNewCustomer($this->getId())) {
         $isNew = true;
         $this->oldId = $this->getId();
         //This stops multiple triggers of this function
         $this->createTransferForNewCustomer();
     }
     Mage::getSingleton('rewards/session')->setCustomer($this);
     if ($isNew) {
         if (Mage::helper('rewards/dispatch')->smartDispatch('rewards_customer_signup', array('customer' => $this))) {
             Mage::getSingleton('rewards/session')->triggerNewCustomerCreate($this);
             Mage::dispatchEvent('rewards_new_customer_create', array('customer' => &$this));
         }
     }
     return parent::_afterSave();
 }
Beispiel #5
0
 protected function _afterSave()
 {
     if ($this->_fileAttributes) {
         $deleteFiles = Mage::app()->getRequest()->getPost('amcustomerattr_delete');
         foreach ($this->_fileAttributes as $id => $attributeCode) {
             if (isset($_FILES['amcustomerattr_' . $attributeCode]['error']) && UPLOAD_ERR_OK == $_FILES['amcustomerattr_' . $attributeCode]['error']) {
                 try {
                     $fileName = $_FILES['amcustomerattr_' . $attributeCode]['name'];
                     $uploader = new Varien_File_Uploader('amcustomerattr_' . $attributeCode);
                     $uploader->setAllowRenameFiles(false);
                     $uploader->setFilesDispersion(false);
                     $destinationFolder = Mage::helper('amcustomerattr')->getAttributeFileUrl($fileName);
                     $fileName = Mage::helper('amcustomerattr')->cleanFileName($fileName);
                     $uploader->save($destinationFolder . $fileName[1] . DS . $fileName[2] . DS, $fileName[3]);
                 } catch (Exception $error) {
                     $e = new Mage_Customer_Exception(Mage::helper('amcustomerattr')->__('An error occurred while saving the file: ' . $error->getMessage()));
                     if (method_exists($e, 'setMessage')) {
                         $e->setMessage(Mage::helper('amcustomerattr')->__('An error occurred while saving the file: ' . $error));
                     }
                     throw $e;
                 }
                 if ($this->_savedFileNames[$attributeCode]) {
                     Mage::helper('amcustomerattr')->deleteFile($this->_savedFileNames[$attributeCode]);
                 }
             }
             if ($deleteFiles && $deleteFiles[$attributeCode] && $this->_savedFileNames[$attributeCode] === $deleteFiles[$attributeCode]) {
                 Mage::helper('amcustomerattr')->deleteFile($deleteFiles[$attributeCode]);
             }
             unset($_FILES['amcustomerattr_' . $attributeCode]);
         }
     }
     if (!$this->getOrigId() && !Mage::registry('amcustomerattr_customer_registry_dispatched')) {
         Mage::register('amcustomerattr_customer_registry_dispatched', true);
         Mage::dispatchEvent('amcustomerattr_customer_registry', array('model' => $this));
     }
     Mage::getSingleton('customer/session')->unsetData('amcustomerattr');
     /*
      * send notification upon new user registration to admin
      */
     $origData = $this->getOrigData();
     if ($origData === null) {
         // new user registration will be
         $notified = Mage::registry('AdminNotifiedAboutNewUser');
         if (Mage::getStoreConfig('amcustomerattr/activation/notify_admin', $this->getStoreId()) && !$notified) {
             Mage::register('AdminNotifiedAboutNewUser', '1');
             $translate = Mage::getSingleton('core/translate');
             $translate->setTranslateInline(false);
             $template = Mage::getStoreConfig('amcustomerattr/activation/email_template_admin', $this->getStoreId());
             $template = $template ? $template : 'amasty_amcustomerattr_activation_email_template_admin';
             $emails = Mage::getStoreConfig('amcustomerattr/activation/admin_email', $this->getStoreId());
             foreach (explode(',', $emails) as $email) {
                 $email = trim($email);
                 $tpl = Mage::getModel('core/email_template');
                 $tpl->setDesignConfig(array('area' => 'frontend', 'store' => $this->getStoreId()))->sendTransactional($template, Mage::getStoreConfig('amcustomerattr/activation/admin_sender', $this->getStoreId()), $email, 'Admin notification', array('customer_name' => $this->getName(), 'customer_id' => $this->getEntityId(), 'created_at' => date('Y-m-d', $this->getCreatedAtTimestamp()), 'customer' => $this), $this->getStoreId());
                 $tpl = null;
             }
             $translate->setTranslateInline(true);
         }
     }
     /*
      * send notification about activation to user
      */
     $payment_post = Mage::app()->getRequest()->getPost('payment');
     //exclude checkout pages
     if (Mage::getStoreConfig('amcustomerattr/activation/notify_customer', $this->getStoreId()) && !$payment_post && $this->getOrigData('am_is_activated') != $this->getData('am_is_activated') && self::ACTIVATION_STATUS_ACTIVATED == $this->getData('am_is_activated')) {
         $notified = Mage::registry('CustomerNotifiedAboutActivation');
         if (!$notified) {
             Mage::register('CustomerNotifiedAboutActivation', '1');
             $translate = Mage::getSingleton('core/translate');
             $translate->setTranslateInline(false);
             $template = Mage::getStoreConfig('amcustomerattr/activation/email_template_customer', $this->getStoreId());
             $template = $template ? $template : 'amasty_amcustomerattr_activation_email_template_customer';
             $tpl = Mage::getModel('core/email_template');
             $tpl->setDesignConfig(array('area' => 'frontend', 'store' => $this->getStoreId()))->sendTransactional($template, Mage::getStoreConfig('amcustomerattr/activation/customer_sender', $this->getStoreId()), $this->getEmail(), 'Customer notification', array('customer_name' => $this->getName(), 'customer_id' => $this->getEntityId(), 'email' => $this->getEmail(), 'created_at' => $this->getCreatedAtTimestamp(), 'customer' => $this), $this->getSoreId());
             $tpl = null;
             $translate->setTranslateInline(true);
         }
     } else {
         if ($origData === null && Mage::getStoreConfig('amcustomerattr/activation/activation_required', $this->getStoreId())) {
             if (!Mage::getStoreConfig('amcustomerattr/activation/auto_activation', $this->getStoreId()) || Mage::getStoreConfig('amcustomerattr/activation/auto_activation', $this->getStoreId()) && Mage::getStoreConfig('amcustomerattr/activation/enabled_customer_groups', $this->getStoreId()) && self::ACTIVATION_STATUS_ACTIVATED != $this->getAmIsActivated()) {
                 $this->setIsLoggedIn(true);
                 Mage::getSingleton('customer/session')->logout();
                 $customerSession = Mage::getSingleton('customer/session');
                 $customerSession->unsetAll();
                 $customerSession->getCookie()->delete($customerSession->getSessionName());
                 if (!Mage::registry('CustomerNotificationAboutActivation') && Mage::getStoreConfig('amcustomerattr/activation/registration_notice', $this->getStoreId())) {
                     Mage::register('CustomerNotificationAboutActivation', 1);
                     Mage::getSingleton('core/session')->addNotice(Mage::getStoreConfig('amcustomerattr/activation/registration_notice', $this->getStoreId()));
                 }
             }
         }
     }
     parent::_afterSave();
 }
 /**
  * (non-PHPdoc)
  * @see Mage_Core_Model_Abstract::_afterSave()
  */
 public function _afterSave()
 {
     if ($this->getId()) {
         if ($this->getData('customer_type') == 'vendor') {
             if (!empty($this->vendorModel)) {
                 $this->vendorModel->addData($this->getData());
                 $this->vendorModel->setCustomerId($this->getId());
                 // create account for vendor
                 $vendorRole = Mage::helper('smvendors')->getVendorRole();
                 $data = array('username' => $this->getEmail(), 'email' => $this->getEmail(), 'firstname' => $this->getFirstname(), 'lastname' => $this->getLastname(), 'is_active' => $this->vendorModel->getVendorStatus(), 'roles' => array($vendorRole));
                 $newPassword = $this->getData('user_password');
                 if (!empty($newPassword)) {
                     $data['password'] = $newPassword;
                     $data['password_confirmation'] = $newPassword;
                 }
                 if ($data) {
                     $id = $this->vendorModel->getUserId();
                     $model = Mage::getModel('admin/user')->load($id);
                     if (!$model->getIsActive() && $data['is_active']) {
                         $this->sendNewAccountEmail('approved', '', Mage::helper('smvendors')->getDefaultStoreId());
                     }
                     $model->addData($data);
                     $result = $model->validate();
                     if (is_array($result)) {
                         Mage::getSingleton('adminhtml/session')->setUserData($data);
                         foreach ($result as $message) {
                             Mage::getSingleton('adminhtml/session')->addError($message);
                         }
                     }
                     try {
                         $model->save();
                         if ($uRoles = $data['roles']) {
                             if (1 == sizeof($uRoles)) {
                                 $model->setRoleIds($uRoles)->setRoleUserId($model->getUserId())->saveRelations();
                             } elseif (sizeof($uRoles) > 1) {
                                 $rs = array();
                                 $rs[0] = $uRoles[0];
                                 $model->setRoleIds($rs)->setRoleUserId($model->getUserId())->saveRelations();
                             }
                         }
                         $this->vendorModel->setUserId($model->getUserId());
                         $passwordHash = trim($this->getPasswordHash());
                         if (!empty($passwordHash)) {
                             //print_r($this->getData());die;
                             $resource = Mage::getSingleton('core/resource');
                             $writeConnection = $resource->getConnection('core_write');
                             $tableUser = $resource->getTableName('admin/user');
                             $query = "UPDATE {$tableUser} SET password = '******' WHERE user_id = " . (int) $model->getUserId();
                             $writeConnection->query($query);
                         }
                         Mage::getSingleton('adminhtml/session')->setUserData(false);
                     } catch (Mage_Core_Exception $e) {
                         Mage::getSingleton('adminhtml/session')->addError($this->__('Customer is saved, but this error happened: ' . $e->getMessage()));
                         Mage::logException($e);
                     }
                 }
                 $this->vendorModel->save();
             }
         }
     }
     return parent::_afterSave();
 }