Beispiel #1
0
 public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $testOnly = false)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->where('email=?', $email);
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         $select->where('website_id=?', (int) $customer->getWebsiteId());
     }
     if ($id = $this->_getReadAdapter()->fetchOne($select)) {
         $this->load($customer, $id);
     }
     return $this;
 }
Beispiel #2
0
 public function updateRegistryData(Mage_Customer_Model_Customer $customer, $data)
 {
     try {
         if (!empty($data)) {
             $this->setCustomerId($customer->getId());
             $this->setWebsiteId($customer->getWebsiteId());
             $this->setTypeId($data['type_id']);
             $this->setEventName($data['event_name']);
             $this->setEventDate($data['event_date']);
             $this->setEventCountry($data['event_country']);
             $this->setEventLocation($data['event_location']);
         }
     } catch (Exception $e) {
         Mage::logException($e);
     }
     Mage::log($data);
     return $this;
 }
Beispiel #3
0
 public function updateRegistryData(Mage_Customer_Model_Customer $customer, $data)
 {
     try {
         if (!empty($data)) {
             $this->setCustomerId($customer->getId());
             $this->setWebsiteId($customer->getWebsiteId());
             $this->setTypeId($data['type_id']);
             $this->setEventName($data['event_name']);
             $this->setEventDate($data['event_date']);
             $this->setEventCountry($data['event_country']);
             $this->setEventLocation($data['event_location']);
         } else {
             throw new Exception("Error Processing Request:Insufficient Data Provided");
         }
     } catch (Exception $e) {
         Mage::logException($e);
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Load customer by username
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param string $username
  * @return Mage_Customer_Model_Entity_Customer
  * @throws Mage_Core_Exception
  */
 public function loadByUsername(Mage_Customer_Model_Customer $customer, $username)
 {
     if (!Mage::getStoreConfigFlag('username/general/case_sensitive')) {
         $filter = new Zend_Filter_StringToLower(array('encoding' => 'UTF-8'));
         $username = $filter->filter($username);
     }
     $select = $this->_getReadAdapter()->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->joinNatural(array('cev' => $this->getTable('customer_entity_varchar')))->joinNatural(array('ea' => $this->getTable('eav/attribute')))->where('ea.attribute_code=\'username\' AND cev.value=?', $username);
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         if (!$customer->hasData('website_id')) {
             Mage::throwException(Mage::helper('customer')->__('Customer website ID must be specified when using the website scope.'));
         }
         $select->where('website_id=?', (int) $customer->getWebsiteId());
     }
     if ($id = $this->_getReadAdapter()->fetchOne($select, 'entity_id')) {
         $this->load($customer, $id);
     } else {
         $customer->setData(array());
     }
     return $this;
 }
Beispiel #5
0
 /**
  * Load customer by email
  *
  * @throws Mage_Core_Exception
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param string $email
  * @param bool $testOnly
  * @return Mage_Customer_Model_Resource_Customer
  */
 public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $testOnly = false)
 {
     $adapter = $this->_getReadAdapter();
     $bind = array('customer_email' => $email);
     $select = $adapter->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->where('email = :customer_email');
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         if (!$customer->hasData('website_id')) {
             Mage::throwException(Mage::helper('Mage_Customer_Helper_Data')->__('Customer website ID must be specified when using the website scope'));
         }
         $bind['website_id'] = (int) $customer->getWebsiteId();
         $select->where('website_id = :website_id');
     }
     $customerId = $adapter->fetchOne($select, $bind);
     if ($customerId) {
         $this->load($customer, $customerId);
     } else {
         $customer->setData(array());
     }
     return $this;
 }
 /**
  * Return the Store Id to read configuration settings for this customer from
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return int
  */
 public function getCustomerStoreId(Mage_Customer_Model_Customer $customer)
 {
     /*
      * Only set in Adminhtml UI
      */
     if (!($storeId = $customer->getSendemailStoreId())) {
         /*
          * store_id might be zero if the account was created in the admin interface
          */
         $storeId = $customer->getStoreId();
         if (!$storeId && $customer->getWebsiteId()) {
             /*
              * Use the default store groups store of the customers website
              */
             if ($store = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()) {
                 $storeId = $store->getId();
             }
         }
         // In case the website_id is not yet set on the customer, and the
         // current store is a frontend store, use the current store ID
         if (!$storeId && !Mage::app()->getStore()->isAdmin()) {
             $storeId = Mage::app()->getStore()->getId();
         }
     }
     return $storeId;
 }
