Skip to content
Permalink
Browse files

removed restore cart and wishlist from customer class as you don't wa…

…nt your cart restored on each login.
  • Loading branch information...
danielkerr committed Jun 24, 2015
1 parent dfbf918 commit 0db2555371228c887a83bd271b4542cacc22603f
@@ -472,6 +472,7 @@ public function getForm() {
$data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
// API Login
$this->load->model('user/api');
$api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
@@ -1191,6 +1192,19 @@ public function info() {
$data['order_status_id'] = $order_info['order_status_id'];
// API Login
$this->load->model('user/api');
$api_info = $this->model_user_api->getApi($this->config->get('config_api_id'));
if ($api_info) {
$data['username'] = $api_info['username'];
$data['password'] = $api_info['password'];
} else {
$data['username'] = '';
$data['password'] = '';
}
$data['payment_action'] = $this->load->controller('payment/' . $order_info['payment_code'] . '/action');
$data['frauds'] = array();
@@ -133,5 +133,4 @@
// Error
$_['error_warning'] = 'Warning: Please check the form carefully for errors!';
$_['error_permission'] = 'Warning: You do not have permission to modify orders!';
$_['error_curl'] = 'Warning: CURL error %s(%s)!';
$_['error_action'] = 'Warning: Could not complete this action!';
@@ -961,8 +961,6 @@ $.ajax({
dataType: 'json',
crossDomain: true,
success: function(json) {
console.log(json);
if (json['cookie']) {
$('input[name=\'cookie\']').val(json['cookie']);
@@ -10,6 +10,7 @@ public function index() {
$this->customer->logout();
$this->cart->clear();
unset($this->session->data['order_id']);
unset($this->session->data['wishlist']);
unset($this->session->data['payment_address']);
unset($this->session->data['payment_method']);
@@ -18,7 +19,6 @@ public function index() {
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['comment']);
unset($this->session->data['order_id']);
unset($this->session->data['coupon']);
unset($this->session->data['reward']);
unset($this->session->data['voucher']);
@@ -26,6 +26,11 @@ public function index() {
$this->session->data['success'] = $this->language->get('text_remove');
// Edit customers cart
$this->load->model('account/customer');
$this->model_account_customer->editWishlist($this->session->data['wishlist']);
$this->response->redirect($this->url->link('account/wishlist'));
}
@@ -157,14 +162,17 @@ public function add() {
if ($product_info) {
if (!in_array($this->request->post['product_id'], $this->session->data['wishlist'])) {
$this->session->data['wishlist'][] = (int)$this->request->post['product_id'];
if ($this->customer->isLogged()) {
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
} else {
$json['info'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
}
}
if ($this->customer->isLogged()) {
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
// Edit customers cart
$this->load->model('account/customer');
$this->model_account_customer->editWishlist($this->session->data['wishlist']);
} else {
$json['info'] = sprintf($this->language->get('text_exists'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
$json['success'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'), $this->url->link('product/product', 'product_id=' . (int)$this->request->post['product_id']), $product_info['name'], $this->url->link('account/wishlist'));
}
$json['total'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
@@ -173,4 +181,4 @@ public function add() {
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
}
@@ -336,7 +336,13 @@ public function add() {
$this->cart->add($this->request->post['product_id'], $quantity, $option, $recurring_id);
$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));
// Edit customers cart
$this->load->model('account/customer');
$this->model_account_customer->editCart($this->cart->getCart());
// Unset all shipping and payment methods
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
@@ -399,6 +405,11 @@ public function edit() {
$this->cart->update($key, $value);
}
// Edit customers cart
$this->load->model('account/customer');
$this->model_account_customer->editCart($this->cart->getCart());
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
@@ -425,6 +436,11 @@ public function remove() {
$this->session->data['success'] = $this->language->get('text_remove');
// Edit customers cart
$this->load->model('account/customer');
$this->model_account_customer->editCart($this->cart->getCart());
unset($this->session->data['shipping_method']);
unset($this->session->data['shipping_methods']);
unset($this->session->data['payment_method']);
@@ -80,8 +80,32 @@ public function save() {
}
if (!$json) {
// Trigger customer pre login event
$this->event->trigger('pre.customer.login');
// Unset guest
unset($this->session->data['guest']);
// Restore customers cart
if ($this->customer->getCart()) {
foreach ($this->customer->getCart() as $key => $value) {
$this->cart->add($key, $value);
}
}
// Restore customers wish list
if ($this->customer->getWishlist()) {
if (!isset($this->session->data['wishlist'])) {
$this->session->data['wishlist'] = array();
}
foreach ($this->customer->getWishlist() as $product_id) {
if (!in_array($product_id, $this->session->data['wishlist'])) {
$this->session->data['wishlist'][] = $product_id;
}
}
}
$this->load->model('account/address');
if ($this->config->get('config_tax_customer') == 'payment') {
@@ -103,6 +127,9 @@ public function save() {
);
$this->model_account_activity->addActivity('login', $activity_data);
// Trigger customer post login event
$this->event->trigger('post.customer.login');
}
$this->response->addHeader('Content-Type: application/json');
@@ -115,7 +115,7 @@ public function editPassword($email, $password) {
$this->event->trigger('post.customer.edit.password');
}
public function editNewsletter($newsletter) {
$this->event->trigger('pre.customer.edit.newsletter');
@@ -124,6 +124,22 @@ public function editNewsletter($newsletter) {
$this->event->trigger('post.customer.edit.newsletter');
}
public function editCart($cart) {
$this->event->trigger('pre.customer.edit.cart');
$this->db->query("UPDATE " . DB_PREFIX . "customer SET cart = '" . $this->db->escape(serialize($cart)) . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
$this->event->trigger('post.customer.edit.cart');
}
public function editWishlist($wishlist) {
$this->event->trigger('pre.customer.edit.wishlist');
$this->db->query("UPDATE " . DB_PREFIX . "customer SET wishlist = '" . $this->db->escape(serialize($wishlist)) . "' WHERE customer_id = '" . (int)$this->customer->getId() . "'");
$this->event->trigger('post.customer.edit.wishlist');
}
public function getCustomer($customer_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
@@ -270,6 +270,10 @@ public function getProducts() {
return $this->data;
}
public function getCart() {
return $this->session->data['cart'];
}
public function getRecurringProducts() {
$recurring_products = array();
@@ -3,12 +3,14 @@ class Customer {
private $customer_id;
private $firstname;
private $lastname;
private $customer_group_id;
private $email;
private $telephone;
private $fax;
private $newsletter;
private $customer_group_id;
private $address_id;
private $cart;
private $wishlist;
public function __construct($registry) {
$this->config = $registry->get('config');
@@ -23,14 +25,16 @@ public function __construct($registry) {
$this->customer_id = $customer_query->row['customer_id'];
$this->firstname = $customer_query->row['firstname'];
$this->lastname = $customer_query->row['lastname'];
$this->customer_group_id = $customer_query->row['customer_group_id'];
$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'];
$this->cart = unserialize($customer_query->row['cart']);
$this->wishlist = unserialize($customer_query->row['cart']);
$this->db->query("UPDATE " . DB_PREFIX . "customer SET cart = '" . $this->db->escape(isset($this->session->data['cart']) ? serialize($this->session->data['cart']) : '') . "', wishlist = '" . $this->db->escape(isset($this->session->data['wishlist']) ? serialize($this->session->data['wishlist']) : '') . "', ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
$this->db->query("UPDATE " . DB_PREFIX . "customer SET ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
$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']) . "'");
@@ -53,41 +57,17 @@ public function login($email, $password, $override = false) {
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;
}
}
}
if ($customer_query->row['wishlist'] && is_string($customer_query->row['wishlist'])) {
if (!isset($this->session->data['wishlist'])) {
$this->session->data['wishlist'] = array();
}
$wishlist = unserialize($customer_query->row['wishlist']);
foreach ($wishlist as $product_id) {
if (!in_array($product_id, $this->session->data['wishlist'])) {
$this->session->data['wishlist'][] = $product_id;
}
}
}
$this->customer_id = $customer_query->row['customer_id'];
$this->firstname = $customer_query->row['firstname'];
$this->lastname = $customer_query->row['lastname'];
$this->customer_group_id = $customer_query->row['customer_group_id'];
$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'];
$this->cart = unserialize($customer_query->row['cart']);
$this->wishlist = unserialize($customer_query->row['wishlist']);
$this->db->query("UPDATE " . DB_PREFIX . "customer SET ip = '" . $this->db->escape($this->request->server['REMOTE_ADDR']) . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
@@ -98,19 +78,19 @@ public function login($email, $password, $override = false) {
}
public function logout() {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET cart = '" . $this->db->escape(isset($this->session->data['cart']) ? serialize($this->session->data['cart']) : '') . "', wishlist = '" . $this->db->escape(isset($this->session->data['wishlist']) ? serialize($this->session->data['wishlist']) : '') . "' WHERE customer_id = '" . (int)$this->customer_id . "'");
unset($this->session->data['customer_id']);
$this->customer_id = '';
$this->firstname = '';
$this->lastname = '';
$this->customer_group_id = '';
$this->email = '';
$this->telephone = '';
$this->fax = '';
$this->newsletter = '';
$this->customer_group_id = '';
$this->address_id = '';
$this->cart = array();
$this->wishlist = array();
}
public function isLogged() {
@@ -129,6 +109,10 @@ public function getLastName() {
return $this->lastname;
}
public function getGroupId() {
return $this->customer_group_id;
}
public function getEmail() {
return $this->email;
}
@@ -145,14 +129,18 @@ public function getNewsletter() {
return $this->newsletter;
}
public function getGroupId() {
return $this->customer_group_id;
}
public function getAddressId() {
return $this->address_id;
}
public function getCart() {
return $this->cart;
}
public function getWishlist() {
return $this->wishlist;
}
public function getBalance() {
$query = $this->db->query("SELECT SUM(amount) AS total FROM " . DB_PREFIX . "customer_transaction WHERE customer_id = '" . (int)$this->customer_id . "'");

1 comment on commit 0db2555

@Ototoo

This comment has been minimized.

Copy link

Ototoo commented on 0db2555 Nov 13, 2015

Hi, if i update all script in opencast version 2.0.3.1 will work all fine?

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.