Answer the question
In order to leave comments, you need to log in
How to change date format when filtering OpenCart 2.3?
Hey! I have an order filter by date. So, the problem is that the filter only works with the YYYY-MM-DD date format, but if I change the date format to DD.MM.YYYY in the data-date-format attribute, then the filter does not find anything else. Although all requests remain in the url. The bootstrap-datetimepicker.js library is connected
Filtering works by checking the post-request and then adding a condition to the request
public function getOrders($data = array()) {
$sql = "SELECT o.order_id, o.firstname, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
$sql .= " WHERE o.order_status_id > '0' AND o.customer_id = '" . (int)$this->customer->getId() . "' AND o.order_status_id > '0' AND o.store_id = '" . (int)$this->config->get('config_store_id')."'";
if (!empty($data['filter_customer'])) {
$sql .= " AND CONCAT(o.order_id, ' ') LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
}
if (!empty($data['filter_date_from'])) {
//добавление запроса к бд
$sql .= " AND DATE(o.date_added) >= '" . $this->db->escape($data['filter_date_from']) . "'";
}
if (!empty($data['filter_date_to'])) {
//добавление запроса к бд
$sql .= " AND DATE(o.date_added) <= DATE('" . $this->db->escape($data['filter_date_to']) . "')";
}
$sort_data = array(
'o.order_id',
'customer',
'status',
'o.date_added',
'o.date_modified',
'o.total'
);
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY o.order_id";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 10;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql);
return $query->rows;
}
$('#button-filter').on('click', function() {
url = 'index.php?route=account/order';
var filter_date_from = $('input[name=\'filter_date_from\']').val();
if (filter_date_from) {
url += '&filter_date_from=' + encodeURIComponent(filter_date_from);
}
var filter_date_to = $('input[name=\'filter_date_to\']').val();
if (filter_date_to) {
url += '&filter_date_to=' + encodeURIComponent(filter_date_to);
}
location = url;
});
Answer the question
In order to leave comments, you need to log in
so convert the values to a single format, what's the problem?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question