PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / wishlist / Wishlist_DB.php

Wishlist_DB.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.78, at includes/wishlist/Wishlist_DB.php

147 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace King_Addons\Wishlist;
4
5 use wpdb;
6
7 if (!defined('ABSPATH')) {
8 exit;
9 }
10
11 /**
12 * Handles wishlist database schema creation and upgrades.
13 */
14 class Wishlist_DB
15 {
16 private const DB_VERSION = '1.1.0';
17
18 /**
19 * Get wishlist items table name with prefix.
20 *
21 * @return string Table name.
22 */
23 public static function get_items_table(): string
24 {
25 global $wpdb;
26
27 return $wpdb->prefix . 'ka_wishlist_items';
28 }
29
30 /**
31 * Get wishlists table name with prefix.
32 *
33 * @return string Table name.
34 */
35 public static function get_lists_table(): string
36 {
37 global $wpdb;
38
39 return $wpdb->prefix . 'ka_wishlists';
40 }
41
42 /**
43 * Get conversions table name with prefix.
44 *
45 * @return string Table name.
46 */
47 public static function get_conversions_table(): string
48 {
49 global $wpdb;
50
51 return $wpdb->prefix . 'ka_wishlist_conversions';
52 }
53
54 /**
55 * Create or update wishlist tables when needed.
56 *
57 * @return void
58 */
59 public static function maybe_create_tables(): void
60 {
61 $installed_version = get_option('king_addons_wishlist_db_version');
62 if ($installed_version === self::DB_VERSION) {
63 return;
64 }
65
66 self::create_tables();
67 update_option('king_addons_wishlist_db_version', self::DB_VERSION);
68 }
69
70 /**
71 * Run dbDelta for all wishlist tables.
72 *
73 * @return void
74 */
75 private static function create_tables(): void
76 {
77 global $wpdb;
78
79 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
80
81 $charset_collate = $wpdb->get_charset_collate();
82 $items_table = self::get_items_table();
83 $lists_table = self::get_lists_table();
84 $conversions_table = self::get_conversions_table();
85
86 $sql_items = "CREATE TABLE {$items_table} (
87 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
88 user_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
89 session_key VARCHAR(64) NOT NULL DEFAULT '',
90 wishlist_id VARCHAR(64) NOT NULL DEFAULT '',
91 product_id BIGINT UNSIGNED NOT NULL,
92 variation_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
93 qty INT UNSIGNED NOT NULL DEFAULT 1,
94 created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
95 updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
96 meta LONGTEXT NULL,
97 PRIMARY KEY (id),
98 KEY user_id (user_id),
99 KEY session_key (session_key),
100 KEY wishlist_id (wishlist_id),
101 KEY product_id (product_id),
102 KEY variation_id (variation_id),
103 KEY created_at (created_at),
104 UNIQUE KEY unique_item (wishlist_id, user_id, session_key, product_id, variation_id)
105 ) {$charset_collate};";
106
107 $sql_lists = "CREATE TABLE {$lists_table} (
108 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
109 user_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
110 session_key VARCHAR(64) NOT NULL DEFAULT '',
111 title VARCHAR(200) NOT NULL DEFAULT '',
112 slug VARCHAR(200) NOT NULL DEFAULT '',
113 visibility VARCHAR(20) NOT NULL DEFAULT 'private',
114 created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
115 updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
116 PRIMARY KEY (id),
117 KEY user_id (user_id),
118 KEY session_key (session_key),
119 KEY slug (slug)
120 ) {$charset_collate};";
121
122 $sql_conversions = "CREATE TABLE {$conversions_table} (
123 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
124 user_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
125 product_id BIGINT UNSIGNED NOT NULL,
126 variation_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
127 order_id BIGINT UNSIGNED NOT NULL,
128 order_item_qty INT UNSIGNED NOT NULL DEFAULT 1,
129 order_item_total DECIMAL(10,2) NOT NULL DEFAULT 0.00,
130 converted_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
131 PRIMARY KEY (id),
132 KEY user_id (user_id),
133 KEY product_id (product_id),
134 KEY order_id (order_id),
135 KEY converted_at (converted_at),
136 UNIQUE KEY unique_conversion (user_id, product_id, variation_id, order_id)
137 ) {$charset_collate};";
138
139 dbDelta($sql_items);
140 dbDelta($sql_lists);
141 dbDelta($sql_conversions);
142 }
143 }
144
145
146
147