Webocreation

Tuesday, April 19, 2011

Collection of customer function and its description in Opencart




customer:
login($email, $password):
Check whether the customer is approved and check whether the username and password is correct or not.
public function login($email, $password) {
if (!$this->config->get('config_customer_approval')) {
$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(strtolower($email)) . "' AND password = '" . $this->db->escape(md5($password)) . "' AND status = '1'");
} else {
$customer_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE LOWER(email) = '" . $this->db->escape(strtolower($email)) . "' AND password = '" . $this->db->escape(md5($password)) . "' AND status = '1' AND approved = '1'");
}

if ($customer_query->num_rows) {
$this->session->data['customer_id'] = $customer_query->row['customer_id'];

if (($customer_query->row['cart']) && (is_string($customer_query->row['cart']))) {
$cart = unserialize($customer_query->row['cart']);

foreach ($cart as $key => $value) {
if (!array_key_exists($key, $this->session->data['cart'])) {
$this->session->data['cart'][$key] = $value;
} else {
$this->session->data['cart'][$key] += $value;
}
}
}

$this->customer_id = $customer_query->row['customer_id'];
$this->firstname = $customer_query->row['firstname'];
$this->lastname = $customer_query->row['lastname'];
$this->email = $customer_query->row['email'];
$this->telephone = $customer_query->row['telephone'];
$this->fax = $customer_query->row['fax'];
$this->newsletter = $customer_query->row['newsletter'];
$this->customer_group_id = $customer_query->row['customer_group_id'];
$this->address_id = $customer_query->row['address_id'];

return TRUE;
} else {
return FALSE;
}
}

logout():
Destroy all the session of the logged customer.
public function logout() {
unset($this->session->data['customer_id']);

$this->customer_id = '';
$this->firstname = '';
$this->lastname = '';
$this->email = '';
$this->telephone = '';
$this->fax = '';
$this->newsletter = '';
$this->customer_group_id = '';
$this->address_id = '';

session_destroy();
}
isLogged():
Check whether the customer is logged in or not.
public function isLogged() {
return $this->customer_id;
}
getId(), getFirstName(), getLastName(), getEmail(), getTelephone(), getFax(), getNewsletter(), getCustomerGroupId(), getAddressId():
Returns the customer information like for ID we have to write $this->customer->getId().
public function getId() {
return $this->customer_id;
}

public function getFirstName() {
return $this->firstname;
}

public function getLastName() {
return $this->lastname;
}

public function getEmail() {
return $this->email;
}

public function getTelephone() {
return $this->telephone;
}

public function getFax() {
return $this->fax;
}

public function getNewsletter() {
return $this->newsletter;
}

public function getCustomerGroupId() {
return $this->customer_group_id;
}

public function getAddressId() {
return $this->address_id;
}

get the customer description with the use of class function

No comments:

Post a Comment