PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.0
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 / AutoFees / AutoFeesListTable.php
surecart / app / src / Controllers / Admin / AutoFees Last commit date
AutoFeesController.php 5 months ago AutoFeesListTable.php 1 week ago AutoFeesScriptsController.php 5 months ago
AutoFeesListTable.php
369 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\AutoFees;
4
5 use SureCart\Controllers\Admin\Tables\ListTable;
6 use SureCart\Models\AutoFee;
7
8 /**
9 * Create a new table class that will extend the WP_List_Table
10 */
11 class AutoFeesListTable extends ListTable {
12 /**
13 * Prepare the items for the table to process
14 *
15 * @return Void
16 */
17 public function prepare_items() {
18 $columns = $this->get_columns();
19 $hidden = $this->get_hidden_columns();
20
21 $this->_column_headers = array( $columns, $hidden );
22
23 $query = $this->table_data();
24
25 if ( is_wp_error( $query ) ) {
26 $this->items = [];
27 return;
28 }
29
30 $this->set_pagination_args(
31 [
32 'total_items' => $query->pagination->count,
33 'per_page' => $this->get_items_per_page( 'auto-fees' ),
34 ]
35 );
36
37 $this->items = $query->data;
38 }
39
40 /**
41 * Search form for the table.
42 *
43 * @return void
44 */
45 public function search() {
46 ?>
47 <form class="search-form"
48 method="get">
49 <?php $this->search_box( __( 'Search Dynamic Prices', 'surecart' ), 'order' ); ?>
50 <input type="hidden"
51 name="id"
52 value="1" />
53 </form>
54 <?php
55 }
56
57 /**
58 * Get the views for the list table.
59 *
60 * @return array
61 */
62 protected function get_views() {
63 $stati = [
64 'all' => __( 'All', 'surecart' ),
65 'active' => __( 'Active', 'surecart' ),
66 'inactive' => __( 'Inactive', 'surecart' ),
67 ];
68
69 foreach ( $stati as $status => $label ) {
70 $link = esc_url_raw( \SureCart::getUrl()->index( 'auto-fees' ) );
71 $current_link_attributes = '';
72
73 if ( ! empty( $_GET['status'] ) ) {
74 if ( $status === sanitize_text_field( wp_unslash( $_GET['status'] ) ) ) {
75 $current_link_attributes = ' class="current" aria-current="page"';
76 }
77 } elseif ( 'all' === $status ) {
78 $current_link_attributes = ' class="current" aria-current="page"';
79 }
80
81 $link = add_query_arg( 'status', $status, $link );
82
83 $link = esc_url( $link );
84
85 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
86 }
87
88 /**
89 * Filters the comment status links.
90 *
91 * @since 2.5.0
92 * @since 5.1.0 The 'Mine' link was added.
93 *
94 * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
95 * 'Pending', 'Approved', 'Spam', and 'Trash'.
96 */
97 return apply_filters( 'surecart/auto_fees/index/links', $status_links );
98 }
99
100 /**
101 * Override the parent columns method. Defines the columns to use in your listing table
102 *
103 * @return array
104 */
105 public function get_columns() {
106 return array_merge(
107 [
108 'internal_name' => __( 'Name', 'surecart' ),
109 'name' => __( 'Display Name', 'surecart' ),
110 'status' => __( 'Status', 'surecart' ),
111 'type' => __( 'Type', 'surecart' ),
112 'date' => __( 'Date', 'surecart' ),
113 ],
114 parent::get_columns()
115 );
116 }
117
118 /**
119 * Define which columns are hidden
120 *
121 * @return array
122 */
123 public function get_hidden_columns() {
124 return array();
125 }
126
127 /**
128 * Get the table data
129 *
130 * @return \SureCart\Models\AutoFee[]|\WP_Error
131 */
132 protected function table_data() {
133 $conditions = [
134 'query' => $this->get_search_query(),
135 ];
136
137 if ( 'active' === $this->getStatus() ) {
138 $conditions['enabled'] = true;
139 }
140
141 if ( 'inactive' === $this->getStatus() ) {
142 $conditions['enabled'] = false;
143 }
144
145 return AutoFee::where( $conditions )
146 ->paginate(
147 [
148 'per_page' => $this->get_items_per_page( 'auto-fees' ),
149 'page' => $this->get_pagenum(),
150 ]
151 );
152 }
153
154 /**
155 * Get the archive query status.
156 *
157 * @return bool|null
158 */
159 public function getStatus() {
160 return sanitize_text_field( wp_unslash( $_GET['status'] ?? false ) );
161 }
162
163 /**
164 * Handle the status
165 *
166 * @param \SureCart\Models\AutoFee $auto_fees Auto Fee model.
167 *
168 * @return void
169 */
170 public function column_status( $auto_fees ) {
171 $toggle_url = add_query_arg(
172 [
173 'action' => 'toggle_active',
174 'nonce' => wp_create_nonce( 'archive_dynamic_price' ),
175 'id' => $auto_fees->id,
176 'status' => 'all',
177 ],
178 \SureCart::getUrl()->index( 'auto-fees' )
179 );
180 ?>
181 <sc-switch checked="<?php echo esc_attr( $auto_fees->enabled ) ? 'true' : 'false'; ?>"
182 onClick="window.location.assign('<?php echo esc_url( $toggle_url ); ?>'); document.querySelector('#loading-<?php echo esc_attr( $auto_fees->id ); ?>').style.display = '';"></sc-switch>
183 <sc-block-ui id="loading-<?php echo esc_attr( $auto_fees->id ); ?>" spinner style="display: none;"></sc-block-ui>
184 <?php
185 }
186
187 /**
188 * Name
189 *
190 * @param \SureCart\Models\AutoFees $auto_fees AutoFees model.
191 *
192 * @return string
193 */
194 public function column_name( $auto_fees ) {
195 return esc_html( $auto_fees->name );
196 }
197
198 /**
199 * Internal name.
200 *
201 * @param \SureCart\Models\AutoFees $auto_fees AutoFees model.
202 *
203 * @return string
204 */
205 public function column_internal_name( $auto_fees ) {
206 ob_start();
207 ?>
208 <a href="<?php echo esc_url_raw( \SureCart::getUrl()->edit( 'auto-fee', $auto_fees->id ) ); ?>">
209 <?php echo esc_html( $auto_fees->metadata->internal_name ?? '' ); ?>
210 </a>
211 <?php echo wp_kses_post( $this->getRowActions( $auto_fees ) ); ?>
212
213 <?php
214 return ob_get_clean();
215 }
216
217 /**
218 * Handle the target.
219 *
220 * @param \SureCart\Models\AutoFees $auto_fees AutoFees model.
221 *
222 * @return string
223 */
224 public function column_type( $auto_fees ) {
225 $translations = [
226 'checkout' => [
227 'label' => __( 'Checkout', 'surecart' ),
228 'icon' => 'shopping-cart',
229 ],
230 'line_item' => [
231 'label' => __( 'Line Item', 'surecart' ),
232 'icon' => 'layout-list',
233 ],
234 'shipping' => [
235 'label' => __( 'Shipping', 'surecart' ),
236 'icon' => 'truck',
237 ],
238 ];
239
240 // Determine fee/discount type.
241 $is_discount = (bool) $auto_fees->discount;
242 $type_label = $is_discount ? __( 'Discount', 'surecart' ) : __( 'Fee', 'surecart' );
243 $type_tag_type = $is_discount ? 'success' : 'danger';
244 $type_icon_name = $is_discount ? 'arrow-down-right' : 'arrow-up-right';
245
246 // Get target information.
247 $target_data = $translations[ $auto_fees->fee_target ] ?? $translations['checkout'];
248 $target_label = $target_data['label'];
249 $target_icon = $target_data['icon'];
250
251 // Build the fee/discount tag.
252 $type_tag = sprintf(
253 '<sc-tag type="%s" pill><div style="display: flex; align-items: center; gap: 0.5em;"><sc-icon name="%s"></sc-icon>%s</div></sc-tag>',
254 esc_attr( $type_tag_type ),
255 esc_attr( $type_icon_name ),
256 esc_html( $type_label )
257 );
258
259 // Build the target tag.
260 $target_tag = sprintf(
261 '<sc-tag type="info" pill><div style="display: flex; align-items: center; gap: 0.5em;"><sc-icon name="%s"></sc-icon>%s</div></sc-tag>',
262 esc_attr( $target_icon ),
263 esc_html( $target_label )
264 );
265
266 // Build the translated sentence with flex container for vertical alignment.
267 return sprintf(
268 /* translators: %1$s: Fee or Discount tag HTML, %2$s: Target tag HTML (e.g., Checkout, Line Item, Shipping) */
269 '<sc-flex align-items="center" justify-content="flex-start" style="--sc-flex-column-gap: 0.35em; flex-wrap: wrap;">' . __( 'Apply a %1$s to %2$s', 'surecart' ) . '</sc-flex>',
270 $type_tag,
271 $target_tag
272 );
273 }
274
275 /**
276 * Get row actions.
277 *
278 * @param \SureCart\Models\AutoFee $auto_fees Auto Fee model.
279 *
280 * @return array
281 */
282 public function getRowActions( $auto_fees ) {
283 return $this->row_actions(
284 array_filter(
285 [
286 'edit' => '<a href="' . esc_url( \SureCart::getUrl()->edit( 'auto-fee', $auto_fees->id ) ) . '" aria-label="' . esc_attr( 'Edit Dynamic Pricing', 'surecart' ) . '">' . esc_html__( 'Edit', 'surecart' ) . '</a>',
287 'delete' => '<a href="' . esc_url( $this->get_action_url( $auto_fees->id, 'delete' ) ) . '">' . esc_html__( 'Delete', 'surecart' ) . '</a>',
288 ]
289 )
290 );
291 }
292
293 /**
294 * Displays extra table navigation.
295 *
296 * @param string $which Top or bottom placement.
297 */
298 protected function extra_tablenav( $which ) {
299 ?>
300 <input type="hidden" name="page" value="sc-auto-fees" />
301
302 <div class="alignleft actions">
303 <?php
304 if ( 'top' === $which ) {
305 ob_start();
306 $this->mode_dropdown();
307
308 /**
309 * Fires before the Filter button on the Auto fees list tables.
310 *
311 * The Filter button allows sorting by date and/or category on the
312 * auto fees list table, and sorting by date on the Pages list table.
313 *
314 * @since 2.1.0
315 * @since 4.4.0 The `$post_type` parameter was added.
316 * @since 4.6.0 The `$which` parameter was added.
317 *
318 * @param string $post_type The post type slug.
319 * @param string $which The location of the extra table nav markup:
320 * 'top' or 'bottom' for WP_Posts_List_Table,
321 * 'bar' for WP_Media_List_Table.
322 */
323 do_action( 'restrict_manage_auto_fees', $this->screen->post_type, $which );
324
325 $output = ob_get_clean();
326
327 if ( ! empty( $output ) ) {
328 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
329 submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-mode-submit' ) );
330 }
331 }
332
333 ?>
334 </div>
335
336 <?php
337 /**
338 * Fires immediately following the closing "actions" div in the tablenav for the auto fees
339 * list table.
340 *
341 * @since 4.4.0
342 *
343 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
344 */
345 do_action( 'manage_auto_fees_extra_tablenav', $which );
346 }
347
348 /**
349 * Get action url.
350 *
351 * @param int $id The id.
352 * @param string $action The action.
353 *
354 * @return string
355 */
356 public function get_action_url( $id, $action ) {
357 return esc_url(
358 add_query_arg(
359 [
360 'action' => $action,
361 'nonce' => wp_create_nonce( $action . '_auto_fee' ),
362 'id' => $id,
363 ],
364 esc_url_raw( \SureCart::getUrl()->index( 'auto-fees' ) )
365 )
366 );
367 }
368 }
369