Здравствуйте.
Таки попытался сделать функцию проигрывания звука в админке на главной странице при поступлении заказа.
Все работает, но только не могу корректно получить ид последнего заказа. на главной выводятся 5 последних заказов, и почему то опенкарт при таком коде выводит последний 5й ид заказа.
../public_html/admin/controller/extension/dashboard/recent.php
<?php
class ControllerExtensionDashboardRecent extends Controller {
private $error = array();
public function index() {
$this->load->language('extension/dashboard/recent');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/setting');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->model_setting_setting->editSetting('dashboard_recent', $this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->response->redirect($this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=dashboard', true));
}
$data['heading_title'] = $this->language->get('heading_title');
$data['text_edit'] = $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['entry_width'] = $this->language->get('entry_width');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_sort_order'] = $this->language->get('entry_sort_order');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_extension'),
'href' => $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=dashboard', true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('extension/dashboard/recent', 'token=' . $this->session->data['token'], true)
);
$data['action'] = $this->url->link('extension/dashboard/recent', 'token=' . $this->session->data['token'], true);
$data['cancel'] = $this->url->link('extension/extension', 'token=' . $this->session->data['token'] . '&type=dashboard', true);
if (isset($this->request->post['dashboard_recent_width'])) {
$data['dashboard_recent_width'] = $this->request->post['dashboard_recent_width'];
} else {
$data['dashboard_recent_width'] = $this->config->get('dashboard_recent_width');
}
$data['columns'] = array();
for ($i = 3; $i <= 12; $i++) {
$data['columns'][] = $i;
}
if (isset($this->request->post['dashboard_recent_status'])) {
$data['dashboard_recent_status'] = $this->request->post['dashboard_recent_status'];
} else {
$data['dashboard_recent_status'] = $this->config->get('dashboard_recent_status');
}
if (isset($this->request->post['dashboard_recent_sort_order'])) {
$data['dashboard_recent_sort_order'] = $this->request->post['dashboard_recent_sort_order'];
} else {
$data['dashboard_recent_sort_order'] = $this->config->get('dashboard_recent_sort_order');
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('extension/dashboard/recent_form', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/analytics/google_analytics')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
public function dashboard() {
$this->load->language('extension/dashboard/recent');
$data['heading_title'] = $this->language->get('heading_title');
$data['text_no_results'] = $this->language->get('text_no_results');
$data['column_order_id'] = $this->language->get('column_order_id');
$data['column_customer'] = $this->language->get('column_customer');
$data['column_status'] = $this->language->get('column_status');
$data['column_date_added'] = $this->language->get('column_date_added');
$data['column_total'] = $this->language->get('column_total');
$data['column_action'] = $this->language->get('column_action');
$data['button_view'] = $this->language->get('button_view');
$data['token'] = $this->session->data['token'];
// Last 5 Orders
$data['orders'] = array();
$filter_data = array(
'sort' => 'o.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => 5
);
$this->load->model('sale/order');
$results = $this->model_sale_order->getOrders($filter_data);
foreach ($results as $result) {
$data['orders'][] = array(
'order_id' => $result['order_id'],
'customer' => $result['customer'],
'status' => $result['order_status'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'view' => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'], true),
);
}
$data['zvuk1'] = $result['order_id'] + '5';
return $this->load->view('extension/dashboard/recent_info', $data);
}
}
Как видно из кода, добавил $data['zvuk1'] = $result['order_id'] + '5';
+5 сделал так как вместо 140 ида берет 135, и чтобы уровнять суммирую +5.
Код ../admin/view/template/extension/dashboard/recent_info.tpl
<script type="text/javascript">
function getCookie(startzvuk) {
var cookie = " " + document.cookie;
var search = " " + startzvuk + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
}
</script>
<script type="text/javascript">
function getCookie(panelzvuk) {
var cookie = " " + document.cookie;
var search = " " + panelzvuk + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
}
</script>
<script type="text/JavaScript">
$(document).ready(function (){
var startzvuk= getCookie("startzvuk");
if(startzvuk == 'on'){
var panelzvuk= getCookie("panelzvuk");
var date = new Date(new Date().getTime() + 5000 * 5000 * 5000);
var audio = new Audio('/image/catalog/samzvuk.mp3');
var zvukid= <?php echo $zvuk1; ?>;
var superyo = document.getElementById('superyo');
if(zvukid > panelzvuk){
audio.play();
document.cookie = "panelzvuk=<?php echo $zvuk1; ?>; path=/; expires=" + date.toUTCString();
superyo.classList.remove('nn');
} else {
setTimeout(function(){
location.reload();
},10000)
}
$('#timer_inp').removeClass('nn');
} else {
}
});
function zvukStart() {
var date = new Date(new Date().getTime() + 5000 * 5000 * 5000);
document.cookie = "startzvuk=on; path=/; expires=" + date.toUTCString();
document.cookie = "panelzvuk=<?php echo $zvuk1; ?>; path=/; expires=" + date.toUTCString();
location.reload();
};
function zvukStop() {
var date = new Date(new Date().getTime() + 5000 * 5000 * 5000);
document.cookie = "startzvuk=off; path=/; expires=" + date.toUTCString();
location.reload();
};
function hiddesuper() {
$('#superyo').addClass('nn');
};
</script>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-shopping-cart"></i> <?php echo $heading_title; ?></h3>
<a id="startzvuk" onclick="zvukStart()" style="cursor:pointer"><i class="fa fa-play-circle" aria-hidden="true"></i> Включить мониторинг</a>
<a id="stoptzvuk" onclick="zvukStop()" style="cursor:pointer"><i class="fa fa-minus-circle" aria-hidden="true"></i> Отключить мониторинг</a>
<script type="text/javascript">
function timer(){
var obj=document.getElementById('timer_inp');
obj.innerHTML--;
if(obj.innerHTML==0){setTimeout(function(){},1000);}
else{setTimeout(timer,1000);}
}
setTimeout(timer,1000);
</script>
<div id="timer_inp" class="nn">10</div>
<div id="superyo" class="nn" onclick="hiddesuper()">Хорошие новости! Вы получили один или несколько новых заказов.<br>Проверьте список заказов в разделе: Продажи > Заказы.</div>
<style>
#timer_inp {float: right;
background-color: #f56b6b;
color: white;
font-weight: 700;
font-size: 14px;
width: 20px;
height: 20px;
text-align: center;
border-radius: 50%;}
#superyo {position: fixed;
bottom: 5%;
left: 5%;
background-color: #f56b6b;
color: white;
padding: 20px;
z-index: 1000;
font-size: 20px;
font-weight: 100;}
.nn {display:none;}
</style>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<td class="text-right"><?php echo $column_order_id; ?></td>
<td><?php echo $column_customer; ?></td>
<td><?php echo $column_status; ?></td>
<td><?php echo $column_date_added; ?></td>
<td class="text-right"><?php echo $column_total; ?></td>
<td class="text-right"><?php echo $column_action; ?></td>
</tr>
</thead>
<tbody>
<?php if ($orders) { ?>
<?php foreach ($orders as $order) { ?>
<tr>
<td class="text-right"><?php echo $order['order_id']; ?></td>
<td><?php echo $order['customer']; ?></td>
<td><?php echo $order['status']; ?></td>
<td><?php echo $order['date_added']; ?></td>
<td class="text-right"><?php echo $order['total']; ?></td>
<td class="text-right"><a href="<?php echo $order['view']; ?>" data-toggle="tooltip" title="<?php echo $button_view; ?>" class="btn btn-info"><i class="fa fa-eye"></i></a></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="6"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
Подскажите пожалуйста как брать именно последний ид, а не последний 5й ид?
Есть вариант 'limit' => указать 1, и тогда не нужно суммировать. Но тогда на главной выводиться только 1 последний заказ.
$filter_data = array(
'sort' => 'o.date_added',
'order' => 'DESC',
'start' => 0,
'limit' => 1
);
Понимаю что код костыльный, но это единственный бесплатный вариант для Opencart 2.3.0.2