Scripts
3 years ago
SubscriptionScriptsController.php
3 years ago
SubscriptionsController.php
1 year ago
SubscriptionsListTable.php
1 month ago
SubscriptionsController.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Admin\Subscriptions; |
| 4 | |
| 5 | use SureCart\Controllers\Admin\AdminController; |
| 6 | use SureCart\Controllers\Admin\Subscriptions\SubscriptionsListTable; |
| 7 | use SureCart\Controllers\Admin\Subscriptions\Scripts\EditScriptsController; |
| 8 | use SureCart\Controllers\Admin\Subscriptions\Scripts\ShowScriptsController; |
| 9 | |
| 10 | /** |
| 11 | * Handles product admin requests. |
| 12 | */ |
| 13 | class SubscriptionsController extends AdminController { |
| 14 | /** |
| 15 | * Orders index. |
| 16 | */ |
| 17 | public function index() { |
| 18 | $table = new SubscriptionsListTable(); |
| 19 | $table->prepare_items(); |
| 20 | $this->withHeader( |
| 21 | array( |
| 22 | 'breadcrumbs' => [ |
| 23 | 'subscriptions' => [ |
| 24 | 'title' => __( 'Subscriptions', 'surecart' ), |
| 25 | ], |
| 26 | ], |
| 27 | 'report_url' => SURECART_REPORTS_URL . 'subscriptions', |
| 28 | ) |
| 29 | ); |
| 30 | return \SureCart::view( 'admin/subscriptions/index' )->with( |
| 31 | [ |
| 32 | 'table' => $table, |
| 33 | ] |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Edit |
| 39 | * |
| 40 | * @return string |
| 41 | */ |
| 42 | public function edit( $request ) { |
| 43 | // enqueue needed script. |
| 44 | add_action( 'admin_enqueue_scripts', \SureCart::closure()->method( EditScriptsController::class, 'enqueue' ) ); |
| 45 | |
| 46 | $this->preloadPaths( |
| 47 | [ |
| 48 | '/wp/v2/users/me', |
| 49 | '/wp/v2/types?context=view', |
| 50 | '/wp/v2/types?context=edit', |
| 51 | '/surecart/v1/subscriptions/' . $request->query( 'id' ) . '?context=edit&expand%5B0%5D=current_period&expand%5B1%5D=current_period.checkout&expand%5B2%5D=discount', |
| 52 | ] |
| 53 | ); |
| 54 | |
| 55 | // return view. |
| 56 | return '<div id="app"></div>'; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Show |
| 61 | * |
| 62 | * @return string |
| 63 | */ |
| 64 | public function show( $request ) { |
| 65 | // enqueue needed script. |
| 66 | add_action( 'admin_enqueue_scripts', \SureCart::closure()->method( ShowScriptsController::class, 'enqueue' ) ); |
| 67 | |
| 68 | $this->preloadPaths( |
| 69 | [ |
| 70 | '/wp/v2/users/me', |
| 71 | '/wp/v2/types?context=view', |
| 72 | '/wp/v2/types?context=edit', |
| 73 | '/surecart/v1/subscriptions?context=edit&ids[0]=' . $request->query( 'id' ) . '&expand[0]=current_period&expand[1]=period.checkout&expand[2]=checkout.line_items&expand[3]=line_item.price&expand[4]=line_item.fees&expand[5]=price&expand[6]=price.product&expand[7]=customer&expand[8]=customer.balances&expand[9]=purchase&expand[10]=discount&expand[11]=discount.coupon&expand[12]=order&expand[13]=current_cancellation_act&expand[14]=payment_method&expand[15]=payment_method.card&expand[16]=payment_method.payment_instrument&expand[17]=payment_method.paypal_account&expand[18]=payment_method.bank_account', |
| 74 | ] |
| 75 | ); |
| 76 | |
| 77 | // return view. |
| 78 | return '<div id="app"></div>'; |
| 79 | } |
| 80 | } |
| 81 |