| 1 |
<?php |
| 2 |
namespace SureCartBlocks\Controllers; |
| 3 |
|
| 4 |
use SureCart\Models\Component; |
| 5 |
use SureCart\Models\User; |
| 6 |
|
| 7 |
/** |
| 8 |
* The subscription controller. |
| 9 |
*/ |
| 10 |
class OrderController extends BaseController { |
| 11 |
/** |
| 12 |
* Preview. |
| 13 |
*/ |
| 14 |
public function preview( $attributes = [] ) { |
| 15 |
if ( ! is_user_logged_in() ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
return wp_kses_post( |
| 20 |
Component::tag( 'sc-orders-list' ) |
| 21 |
->id( 'customer-orders-preview' ) |
| 22 |
->with( |
| 23 |
[ |
| 24 |
'allLink' => add_query_arg( |
| 25 |
[ |
| 26 |
'tab' => $this->getTab(), |
| 27 |
'model' => 'order', |
| 28 |
'action' => 'index', |
| 29 |
] |
| 30 |
), |
| 31 |
'isCustomer' => User::current()->isCustomer(), |
| 32 |
'query' => apply_filters( |
| 33 |
'surecart/dashboard/order_list/query', |
| 34 |
[ |
| 35 |
'customer_ids' => array_values( User::current()->customerIds() ), |
| 36 |
'status' => [ 'paid', 'processing', 'payment_failed', 'canceled', 'void' ], |
| 37 |
'page' => 1, |
| 38 |
'per_page' => 5, |
| 39 |
] |
| 40 |
), |
| 41 |
] |
| 42 |
)->render( $attributes['title'] ? "<span slot='heading'>" . $attributes['title'] . '</span>' : '' ) |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Index. |
| 48 |
*/ |
| 49 |
public function index() { |
| 50 |
if ( ! is_user_logged_in() ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
ob_start(); |
| 54 |
?> |
| 55 |
|
| 56 |
<sc-spacing style="--spacing: var(--sc-spacing-large)"> |
| 57 |
<sc-breadcrumbs> |
| 58 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 59 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 60 |
</sc-breadcrumb> |
| 61 |
<sc-breadcrumb> |
| 62 |
<?php esc_html_e( 'Orders', 'surecart' ); ?> |
| 63 |
</sc-breadcrumb> |
| 64 |
</sc-breadcrumbs> |
| 65 |
|
| 66 |
<?php |
| 67 |
echo wp_kses_post( |
| 68 |
Component::tag( 'sc-orders-list' ) |
| 69 |
->id( 'customer-orders-index' ) |
| 70 |
->with( |
| 71 |
[ |
| 72 |
'heading' => __( 'Order History', 'surecart' ), |
| 73 |
'isCustomer' => User::current()->isCustomer(), |
| 74 |
'query' => apply_filters( |
| 75 |
'surecart/dashboard/order_list/query', |
| 76 |
[ |
| 77 |
'customer_ids' => array_values( User::current()->customerIds() ), |
| 78 |
'status' => [ 'paid', 'processing', 'payment_failed', 'canceled', 'void' ], |
| 79 |
'page' => 1, |
| 80 |
'per_page' => 10, |
| 81 |
] |
| 82 |
), |
| 83 |
] |
| 84 |
)->render() |
| 85 |
); |
| 86 |
?> |
| 87 |
</sc-spacing> |
| 88 |
|
| 89 |
<?php |
| 90 |
return ob_get_clean(); |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Index. |
| 95 |
*/ |
| 96 |
public function show() { |
| 97 |
if ( ! is_user_logged_in() ) { |
| 98 |
return; |
| 99 |
} |
| 100 |
ob_start(); |
| 101 |
?> |
| 102 |
|
| 103 |
<sc-spacing style="--spacing: var(--sc-spacing-large)"> |
| 104 |
<sc-breadcrumbs> |
| 105 |
|
| 106 |
<sc-breadcrumb href="<?php echo esc_url( add_query_arg( [ 'tab' => $this->getTab() ], remove_query_arg( array_keys( $_GET ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>"> |
| 107 |
<?php esc_html_e( 'Dashboard', 'surecart' ); ?> |
| 108 |
</sc-breadcrumb> |
| 109 |
<sc-breadcrumb href=" |
| 110 |
<?php |
| 111 |
echo esc_url( |
| 112 |
add_query_arg( |
| 113 |
[ |
| 114 |
'tab' => $this->getTab(), |
| 115 |
'model' => 'order', |
| 116 |
'action' => 'index', |
| 117 |
], |
| 118 |
remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 119 |
) |
| 120 |
); |
| 121 |
?> |
| 122 |
"> |
| 123 |
<?php esc_html_e( 'Orders', 'surecart' ); ?> |
| 124 |
</sc-breadcrumb> |
| 125 |
<sc-breadcrumb> |
| 126 |
<?php esc_html_e( 'Order', 'surecart' ); ?> |
| 127 |
</sc-breadcrumb> |
| 128 |
</sc-breadcrumbs> |
| 129 |
|
| 130 |
<div> |
| 131 |
<?php |
| 132 |
echo wp_kses_post( |
| 133 |
Component::tag( 'sc-order' ) |
| 134 |
->id( 'sc-customer-order' ) |
| 135 |
->with( |
| 136 |
[ |
| 137 |
'orderId' => $this->getId(), |
| 138 |
'customerIds' => array_values( (array) User::current()->customerIds() ), |
| 139 |
] |
| 140 |
)->render() |
| 141 |
); |
| 142 |
?> |
| 143 |
</div> |
| 144 |
|
| 145 |
<div> |
| 146 |
<?php |
| 147 |
echo wp_kses_post( |
| 148 |
Component::tag( 'sc-fulfillments' ) |
| 149 |
->id( 'sc-customer-fulfillments' ) |
| 150 |
->with( |
| 151 |
[ |
| 152 |
'orderId' => $this->getId(), |
| 153 |
] |
| 154 |
)->render() |
| 155 |
); |
| 156 |
?> |
| 157 |
</div> |
| 158 |
</sc-spacing> |
| 159 |
|
| 160 |
<?php |
| 161 |
return ob_get_clean(); |
| 162 |
} |
| 163 |
} |
| 164 |
|