/**
  * @param string $login
  * @param waAuth $auth
  * @return waContact|bool
  */
 protected function findContact($login, $auth)
 {
     $contact_model = new waContactModel();
     $is_user = $auth->getOption('is_user');
     if (strpos($login, '@')) {
         $sql = "SELECT c.* FROM wa_contact c\n            JOIN wa_contact_emails e ON c.id = e.contact_id\n            WHERE " . ($is_user ? "c.is_user = 1 AND " : "") . "e.email LIKE s:email AND e.sort = 0\n            ORDER BY c.id LIMIT 1";
         $contact_info = $contact_model->query($sql, array('email' => $login))->fetch();
     } else {
         $contact_info = $contact_model->getByField('login', $login);
     }
     if ($contact_info && (!$is_user || $contact_info['is_user'])) {
         $contact = new waContact($contact_info['id']);
         $contact->setCache($contact_info);
         return $contact;
     }
     return false;
 }
 private function _include_tracker()
 {
     if (!($api_key = self::_get_app_key())) {
         return false;
     }
     include_once 'vendors/ConveadTracker.php';
     $auth = new waAuth();
     if (isset($_REQUEST['customer_id'])) {
         // create purchase from admin panel without customer
         $guest_uid = $_REQUEST['customer_id'] == 0 ? uniqid() : false;
         $uid = $_REQUEST['customer_id'] == 0 ? false : $_REQUEST['customer_id'];
     } else {
         $guest_uid = waRequest::cookie('convead_guest_uid');
         $uid = ($auth_info = $auth->isAuth()) ? $auth_info['id'] : false;
     }
     $tracker = new ConveadTracker($api_key, waRequest::server('SERVER_NAME'), $guest_uid, $uid, isset($this->visitor_info) ? $this->visitor_info : false);
     return $tracker;
 }