PluginProbe
Tutor LMS – eLearning and online course solution / 3.7.2
Tutor LMS – eLearning and online course solution v3.7.2
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
← All changes | models/CartModel.php +16 -43 trunk3.7.2 View file →
@@ -9,9 +9,8 @@
9 9 */
10 10
11 11 namespace Tutor\Models;
12 12
13 -use Tutor\Cache\TutorCache;
14 13 use Tutor\Helpers\QueryHelper;
15 14
16 15 /**
17 16 * Cart model class for performing cart functionalities
@@ -38,18 +37,14 @@
38 37
39 38 /**
40 39 * Add a course to the user's cart.
41 40 *
42 - * @since 3.8.0 $item_type & $items_details Param added
41 + * @param int $user_id User ID.
42 + * @param int $course_id Course ID.
43 43 *
44 - * @param int $user_id User ID.
45 - * @param int $course_id Course ID.
46 - * @param string $item_type Cart item type.
47 - * @param mixed $item_details Cart item details.
48 - *
49 - * @return int Inserted row ID on success, 0 otherwise.
44 + * @return array Array containing the result of the insert operation.
50 45 */
51 - public function add_course_to_cart( $user_id, $course_id, $item_type = '', $item_details = '' ) {
46 + public function add_course_to_cart( $user_id, $course_id ) {
52 47 global $wpdb;
53 48
54 49 $current_time = current_time( 'mysql', true );
55 50 $user_cart_id = 0;
@@ -73,21 +68,13 @@
73 68 )
74 69 );
75 70 }
76 71
77 - if ( 'gift' === $item_type ) {
78 - $item_details = wp_json_encode( $item_details, JSON_UNESCAPED_UNICODE );
79 - } else {
80 - $item_details = wp_json_encode( $item_details );
81 - }
82 -
83 72 return QueryHelper::insert(
84 73 "{$wpdb->prefix}tutor_cart_items",
85 74 array(
86 - 'cart_id' => $user_cart_id,
87 - 'course_id' => $course_id,
88 - 'item_type' => $item_type,
89 - 'item_details' => $item_details,
75 + 'cart_id' => $user_cart_id,
76 + 'course_id' => $course_id,
90 77 )
91 78 );
92 79 }
93 80
@@ -93,23 +80,15 @@
93 80
94 81 /**
95 82 * Get items from the user's cart.
96 83 *
97 - * @since 3.8.0 $is_details param added.
84 + * @param int $user_id User ID.
98 85 *
99 - * @param int $user_id User ID.
100 - * @param bool $is_details If false then just cart items will be returned.
101 - *
102 86 * @return array Array containing the cart items and their total count.
103 87 */
104 - public function get_cart_items( $user_id, $is_details = true ) {
105 - $cache_key = "tutor_get_cart_items_{$user_id}_{$is_details}";
106 - $cached = TutorCache::get( $cache_key );
88 + public function get_cart_items( $user_id ) {
89 + global $wpdb;
107 90
108 - if ( $cached ) {
109 - return $cached;
110 - }
111 -
112 91 $cart_data = array(
113 92 'cart' => null,
114 93 'courses' => array(
115 94 'total_count' => 0,
@@ -117,9 +96,9 @@
117 96 ),
118 97 );
119 98
120 99 $user_cart = QueryHelper::get_row(
121 - 'tutor_carts',
100 + "{$wpdb->prefix}tutor_carts",
122 101 array(
123 102 'user_id' => $user_id,
124 103 ),
125 104 'id'
@@ -127,20 +106,17 @@
127 106
128 107 if ( $user_cart ) {
129 108 $cart_data['cart'] = $user_cart;
130 109
131 - $primary_table = 'tutor_cart_items AS item';
110 + $primary_table = "{$wpdb->prefix}tutor_cart_items AS item";
132 111 $joining_tables = array(
133 112 array(
134 113 'type' => 'LEFT',
135 - 'table' => 'posts AS post',
114 + 'table' => "{$wpdb->prefix}posts AS post",
136 115 'on' => 'item.course_id = post.ID',
137 116 ),
138 117 );
139 - $where = array(
140 - 'item.cart_id' => $user_cart->id,
141 - 'post.post_status' => 'publish',
142 - );
118 + $where = array( 'item.cart_id' => $user_cart->id );
143 119 $select_columns = array( 'post.*' );
144 120 $cart_data['courses'] = QueryHelper::get_joined_data(
145 121 $primary_table,
146 122 $joining_tables,
@@ -146,17 +122,13 @@
146 122 $joining_tables,
147 123 $select_columns,
148 124 $where,
149 125 array(),
150 - 'item.id',
151 - -1
126 + 'item.id'
152 127 );
153 128 }
154 129
155 - $result = $is_details ? $cart_data : $cart_data['courses']['results'];
156 - TutorCache::set( $cache_key, $result );
157 -
158 - return $result;
130 + return $cart_data;
159 131 }
160 132
161 133 /**
162 134 * Check if the user has any items in their cart.
@@ -279,5 +251,6 @@
279 251 'user_id' => $user_id,
280 252 )
281 253 );
282 254 }
255 +
283 256 }