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