Block.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCartBlocks\Blocks\Dashboard\CustomerShippingAddress; |
| 4 | |
| 5 | use SureCartBlocks\Blocks\Dashboard\DashboardPage; |
| 6 | |
| 7 | /** |
| 8 | * Checkout block |
| 9 | */ |
| 10 | class Block extends DashboardPage { |
| 11 | /** |
| 12 | * Render the block |
| 13 | * |
| 14 | * @param array $attributes Block attributes. |
| 15 | * @param string $content Post content. |
| 16 | * |
| 17 | * @return function |
| 18 | */ |
| 19 | public function render( $attributes, $content ) { |
| 20 | // get the current page tab and possible id. |
| 21 | $id = sanitize_text_field( $_GET['order']['id'] ?? null ); |
| 22 | $page = sanitize_text_field( $_GET['order']['page'] ?? 1 ); |
| 23 | |
| 24 | return $id ? $this->show( $id ) : $this->index( $page ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Show and individual checkout session. |
| 29 | * |
| 30 | * @param string $id Session ID. |
| 31 | * |
| 32 | * @return function |
| 33 | */ |
| 34 | public function show( $id ) { |
| 35 | return \SureCart::blocks()->render( |
| 36 | 'web/dashboard/shipping_address/show', |
| 37 | [ |
| 38 | 'customer_id' => $this->customer_id, |
| 39 | ] |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Show and individual checkout session. |
| 45 | * |
| 46 | * @param array $page Current page. |
| 47 | * |
| 48 | * @return function |
| 49 | */ |
| 50 | public function index( $page ) { |
| 51 | if ( empty( $this->customer_id ) ) { |
| 52 | return; |
| 53 | } |
| 54 | return \SureCart::blocks()->render( |
| 55 | 'web/dashboard/orders/index', |
| 56 | [ |
| 57 | 'query' => [ |
| 58 | 'customer_ids' => [ $this->customer_id ], |
| 59 | 'status' => [ 'paid' ], |
| 60 | 'page' => 1, |
| 61 | 'per_page' => 10, |
| 62 | ], |
| 63 | ] |
| 64 | ); |
| 65 | } |
| 66 | } |
| 67 |