PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.2
4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 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 3 months ago AbandonedCheckoutScriptsController.php 3 years ago AbandonedCheckoutViewController.php 1 year ago
AbandonedCheckoutListTable.php
300 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 array_merge(
102 [
103 'placed_by' => __( 'Placed By', 'surecart' ),
104 'created' => __( 'Date', 'surecart' ),
105 'notification_status' => __( 'Email Status', 'surecart' ),
106 'recovery_status' => __( 'Recovery Status', 'surecart' ),
107 'total' => __( 'Total', 'surecart' ),
108 'mode' => '',
109 ],
110 parent::get_columns()
111 );
112 }
113
114 /**
115 * Get the table data
116 *
117 * @return Array
118 */
119 protected function table_data() {
120 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) );
121 $status = $this->getStatus();
122 $where = array();
123
124 if ( ! empty( $mode ) ) {
125 $where['live_mode'] = 'live' === $mode;
126 }
127
128 if ( $status ) {
129 $where['notification_status'] = [ $status ];
130 }
131
132 return AbandonedCheckout::where( $where )
133 ->with( [ 'recovered_checkout', 'checkout', 'customer' ] )
134 ->paginate(
135 [
136 'per_page' => $this->get_items_per_page( 'abandoned-checkouts' ),
137 'page' => $this->get_pagenum(),
138 'expand' => [ 'checkout' ],
139 ]
140 );
141 }
142
143 /**
144 * Get the archive query status.
145 *
146 * @return boolean|null
147 */
148 public function getStatus() {
149 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) );
150 if ( 'all' === $status ) {
151 return null;
152 }
153 return $status ? [ esc_html( $status ) ] : [];
154 }
155
156 /**
157 * Handle the total column
158 *
159 * @param \SureCart\Models\AbandonedCheckout $checkout Checkout Session Model.
160 *
161 * @return string
162 */
163 public function column_total( $abandoned ) {
164 return $abandoned->checkout->total_display_amount;
165 }
166
167 /**
168 * Handle the notification status
169 *
170 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout session.
171 *
172 * @return string
173 */
174 public function column_notification_status( $abandoned ) {
175 if ( $abandoned->recovered_checkout ) {
176 return '--';
177 }
178
179 switch ( $abandoned->notification_status ?? '' ) {
180 case 'scheduled':
181 return '<sc-tag type="info">' . __( 'Scheduled', 'surecart' ) . '</sc-tag>';
182 case 'not_scheduled':
183 return '<sc-tag type="warning">' . __( 'Not Scheduled', 'surecart' ) . '</sc-tag>';
184 case 'sent':
185 return '<sc-tag type="success">' . __( 'Email Sent', 'surecart' ) . '</sc-tag>';
186 }
187 return '<sc-tag>' . esc_html( $abandoned->notification_status ?? 'Unknown' ) . '</sc-tag>';
188 }
189
190 /**
191 * Handle the recovery status
192 *
193 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout session.
194 *
195 * @return string
196 */
197 public function column_recovery_status( $abandoned ) {
198 switch ( $abandoned->recovery_status ) {
199 case 'abandoned':
200 return '<sc-tag type="warning">' . __( 'Abandoned', 'surecart' ) . '</sc-tag>';
201 case 'assisted_recovered':
202 return '<sc-tag type="success">' . __( 'Recovered', 'surecart' ) . '</sc-tag>';
203 case 'unassisted_recovered':
204 return '<sc-tag type="info">' . __( 'Recovered Before Email Was Sent', 'surecart' ) . '</sc-tag>';
205 }
206 return '<sc-tag type="success">' . esc_html( $abandoned->recovery_status ) . '</sc-tag>';
207 }
208
209 /**
210 * Handle the mode column
211 *
212 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout model.
213 *
214 * @return string
215 */
216 public function column_mode( $abandoned ) {
217 return empty( $abandoned->checkout->live_mode ) ? '<sc-tag type="warning">' . __( 'Test', 'surecart' ) . '</sc-tag>' : '';
218 }
219
220 /**
221 * Email of customer
222 *
223 * @param \SureCart\Models\AbandonedCheckout $abandoned Abandoned checkout model.
224 *
225 * @return string
226 */
227 public function column_placed_by( $abandoned ) {
228 ob_start();
229 ?>
230 <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 ) ); ?>">
231 <?php
232 // translators: Customer name.
233 printf( esc_html__( 'By %s', 'surecart' ), esc_html( $abandoned->customer->name ?? $abandoned->customer->email ) );
234 ?>
235 </a>
236 <br />
237 <a aria-label="<?php esc_attr_e( 'View Checkout', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'abandoned-checkout', $abandoned->id ) ); ?>">
238 <?php esc_attr_e( 'View Checkout', 'surecart' ); ?>
239 </a>
240 <?php
241
242 return ob_get_clean();
243 }
244
245 /**
246 * Displays extra table navigation.
247 *
248 * @param string $which Top or bottom placement.
249 */
250 protected function extra_tablenav( $which ) {
251 ?>
252 <input type="hidden" name="page" value="sc-abandoned-checkouts" />
253
254 <div class="alignleft actions">
255 <?php
256 if ( 'top' === $which ) {
257 ob_start();
258 $this->mode_dropdown();
259
260 /**
261 * Fires before the Filter button on the Posts and Pages list tables.
262 *
263 * The Filter button allows sorting by date and/or category on the
264 * Posts list table, and sorting by date on the Pages list table.
265 *
266 * @since 2.1.0
267 * @since 4.4.0 The `$post_type` parameter was added.
268 * @since 4.6.0 The `$which` parameter was added.
269 *
270 * @param string $post_type The post type slug.
271 * @param string $which The location of the extra table nav markup:
272 * 'top' or 'bottom' for WP_Posts_List_Table,
273 * 'bar' for WP_Media_List_Table.
274 */
275 do_action( 'restrict_manage_abandoned_checkouts', $this->screen->post_type, $which );
276
277 $output = ob_get_clean();
278
279 if ( ! empty( $output ) ) {
280 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
281 submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) );
282 }
283 }
284
285 ?>
286 </div>
287
288 <?php
289 /**
290 * Fires immediately following the closing "actions" div in the tablenav for the posts
291 * list table.
292 *
293 * @since 4.4.0
294 *
295 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
296 */
297 do_action( 'manage_abandoned_checkouts_extra_tablenav', $which );
298 }
299 }
300