CouponScriptsController.php
3 years ago
CouponsController.php
2 years ago
CouponsListTable.php
3 years ago
CouponsController.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Admin\Coupons; |
| 4 | |
| 5 | use SureCart\Controllers\Admin\AdminController; |
| 6 | use SureCart\Controllers\Admin\Coupons\CouponsListTable; |
| 7 | |
| 8 | /** |
| 9 | * Handles product admin requests. |
| 10 | */ |
| 11 | class CouponsController extends AdminController { |
| 12 | |
| 13 | /** |
| 14 | * Coupons index. |
| 15 | */ |
| 16 | public function index() { |
| 17 | $table = new CouponsListTable(); |
| 18 | $table->prepare_items(); |
| 19 | |
| 20 | $this->withHeader( |
| 21 | [ |
| 22 | 'coupons' => [ |
| 23 | 'title' => __( 'Coupons', 'surecart' ), |
| 24 | ], |
| 25 | ] |
| 26 | ); |
| 27 | |
| 28 | return \SureCart::view( 'admin/coupons/index' )->with( |
| 29 | [ |
| 30 | 'table' => $table, |
| 31 | ] |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Coupons edit. |
| 37 | */ |
| 38 | public function edit( $request ) { |
| 39 | // admin edit page. |
| 40 | do_action( 'surecart/admin/coupons/edit' ); |
| 41 | // enqueue needed script. |
| 42 | add_action( 'admin_enqueue_scripts', \SureCart::closure()->method( CouponScriptsController::class, 'enqueue' ) ); |
| 43 | |
| 44 | $this->preloadPaths( |
| 45 | [ |
| 46 | '/wp/v2/users/me', |
| 47 | '/wp/v2/types?context=view', |
| 48 | '/wp/v2/types?context=edit', |
| 49 | '/surecart/v1/coupons/' . $request->query( 'id' ) . '?context=edit', |
| 50 | ] |
| 51 | ); |
| 52 | |
| 53 | // return view. |
| 54 | return '<div id="app"></div>'; |
| 55 | } |
| 56 | } |
| 57 |