shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

customer.php (4912B)


      1 <?php
      2 namespace Cart;
      3 class Customer {
      4 	private $customer_id;
      5 	private $firstname;
      6 	private $lastname;
      7 	private $customer_group_id;
      8 	private $email;
      9 	private $telephone;
     10 	private $newsletter;
     11 	private $address_id;
     12 
     13 	public function __construct($registry) {
     14 		$this->config = $registry->get('config');
     15 		$this->db = $registry->get('db');
     16 		$this->request = $registry->get('request');
     17 		$this->session = $registry->get('session');
     18 
     19 		if (isset($this->session->data['customer_id'])) {
     20 			$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$this->session->data['customer_id'] . "' AND status = '1'");
     21 
     22 			if ($customer_query->num_rows) {
     23 				$this->customer_id = $customer_query->row['customer_id'];
     24 				$this->firstname = $customer_query->row['firstname'];
     25 				$this->lastname = $customer_query->row['lastname'];
     26 				$this->customer_group_id = $customer_query->row['customer_group_id'];
     27 				$this->email = $customer_query->row['email'];
     28 				$this->telephone = $customer_query->row['telephone'];
     29 				$this->newsletter = $customer_query->row['newsletter'];
     30 				$this->address_id = $customer_query->row['address_id'];
     31 
     32 				$this->db->query("UPDATE " . DB_PREFIX . "customer SET language_id = '" . (int)$this->config->get('config_language_id') . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
     33 
     34 				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_ip WHERE customer_id = '" . (int)$this->session->data['customer_id'] . "' AND ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "'");
     35 
     36 				if (!$query->num_rows) {
     37 					$this->db->query("INSERT INTO " . DB_PREFIX . "customer_ip SET customer_id = '" . (int)$this->session->data['customer_id'] . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "', date_added = NOW()");
     38 				}
     39 			} else {
     40 				$this->logout();
     41 			}
     42 		}
     43 	}
     44 
     45   public function login($email, $password, $override = false) {
     46 		if ($override) {
     47 			$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND status = '1'");
     48 		} else {
     49 			$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this->db->escape($password) . "'))))) OR password = '" . $this->db->escape(md5($password)) . "') AND status = '1'");
     50 		}
     51 
     52 		if ($customer_query->num_rows) {
     53 			$this->session->data['customer_id'] = $customer_query->row['customer_id'];
     54 
     55 			$this->customer_id = $customer_query->row['customer_id'];
     56 			$this->firstname = $customer_query->row['firstname'];
     57 			$this->lastname = $customer_query->row['lastname'];
     58 			$this->customer_group_id = $customer_query->row['customer_group_id'];
     59 			$this->email = $customer_query->row['email'];
     60 			$this->telephone = $customer_query->row['telephone'];
     61 			$this->newsletter = $customer_query->row['newsletter'];
     62 			$this->address_id = $customer_query->row['address_id'];
     63 		
     64 			$this->db->query("UPDATE " . DB_PREFIX . "customer SET language_id = '" . (int)$this->config->get('config_language_id') . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
     65 
     66 			return true;
     67 		} else {
     68 			return false;
     69 		}
     70 	}
     71 
     72 	public function logout() {
     73 		unset($this->session->data['customer_id']);
     74 
     75 		$this->customer_id = '';
     76 		$this->firstname = '';
     77 		$this->lastname = '';
     78 		$this->customer_group_id = '';
     79 		$this->email = '';
     80 		$this->telephone = '';
     81 		$this->newsletter = '';
     82 		$this->address_id = '';
     83 	}
     84 
     85 	public function isLogged() {
     86 		return $this->customer_id;
     87 	}
     88 
     89 	public function getId() {
     90 		return $this->customer_id;
     91 	}
     92 
     93 	public function getFirstName() {
     94 		return $this->firstname;
     95 	}
     96 
     97 	public function getLastName() {
     98 		return $this->lastname;
     99 	}
    100 
    101 	public function getGroupId() {
    102 		return $this->customer_group_id;
    103 	}
    104 
    105 	public function getEmail() {
    106 		return $this->email;
    107 	}
    108 
    109 	public function getTelephone() {
    110 		return $this->telephone;
    111 	}
    112 
    113 	public function getNewsletter() {
    114 		return $this->newsletter;
    115 	}
    116 
    117 	public function getAddressId() {
    118 		return $this->address_id;
    119 	}
    120 
    121 	public function getBalance() {
    122 		$query = $this->db->query("SELECT SUM(amount) AS total FROM " . DB_PREFIX . "customer_transaction WHERE customer_id = '" . (int)$this->customer_id . "'");
    123 
    124 		return $query->row['total'];
    125 	}
    126 
    127 	public function getRewardPoints() {
    128 		$query = $this->db->query("SELECT SUM(points) AS total FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$this->customer_id . "'");
    129 
    130 		return $query->row['total'];
    131 	}
    132 }