Skip to content

Commit

Permalink
fixed the wishlist customer_id issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Tomaraei committed Dec 16, 2021
1 parent 00e0c63 commit 084543d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/catalog/controller/vsbridge/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,19 +690,19 @@ public function orderHistory(){
}

/*
* GET /vsbridge/user/getWishlistItems
* Get the user wishlist items from server side
*
* GET PARAMS:
* token - user token returned from POST /vsbridge/user/getWishlistItems
*/
* GET /vsbridge/user/getWishlistItems
* Get the user wishlist items from server side
*
* GET PARAMS:
* token - user token returned from POST /vsbridge/user/getWishlistItems
*/

public function getWishlistItems(){
$token = $this->getParam('token');
$this->validateCustomerToken($token);
$customer_info = $this->validateCustomerToken($token);

$this->load->model('account/wishlist');
$this->result = $this->model_account_wishlist->getWishlist();
$this->load->model('vsbridge/api');
$this->result = $this->model_vsbridge_api->getWishlist($customer_info['customer_id']);

$this->sendResponse();
}
Expand All @@ -717,10 +717,10 @@ public function getWishlistItems(){

public function addWishlistItem(){
$token = $this->getParam('token');
$this->validateCustomerToken($token);
$customer_info = $this->validateCustomerToken($token);

$input = $this->getPost();
if(empty($input['product_id']) || !is_numeric($input['product_id'])) {
if(empty($input['product_id']) || !(is_numeric($input['product_id']) || is_array($input['product_id']))) {
$this->error[] = $this->language->get('error_product_id');
}

Expand All @@ -730,10 +730,16 @@ public function addWishlistItem(){
$this->sendResponse();
}

$this->load->model('account/wishlist');
$this->model_account_wishlist->addWishlist($input['product_id']);
$this->result = $this->model_account_wishlist->getWishlist();

$this->load->model('vsbridge/api');
if (is_array($input['product_id'])) {
foreach($input['product_id'] as $product_id) {
$this->model_vsbridge_api->addWishlist($product_id, $customer_info['customer_id']);
}
} else {
$this->model_vsbridge_api->addWishlist($input['product_id'], $customer_info['customer_id']);
}
$this->result = $this->model_vsbridge_api->getWishlist($customer_info['customer_id']);

$this->sendResponse();
}

Expand All @@ -747,10 +753,10 @@ public function addWishlistItem(){

public function deleteWishlistItem(){
$token = $this->getParam('token');
$this->validateCustomerToken($token);
$customer_info = $this->validateCustomerToken($token);

$input = $this->getPost();
if(empty($input['product_id']) || !is_numeric($input['product_id'])) {
if(empty($input['product_id']) || !(is_numeric($input['product_id']) || is_array($input['product_id']))) {
$this->error[] = $this->language->get('error_product_id');
}

Expand All @@ -760,9 +766,15 @@ public function deleteWishlistItem(){
$this->sendResponse();
}

$this->load->model('account/wishlist');
$this->model_account_wishlist->deleteWishlist($input['product_id']);
$this->result = $this->model_account_wishlist->getWishlist();
$this->load->model('vsbridge/api');
if (is_array($input['product_id'])) {
foreach($input['product_id'] as $product_id) {
$this->model_vsbridge_api->deleteWishlist($product_id, $customer_info['customer_id']);
}
} else {
$this->model_vsbridge_api->deleteWishlist($input['product_id'], $customer_info['customer_id']);
}
$this->result = $this->model_vsbridge_api->getWishlist($customer_info['customer_id']);

$this->sendResponse();
}
Expand Down
21 changes: 21 additions & 0 deletions src/catalog/model/vsbridge/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,25 @@ public function getLengthClass($length_class_id, $language_id) {

return $query->rows;
}
public function addWishlist($product_id, $customer_id) {
$this->db->query("DELETE FROM " . DB_PREFIX . "customer_wishlist WHERE customer_id = '" . (int)$customer_id . "' AND product_id = '" . (int)$product_id . "'");

$this->db->query("INSERT INTO " . DB_PREFIX . "customer_wishlist SET customer_id = '" . (int)$customer_id . "', product_id = '" . (int)$product_id . "', date_added = NOW()");
}

public function deleteWishlist($product_id, $customer_id) {
$this->db->query("DELETE FROM " . DB_PREFIX . "customer_wishlist WHERE customer_id = '" . (int)$customer_id . "' AND product_id = '" . (int)$product_id . "'");
}

public function getWishlist($customer_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_wishlist WHERE customer_id = '" . (int)$customer_id . "'");

return $query->rows;
}

public function getTotalWishlist($customer_id) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_wishlist WHERE customer_id = '" . (int)$customer_id . "'");

return $query->row['total'];
}
}

0 comments on commit 084543d

Please sign in to comment.