64 lines
2.5 KiB
PHP
64 lines
2.5 KiB
PHP
|
|
<?php
|
||
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
||
|
|
global $MIRAVIAWOO;
|
||
|
|
|
||
|
|
if(isset($_GET['account'])) {
|
||
|
|
|
||
|
|
$link = new MiraviaLink(sanitize_text_field($_GET['token']));
|
||
|
|
$orders = $link->getOrders('2022-09-01');
|
||
|
|
$miraviaTable = new MiraviaTable();
|
||
|
|
// die('<pre>'.print_r($orders,true).'</pre>');
|
||
|
|
$data = array();
|
||
|
|
$miraviaTable->custom_actions = array(
|
||
|
|
'download' => sprintf('<a href="javascript:void(0);" class="download_order" data-account="'.sanitize_text_field($_GET['account_id']).'" data-token="'.sanitize_text_field($_GET['token']).'" data-id="[id]">Download</a>', sanitize_text_field($_REQUEST['page']), sanitize_text_field($_REQUEST['subpage']), 'download', ),
|
||
|
|
);
|
||
|
|
|
||
|
|
$miraviaTable->columns = [
|
||
|
|
'id' => "Order Number",
|
||
|
|
'name' => 'Customer Name',
|
||
|
|
'price' => "Price",
|
||
|
|
'statuses' => "Status",
|
||
|
|
'created_at' => 'Created',
|
||
|
|
'updated_at' => 'Updated',
|
||
|
|
];
|
||
|
|
foreach($orders['data']['orders'] as $k => $p) {
|
||
|
|
$data[] = array(
|
||
|
|
'id' => $p['order_number'],
|
||
|
|
'name' => $p['customer_first_name'],
|
||
|
|
'price' => number_format($p['price'], 2) . '€',
|
||
|
|
'statuses' => $p['statuses'][0],
|
||
|
|
'created_at' => date('d-m-Y H:i', strtotime($p['created_at'])),
|
||
|
|
'updated_at' => date('d-m-Y H:i', strtotime($p['updated_at'])),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
// die('<pre>' . print_r($data, true) . '</pre>');
|
||
|
|
$miraviaTable->data_table = $data;
|
||
|
|
$miraviaTable->total_elements = $orders['data']['count'];
|
||
|
|
|
||
|
|
|
||
|
|
$miraviaTable->prepare_items();
|
||
|
|
}else{
|
||
|
|
$accounts = MiraviaCore::get_accounts();
|
||
|
|
|
||
|
|
$html_accounts = "";
|
||
|
|
if(count($accounts) == 1) {
|
||
|
|
wp_safe_redirect( "?page=miravia_settings&subpage=orders&account={$accounts[0]['name']}&token={$accounts[0]['token']}&account_id={$accounts[0]['id']}", 301);
|
||
|
|
die();
|
||
|
|
}
|
||
|
|
foreach($accounts as $a) {
|
||
|
|
$html_accounts .= "<a href='?page=miravia_settings&subpage=orders&account={$a['name']}&token={$a['token']}&account_id={$a['id']}'>{$a['name']} ({$a['email']})</a>";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
?>
|
||
|
|
<div class="wrap">
|
||
|
|
<h2>Miravia Orders</h2>
|
||
|
|
<?php if(!isset($_GET['account'])) {
|
||
|
|
echo wp_kses('<p>'.__('Select an account', 'miravia').'</p>', array('p' => array()));
|
||
|
|
echo wp_kses($html_accounts, array('a' => array()));
|
||
|
|
}else{
|
||
|
|
echo wp_kses('<p>'.__('Orders by account', 'miravia').' '.sanitize_text_field($_GET['account']).'</p>', array('p' => array()));
|
||
|
|
$miraviaTable->display();
|
||
|
|
} ?>
|
||
|
|
</div>
|