1: <?php
2: namespace Opencart\Catalog\Model\Account;
3: /**
4: * Class Wishlist
5: *
6: * @package Opencart\Catalog\Model\Account
7: */
8: class Wishlist extends \Opencart\System\Engine\Model {
9: /**
10: * Add Wishlist
11: *
12: * @param int $customer_id
13: * @param int $product_id
14: *
15: * @return void
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: * Delete Wishlist
25: *
26: * @param int $customer_id
27: * @param int $product_id
28: *
29: * @return void
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: * Get Wishlist
43: *
44: * @param int $customer_id
45: *
46: * @return array<int, array<string, mixed>>
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: * Get Total Wishlist
56: *
57: * @param int $customer_id
58: *
59: * @return int
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: