PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.3
4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 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 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Controllers / Admin / Abandoned / AbandonedCheckoutListTable.php
surecart / app / src / Controllers / Admin / Abandoned Last commit date
AbandonedCheckoutListTable.php 1 year ago AbandonedCheckoutScriptsController.php 3 years ago AbandonedCheckoutViewController.php 1 year ago
AbandonedCheckoutListTable.php
308 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\Abandoned;
4
5 use SureCart\Controllers\Admin\Tables\ListTable;
6 use SureCart\Models\AbandonedCheckout;
7 use SureCart\Controllers\Admin\Tables\HasModeFilter;
8
9 /**
10 * Create a new table class that will extend the WP_List_Table
11 */
12 class AbandonedCheckoutListTable extends ListTable {
13 use HasModeFilter;
14
15 /**
16 * Prepare the items for the table to process
17 *
18 * @return Void
19 */
20 public function prepare_items() {
21 $columns = $this->get_columns();
22 $hidden = $this->get_hidden_columns();
23 $sortable = $this->get_sortable_columns();
24
25 $this->_column_headers = array( $columns, $hidden, $sortable );
26
27 $query = $this->table_data();
28 if ( is_wp_error( $query ) ) {
29 $this->items = [];
30 return;
31 }
32
33 $this->set_pagination_args(
34 [
35 'total_items' => $query->pagination->count,
36 'per_page' => $this->get_items_per_page( 'abandoned_checkout' ),
37 ]
38 );
39
40 $this->items = $query->data;
41 }
42
43 protected function get_views() {
44 $stati = [
45 'all' => __( 'All', 'surecart' ),
46 'scheduled' => __( 'Scheduled', 'surecart' ),
47 'sent' => __( 'Sent', 'surecart' ),
48 'not_scheduled' => __( 'Not Scheduled', 'surecart' ),
49 ];
50
51 foreach ( $stati as $status => $label ) {
52 $link = \SureCart::getUrl()->index( 'abandoned-checkout' );
53
54 $current_link_attributes = '';
55
56 if ( ! empty( $_GET['status'] ) ) {
57 if ( sanitize_text_field( wp_unslash( $_GET['status'] ) ) === $status ) {
58 $current_link_attributes = ' class="current" aria-current="page"';
59 }
60 } elseif ( 'all' === $status ) {
61 $current_link_attributes = ' class="current" aria-current="page"';
62 }
63
64 $link = add_query_arg( 'status', $status, $link );
65
66 $link = esc_url( $link );
67
68 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
69 }
70
71 /**
72 * Filters the comment status links.
73 *
74 * @since 2.5.0
75 * @since 5.1.0 The 'Mine' link was added.
76 *
77 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
78 * 'Pending', 'Approved', 'Spam', and 'Trash'.
79 */
80 return apply_filters( 'abandoned_order_status_links', $status_links );
81 }
82
83 public function search() {
84 ?>
85 <form class="search-form"
86 method="get">
87 <?php $this->search_box( __( 'Search Abanonded Orders', 'surecart' ), 'abandoned_order' ); ?>
88 <input type="hidden"
89 name="id"
90 value="1" />
91 </form>
92 <?php
93 }
94
95 /**
96 * Override the parent columns method. Defines the columns to use in your listing table
97 *
98 * @return Array
99 */
100 public function get_columns() {
101 return [
102 'placed_by' => __( 'Placed By', 'surecart' ),
103 'date' => __( 'Date', 'surecart' ),
104 'notification_status' => __( 'Email Status', 'surecart' ),
105 'recovery_status' => __( 'Recovery Status', 'surecart' ),
106 'total' => __( 'Total', 'surecart' ),
107 'mode' => '',
108 ];
109 }
110
111 /**
112 * Get the table data
113 *
114 * @return Array
115 */
116 protected function table_data() {
117 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) );
118 $status = $this->getStatus();
119 $where = array();
120
121 if ( ! empty( $mode ) ) {
122 $where['live_mode'] = 'live' === $mode;
123 }
124
125 if ( $status ) {
126 $where['notification_status'] = [ $status ];
127 }
128
129 return AbandonedCheckout::where( $where )
130 ->with( [ 'recovered_checkout', 'checkout', 'customer' ] )
131 ->paginate(
132 [
133 'per_page' => $this->get_items_per_page( 'abandoned-checkouts' ),
134 'page' => $this->get_pagenum(),
135 'expand' => [ 'checkout' ],
136 ]
137 );
138 }
139
140 /**
141 * Get the archive query status.
142 *
143 * @return boolean|null
144 */
145 public function getStatus() {
146 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) );
147 if ( 'all' === $status ) {
148 return null;
149 }
150 return $status ? [ esc_html( $status ) ] : [];
151 }
152
153 /**
154 * Handle the total column
155 *
156 * @param \SureCart\Models\AbandonedCheckout $checkout Checkout Session Model.
157 *
158 * @return string
159 */
160 public function column_total( $abandoned ) {
161 return '<sc-format-number type="currency" currency="' . strtoupper( esc_html( $abandoned->checkout->currency ?? 'usd' ) ) . '" value="' . (float) $abandoned->checkout->total_amount . '"></sc-format-number>';
162 }
163
164 /**
165 * Handle the total column
166 *
167 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout model.
168 *
169 * @return string
170 */
171 public function column_date( $abandoned ) {
172 return isset( $abandoned->created_at ) ? '<sc-format-date date="' . (int) $abandoned->created_at . '" type="timestamp" month="short" day="numeric" year="numeric" hour="numeric" minute="numeric"></sc-format-date>' : '--';
173 }
174
175 /**
176 * Handle the notification status
177 *
178 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout session.
179 *
180 * @return string
181 */
182 public function column_notification_status( $abandoned ) {
183 if ( $abandoned->recovered_checkout ) {
184 return '--';
185 }
186
187 switch ( $abandoned->notification_status ?? '' ) {
188 case 'scheduled':
189 return '<sc-tag type="info">' . __( 'Scheduled', 'surecart' ) . '</sc-tag>';
190 case 'not_scheduled':
191 return '<sc-tag type="warning">' . __( 'Not Scheduled', 'surecart' ) . '</sc-tag>';
192 case 'sent':
193 return '<sc-tag type="success">' . __( 'Email Sent', 'surecart' ) . '</sc-tag>';
194 }
195 return '<sc-tag>' . esc_html( $abandoned->notification_status ?? 'Unknown' ) . '</sc-tag>';
196 }
197
198 /**
199 * Handle the recovery status
200 *
201 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout session.
202 *
203 * @return string
204 */
205 public function column_recovery_status( $abandoned ) {
206 switch ( $abandoned->recovery_status ) {
207 case 'abandoned':
208 return '<sc-tag type="warning">' . __( 'Abandoned', 'surecart' ) . '</sc-tag>';
209 case 'assisted_recovered':
210 return '<sc-tag type="success">' . __( 'Recovered', 'surecart' ) . '</sc-tag>';
211 case 'unassisted_recovered':
212 return '<sc-tag type="info">' . __( 'Recovered Before Email Was Sent', 'surecart' ) . '</sc-tag>';
213 }
214 return '<sc-tag type="success">' . $abandoned->recovery_status . '</sc-tag>';
215 }
216
217 /**
218 * Handle the mode column
219 *
220 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout model.
221 *
222 * @return string
223 */
224 public function column_mode( $abandoned ) {
225 return empty( $abandoned->checkout->live_mode ) ? '<sc-tag type="warning">' . __( 'Test', 'surecart' ) . '</sc-tag>' : '';
226 }
227
228 /**
229 * Email of customer
230 *
231 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout model.
232 *
233 * @return string
234 */
235 public function column_placed_by( $abandoned ) {
236 ob_start();
237 ?>
238 <a class="row-title" aria-label="<?php esc_attr_e( 'Edit Order', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'abandoned-checkout', $abandoned->id ) ); ?>">
239 <?php
240 // translators: Customer name.
241 echo sprintf( esc_html__( 'By %s', 'surecart' ), esc_html( $abandoned->customer->name ?? $abandoned->customer->email ) );
242 ?>
243 </a>
244 <br />
245 <a aria-label="<?php esc_attr_e( 'View Checkout', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'abandoned-checkout', $abandoned->id ) ); ?>">
246 <?php esc_attr_e( 'View Checkout', 'surecart' ); ?>
247 </a>
248 <?php
249
250 return ob_get_clean();
251 }
252
253 /**
254 * Displays extra table navigation.
255 *
256 * @param string $which Top or bottom placement.
257 */
258 protected function extra_tablenav( $which ) {
259 ?>
260 <input type="hidden" name="page" value="sc-abandoned-checkouts" />
261
262 <div class="alignleft actions">
263 <?php
264 if ( 'top' === $which ) {
265 ob_start();
266 $this->mode_dropdown();
267
268 /**
269 * Fires before the Filter button on the Posts and Pages list tables.
270 *
271 * The Filter button allows sorting by date and/or category on the
272 * Posts list table, and sorting by date on the Pages list table.
273 *
274 * @since 2.1.0
275 * @since 4.4.0 The `$post_type` parameter was added.
276 * @since 4.6.0 The `$which` parameter was added.
277 *
278 * @param string $post_type The post type slug.
279 * @param string $which The location of the extra table nav markup:
280 * 'top' or 'bottom' for WP_Posts_List_Table,
281 * 'bar' for WP_Media_List_Table.
282 */
283 do_action( 'restrict_manage_abandoned_checkouts', $this->screen->post_type, $which );
284
285 $output = ob_get_clean();
286
287 if ( ! empty( $output ) ) {
288 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
289 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) );
290 }
291 }
292
293 ?>
294 </div>
295
296 <?php
297 /**
298 * Fires immediately following the closing "actions" div in the tablenav for the posts
299 * list table.
300 *
301 * @since 4.4.0
302 *
303 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
304 */
305 do_action( 'manage_abandoned_checkouts_extra_tablenav', $which );
306 }
307 }
308