1: | <?php
|
2: | namespace Opencart\Catalog\Model\Account;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Wishlist extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: |
|
17: | public function addWishlist(int $customer_id, int $product_id): void {
|
18: | $this->db->query("DELETE FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$customer_id . "' AND `product_id` = '" . (int)$product_id . "'");
|
19: |
|
20: | $this->db->query("INSERT INTO `" . DB_PREFIX . "customer_wishlist` SET `customer_id` = '" . (int)$customer_id . "', `product_id` = '" . (int)$product_id . "', `date_added` = NOW()");
|
21: | }
|
22: |
|
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: |
|
31: | public function deleteWishlist(int $customer_id, int $product_id = 0): void {
|
32: | $sql = "DELETE FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$customer_id . "'";
|
33: |
|
34: | if ($product_id) {
|
35: | $sql .= " AND `product_id` = '" . (int)$product_id . "'";
|
36: | }
|
37: |
|
38: | $this->db->query($sql);
|
39: | }
|
40: |
|
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: |
|
48: | public function getWishlist(int $customer_id): array {
|
49: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
50: |
|
51: | return $query->rows;
|
52: | }
|
53: |
|
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: |
|
61: | public function getTotalWishlist(int $customer_id): int {
|
62: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
63: |
|
64: | return (int)$query->row['total'];
|
65: | }
|
66: | }
|
67: | |