PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.1.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.1.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / classes / subscriptions.php

subscriptions.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.1.0, at includes/classes/subscriptions.php

99 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Classes;
4
5 use StoreEngine\Addons\Subscription\Classes\Subscription;
6
7 /**
8 * @deprecated
9 */
10 class Subscriptions extends Orders {
11
12 /**
13 * @param $conditions
14 *
15 * @return array
16 * @throws Exceptions\StoreEngineException
17 *
18 * @deprecated
19 */
20 public function get( $conditions = [] ): array {
21 global $wpdb;
22
23 $conditions = array_merge( [
24 'status' => [
25 'condition' => '!=',
26 'formatter' => '%s',
27 'value' => 'draft',
28 ],
29 'type' => [
30 'condition' => '=',
31 'formatter' => '%s',
32 'value' => 'subscription',
33 ],
34 ], $conditions);
35
36 $offset = ( $this->page - 1 ) * $this->limit;
37
38 // @TODO cache (must be same as Abstract Entity (order object format) to reduce multiple query.
39
40 $sql_conditions = $this->generate_conditions( $conditions );
41 $results = $wpdb->get_results($wpdb->prepare("{$this->query()} WHERE {$sql_conditions} GROUP BY o.id ORDER BY o.id DESC LIMIT %d OFFSET %d;", $this->limit, $offset), ARRAY_A); // phpcs:ignore
42
43 if ( ! $results ) {
44 return [];
45 }
46
47 $orders = [];
48
49 foreach ( $results as $result ) {
50 if ( ! empty( $result['o_id'] ) ) {
51 $order = new Subscription( $result['o_id'] );
52 $orders[] = $order;
53 }
54 }
55
56 return $orders;
57 }
58
59 /**
60 * @param $conditions
61 *
62 * @return int
63 *
64 * @deprecated
65 */
66 public function get_total_orders_count( $conditions = [] ) {
67 global $wpdb;
68
69 $conditions = array_merge( [
70 'status' => [
71 'condition' => '!=',
72 'formatter' => '%s',
73 'value' => 'draft',
74 ],
75 'type' => [
76 'condition' => '=',
77 'formatter' => '%s',
78 'value' => 'subscription',
79 ],
80 ], $conditions);
81
82 $sql_conditions = $this->generate_conditions( $conditions );
83
84 // phpcs:disable PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- query prepared above.
85 $result = $wpdb->get_row("SELECT COUNT(DISTINCT o.id) as order_totals FROM {$wpdb->prefix}storeengine_orders o
86 LEFT JOIN {$wpdb->prefix}storeengine_order_addresses b ON b.order_id = o.id AND b.address_type = 'billing'
87 LEFT JOIN {$wpdb->prefix}storeengine_order_addresses s ON s.order_id = o.id AND s.address_type = 'shipping'
88 LEFT JOIN {$wpdb->prefix}storeengine_order_operational_data p ON p.order_id = o.id
89 LEFT JOIN {$wpdb->prefix}storeengine_orders_meta m ON m.order_id = o.id WHERE $sql_conditions;");
90 // phpcs:enable PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
91
92 if ( ! $result ) {
93 return 0;
94 }
95
96 return $result->order_totals;
97 }
98 }
99