Beispiel #7
0
 /**
  * Load customer by email
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param string $email
  * @param bool $testOnly
  * @return Mage_Customer_Model_Entity_Customer
  * @throws Mage_Core_Exception
  */
 public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $testOnly = false)
 {
     $select = $this->_getReadAdapter()->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->where('email=:customer_email');
     if ($customer->getSharingConfig()->isWebsiteScope()) {
         if (!$customer->hasData('website_id')) {
             Mage::throwException(Mage::helper('customer')->__('Customer website id must be specified, when using website scope.'));
         }
         $select->where('website_id=?', (int) $customer->getWebsiteId());
     }
     if ($id = $this->_getReadAdapter()->fetchOne($select, array('customer_email' => $email))) {
         $this->load($customer, $id);
     } else {
         $customer->setData(array());
     }
     return $this;
 }
Beispiel #8
0
 /**
  * Get Customer Store Id
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return int|null
  */
 protected function _getCustomerStoreId(Mage_Customer_Model_Customer $customer)
 {
     $customerStoreId = null;
     if ($customer->getId()) {
         $customerStoreId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
     }
     return $customerStoreId;
 }
Beispiel #9
0
 /**
  * Send welcome email to customer
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param array $customerData
  * @return Mage_Customer_Service_Customer
  */
 protected function _sendWelcomeEmail($customer, array $customerData)
 {
     if ($customer->getWebsiteId() && ($this->_isSendEmail($customerData) || $this->_isAutogeneratePassword($customerData))) {
         $isNewCustomer = !(bool) $customer->getOrigData($customer->getIdFieldName());
         $storeId = $customer->getSendemailStoreId();
         if ($isNewCustomer) {
             $customer->sendNewAccountEmail('registered', '', $storeId);
         } elseif (!$customer->getConfirmation()) {
             // Confirm not confirmed customer
             $customer->sendNewAccountEmail('confirmed', '', $storeId);
         }
     }
     return $this;
 }
 /**
  * get customer last quote id
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return bool|Varien_Object
  */
 public function getCustomerLastQuoteId(Mage_Customer_Model_Customer $customer)
 {
     $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
     $collection = Mage::getModel('sales/quote')->getCollection();
     $collection->addFieldToFilter('customer_id', $customer->getId())->addFieldToFilter('store_id', array('in' => $storeIds))->setPageSize(1)->setOrder('entity_id');
     if ($collection->count()) {
         return $collection->getFirstItem();
     } else {
         return false;
     }
 }
Beispiel #11
0
 /**
  * Customer validate before save
  *
  * @param Mage_Customer_Model_Customer $model
  * @return void
  */
 public function customerSaveBefore($model)
 {
     if ($model->getId() && !$this->_role->hasWebsiteAccess($model->getWebsiteId(), true)) {
         $this->_throwSave();
     } elseif (!$model->getId() && !$this->_role->getIsWebsiteLevel()) {
         $this->_throwSave();
     }
 }
 /**
  * Send email with new release information.
  *
  * @param Mage_Customer_Model_Customer $customer
  * 		Customer to send the mail to
  * @param Faett_Package_Model_Link_Purchased $linkPurchased
  * 		The data about when the product has been purchased
  * @param Faett_Package_Model_Link $link
  * 		Data previously created link
  * @return Faett_Package_Model_Mysql4_Link
  * 		The instance
  */
 protected function _sendNewReleaseEmail(Mage_Customer_Model_Customer $customer, Faett_Package_Model_Link_Purchased $linkPurchased, Faett_Package_Model_Link $link)
 {
     try {
         // load the translation model
         $translate = Mage::getSingleton('core/translate');
         $translate->setTranslateInline(false);
         // initialize the store ID necessary for the translation
         $storeId = $customer->getStoreId();
         if ($customer->getWebsiteId() != '0' && $storeId == '0') {
             $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
             reset($storeIds);
             $storeId = current($storeIds);
         }
         // load the email template, generate and send the mail
         Mage::getModel('core/email_template')->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))->sendTransactional(Mage::getStoreConfig(Faett_Channel_Model_Service::XML_PATH_EMAILS_RELEASE_NEW), Mage::getStoreConfig(Mage_Customer_Model_Customer::XML_PATH_REGISTER_EMAIL_IDENTITY), $customer->getEmail(), $customer->getName(), array('customer' => $customer, 'linkPurchased' => $linkPurchased, 'link' => $link));
         // close the translation model
         $translate->setTranslateInline(true);
     } catch (Exception $e) {
         Mage::logException($e);
     }
     // return the instance itself
     return $this;
 }