Related
I want, in the latest module to be able to show only the products that don't have special price!
in model/catalog/product.php I have modified getLatestProducts() function from
foreach ($query->rows as $result) {
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}
with
foreach ($query->rows as $result) {
$queryCheckSpecial = $this->db->query("SELECT product_id FROM ". DB_PREFIX ."product_special WHERE product_id =".$result['product_id']);
if (!$queryCheckSpecial->row){
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}else{
continue;
}
}
but it's not working!
What I'm doing wrong?
any help will be apreciated!
Edit:
catalog\controller\extension\module\latest.php
Find:
'sort' => 'p.date_added',
Add after:
'ignore_special' => 1,
Edit:
catalog\model\catalog\product.php
Find (first match):
if (!empty($data['filter_name']) || !empty($data['filter_tag'])) {
Add before:
if (!empty($data['ignore_special'])) {
$sql .= " AND (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) IS NULL";
}
Then clear your caches.
simply update:
this:
foreach ($query->rows as $result) {
$queryCheckSpecial = $this->db->query("SELECT product_id FROM ". DB_PREFIX ."product_special WHERE product_id =".$result['product_id']);
if (!$queryCheckSpecial->row){
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}else{
continue;
}
}
}
with:
foreach ($query->rows as $result) {
$product_info = $this->getProduct($result['product_id']);
if (!$product_info['special']){
$product_data[$result['product_id']] =
}
}
Also don't forget to clear cache before testing.
#digicart
I've done in catalog\controller\extension\module\latest.php
'ignore_special' => 1,
in catalog\model\catalog\product.php
if (!empty($data['ignore_special']) && empty($data['filter_category_id'])){
$this->log->debug('dsadsa');
$queryCheckSpecial = $this->db->query("SELECT product_id FROM ". DB_PREFIX ."product_special WHERE product_id =".$result['product_id']);
if (!$queryCheckSpecial->row){
$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
}else{
continue;
}
at the end of getproducts()
And it's working on latest page! Problem is that in category page, somehow the ignore special field is present, and i don't know why !
Am new in Opencart, I need to show all status orders in order list page.
I mean my dashboard shows only pending status orders list.
But i need to show processing, Missing Order, complete, ect...
This is my code in controller
order.php:
$results = $this->model_sale_order->getOrders($filter_data);
foreach ($results as $result) {
$data['orders'][] = array(
'order_id' => $result['order_id'],
'customer' => $result['customer'],
'selected_customer_name'=>$result['selected_customer_name'],
'is_sales_person'=>$result['is_sales_person'],
'status' => $result['status'],
'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
'shipping_code' => $result['shipping_code'],
'view' => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL'),
'edit' => $this->url->link('sale/order/edit', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL'),
'delete' => $this->url->link('sale/order/delete', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
);
Following code for model
order.php
public function getOrders($data = array()) {
//$sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (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 = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id) AS status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified,o.is_sales_person,o.selected_customer_name FROM `" . DB_PREFIX . "order` o";
if (isset($data['filter_order_status'])) {
$implode = array();
$order_statuses = explode(',', $data['filter_order_status']);
foreach ($order_statuses as $order_status_id) {
$implode[] = "o.order_status_id = '" . (int)$order_status_id . "'";
}
if ($implode) {
$sql .= " WHERE (" . implode(" OR ", $implode) . ")";
} else {
}
} else {
$sql .= " WHERE o.order_status_id > '0'";
}
if (!empty($data['filter_order_id'])) {
$sql .= " AND o.order_id = '" . (int)$data['filter_order_id'] . "'";
}
if (!empty($data['filter_customer'])) {
$sql .= " AND CONCAT(o.firstname, ' ', o.lastname) LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
}
if (!empty($data['filter_route'])) {
$query1 = $this->db->query("SELECT r.route_id FROM " . DB_PREFIX . "route r left join ".DB_PREFIX."route_description rd on r.route_id=rd.route_id WHERE rd.name = '" . $data['filter_route']. "'");
$route_id=$query1->row['route_id'];
$tempArray=array();
$query2 = $this->db->query("SELECT c.customer_id FROM " . DB_PREFIX . "customer c WHERE c.route_id = '" . $route_id. "'");
$customerIdList=$query2->rows;
if(!empty($customerIdList))
{
foreach($customerIdList as $customer)
{
array_push($tempArray,$customer['customer_id']);
}
$customer_id=implode(',',$tempArray);
$sql .= " AND o.customer_id in(" . $customer_id . ")";
}
}
if (!empty($data['filter_date_added'])) {
$sql .= " AND DATE(o.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
}
if (!empty($data['filter_date_modified'])) {
$sql .= " AND DATE(o.date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
}
if (!empty($data['filter_total'])) {
$sql .= " AND o.total = '" . (float)$data['filter_total'] . "'";
}
$status=1;
$sql.="AND o.order_status_id='".$status."'";
$admin_user=$_COOKIE['admin_user'];
if($admin_user=='sales_01')
{
$sql.="AND o.customer_group_id!=3";
}
elseif($admin_user=='mmd_bangalore')
{
$sql.="AND o.customer_group_id in(3)";
}
$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'] = 20;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql);
return $query->rows;
}
I try to change this code $sql .= " WHERE o.order_status_id > '0'"; but it not working.
And this is my order list page image:
See here in this page showing only pending status orders.
And this is my database image
And here order_id 35434 not showing in order list page . because order_status_id in 2
How can i show all orders?
Possible without programming
When order is completed you can edit the order and then set order status to completed, cancelled etc. You don't need to edit order list page.
Click in edit order(pencil icon) button.
Scroll down to add order history section.
Then set the status you want.
i'm using opencart 1.5.6.3, i'm trying to display a page with 2 field. 1 field will be use for Email and another field for Order ID. So client can see their order status directly without login.
thanks in advance.
After so much try, I got solution.
Add new file to
catalog> controller> account> guest.php
<?php class ControllerAccountGuest extends Controller {
private $error = array();
public function index() {
$this->language->load('account/guest');
$this->document->setTitle($this->language->get('heading_title'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_email'] = $this->language->get('entry_email');
$this->data['entry_ip'] = $this->language->get('entry_ip');
$this->data['entry_order_id'] = $this->language->get('entry_order_id');
$this->data['text_err'] = $this->language->get('text_err');
$this->data['text_ip'] = $this->language->get('text_ip');
$this->data['text_order_id'] = $this->language->get('text_order_id');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('account/guest/info', '', 'SSL');
$this->data['continue'] = $this->url->link('account/guest', '', 'SSL');
if (isset($this->request->get['email'])) {
$this->data['email'] = $this->request->get['email'];
} else {
$this->data['email'] = '';
}
if (isset($this->request->get['ip'])) {
$this->data['ip'] = $this->request->get['ip'];
} else {
$this->data['ip'] = '';
}
if (isset($this->request->get['order_id'])) {
$this->data['order_id'] = $this->request->get['order_id'];
} else {
$this->data['order_id'] = '';
}
// Nacteni chybovych hlaseni
$err = array(
'email' => false,
'ip' => false,
'order_id' => false,
);
if (isset($this->request->get['err'])) {
$err_temp = explode('|', $this->request->get['err']);
foreach ($err_temp as $value) {
$err[$value] = true;
} // foreach
}
$this->data['err'] = $err;
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/guest_login.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/guest_login.tpl';
} else {
$this->template = 'default/template/account/guest_login.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
public function info() {
$err = false;
$url = '';
if ( isset($this->request->post['email']) AND strlen($this->request->post['email']) > 4 ) {
$email = $this->request->post['email'];
$url .= '&email=' . $this->request->post['email'];
} else {
$email = '';
$err = ( $err ? $err . '|' . 'email' : 'email' );
}
/*
if (isset($this->request->post['ip'])) {
$ip = $this->request->post['ip'];
$url .= '&ip=' . $this->request->post['ip'];
} else {
$ip = '0';
$err = ( $err ? $err . '|' . 'ip' : 'ip' );
}
*/
if ( isset($this->request->post['order_id']) AND is_numeric($this->request->post['order_id']) ) {
$order_id = $this->request->post['order_id'];
$url .= '&order_id=' . $this->request->post['order_id'];
} else {
$order_id = '0';
$err = ( $err ? $err . '|' . 'order_id' : 'order_id' );
}
if ($err) {
$url .= '&err=' . $err;
$this->redirect($this->url->link('account/guest', 'token=' . $this->session->data['token'] . $url, 'SSL'));
}
$this->language->load('account/guest_history');
$this->load->model('account/guest');
//$order_info = $this->model_account_guest->getOrder($order_id, $email, $ip);
$order_info = $this->model_account_guest->getOrder($order_id, $email);
if ($order_info) {
$this->document->setTitle($this->language->get('text_order'));
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['heading_title'] = $this->language->get('text_order');
$this->data['text_order_detail'] = $this->language->get('text_order_detail');
$this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
$this->data['text_order_id'] = $this->language->get('text_order_id');
$this->data['text_date_added'] = $this->language->get('text_date_added');
$this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
$this->data['text_shipping_address'] = $this->language->get('text_shipping_address');
$this->data['text_payment_method'] = $this->language->get('text_payment_method');
$this->data['text_payment_address'] = $this->language->get('text_payment_address');
$this->data['text_history'] = $this->language->get('text_history');
$this->data['text_comment'] = $this->language->get('text_comment');
$this->data['text_action'] = $this->language->get('text_action');
$this->data['text_selected'] = $this->language->get('text_selected');
$this->data['text_reorder'] = $this->language->get('text_reorder');
$this->data['text_return'] = $this->language->get('text_return');
$this->data['column_name'] = $this->language->get('column_name');
$this->data['column_model'] = $this->language->get('column_model');
$this->data['column_quantity'] = $this->language->get('column_quantity');
$this->data['column_price'] = $this->language->get('column_price');
$this->data['column_total'] = $this->language->get('column_total');
$this->data['column_date_added'] = $this->language->get('column_date_added');
$this->data['column_status'] = $this->language->get('column_status');
$this->data['column_comment'] = $this->language->get('column_comment');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['action'] = $this->url->link('account/order/info', 'order_id=' . $order_id , 'SSL');
if ($order_info['invoice_no']) {
$this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$this->data['invoice_no'] = '';
}
$this->data['order_id'] = $order_id ;
$this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$this->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
$this->data['shipping_method'] = $order_info['shipping_method'];
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
$this->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
$this->data['payment_method'] = $order_info['payment_method'];
$this->data['products'] = array();
$products = $this->model_account_guest->getOrderProducts($order_id );
foreach ($products as $product) {
$option_data = array();
$options = $this->model_account_guest->getOrderOptions($order_id , $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$option_data[] = array(
'name' => $option['name'],
'value' => (strlen($option['value']) > 20 ? substr($option['value'], 0, 20) . '..' : $option['value']),
);
} else {
$filename = substr($option['value'], 0, strrpos($option['value'], '.'));
$option_data[] = array(
'name' => $option['name'],
'value' => (strlen($filename) > 20 ? substr($filename, 0, 20) . '..' : $filename)
);
}
} // foreach
$this->data['products'][] = array(
'order_product_id' => $product['order_product_id'],
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']),
'selected' => isset($this->request->post['selected']) && in_array($result['order_product_id'], $this->request->post['selected'])
);
}
$this->data['totals'] = $this->model_account_guest->getOrderTotals($order_id );
$this->data['comment'] = $order_info['comment'];
$this->data['histories'] = array();
$results = $this->model_account_guest->getOrderHistories($order_id );
foreach ($results as $result) {
$this->data['histories'][] = array(
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'status' => $result['status'],
'comment' => nl2br($result['comment'])
);
} // foreach
$this->data['continue'] = $this->url->link('account/order', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/guest_history.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/guest_history.tpl';
} else {
$this->template = 'default/template/account/guest_history.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
} else {
$this->document->setTitle($this->language->get('text_order'));
$this->data['heading_title'] = $this->language->get('text_order');
$this->data['text_error'] = $this->language->get('text_error');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL'),
'separator' => $this->language->get('text_separator')
);
$this->data['continue'] = $this->url->link('account/order', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
} else {
$this->template = 'default/template/error/not_found.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}} // info
private function validate() {
if (!isset($this->request->post['selected']) || !isset($this->request->post['action']) || !$this->request->post['action']) {
$this->error['warning'] = $this->language->get('error_warning');
}
if (!$this->error) {
return true;
} else {
return false;
}
} // validate } ?>
Add another new file to catalog> model> account> guest.php
<?php class ModelAccountGuest extends Model { //public function getOrder($order_id, $email, $ip) { public function getOrder($order_id, $email) {
$order_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "order`
WHERE order_id = '" . (int)$order_id . "'
AND email = '" . $this->db->escape($email) . "'
AND order_status_id > '0'
"); // AND ip = '" . $this->db->escape($ip) . "'
if ($order_query->num_rows) {
$country_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "country`
WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'
");
if ($country_query->num_rows) {
$shipping_iso_code_2 = $country_query->row['iso_code_2'];
$shipping_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$shipping_iso_code_2 = '';
$shipping_iso_code_3 = '';
}
$zone_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "zone`
WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'
");
if ($zone_query->num_rows) {
$shipping_zone_code = $zone_query->row['code'];
} else {
$shipping_zone_code = '';
}
$country_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "country`
WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'
");
if ($country_query->num_rows) {
$payment_iso_code_2 = $country_query->row['iso_code_2'];
$payment_iso_code_3 = $country_query->row['iso_code_3'];
} else {
$payment_iso_code_2 = '';
$payment_iso_code_3 = '';
}
$zone_query = $this->db->query("
SELECT *
FROM `" . DB_PREFIX . "zone`
WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'
");
if ($zone_query->num_rows) {
$payment_zone_code = $zone_query->row['code'];
} else {
$payment_zone_code = '';
}
return array(
'order_id' => $order_query->row['order_id'],
'invoice_no' => $order_query->row['invoice_no'],
'invoice_prefix' => $order_query->row['invoice_prefix'],
'store_id' => $order_query->row['store_id'],
'store_name' => $order_query->row['store_name'],
'store_url' => $order_query->row['store_url'],
'customer_id' => $order_query->row['customer_id'],
'firstname' => $order_query->row['firstname'],
'lastname' => $order_query->row['lastname'],
'telephone' => $order_query->row['telephone'],
'fax' => $order_query->row['fax'],
'email' => $order_query->row['email'],
'shipping_firstname' => $order_query->row['shipping_firstname'],
'shipping_lastname' => $order_query->row['shipping_lastname'],
'shipping_company' => $order_query->row['shipping_company'],
'shipping_address_1' => $order_query->row['shipping_address_1'],
'shipping_address_2' => $order_query->row['shipping_address_2'],
'shipping_postcode' => $order_query->row['shipping_postcode'],
'shipping_city' => $order_query->row['shipping_city'],
'shipping_zone_id' => $order_query->row['shipping_zone_id'],
'shipping_zone' => $order_query->row['shipping_zone'],
'shipping_zone_code' => $shipping_zone_code,
'shipping_country_id' => $order_query->row['shipping_country_id'],
'shipping_country' => $order_query->row['shipping_country'],
'shipping_iso_code_2' => $shipping_iso_code_2,
'shipping_iso_code_3' => $shipping_iso_code_3,
'shipping_address_format' => $order_query->row['shipping_address_format'],
'shipping_method' => $order_query->row['shipping_method'],
'payment_firstname' => $order_query->row['payment_firstname'],
'payment_lastname' => $order_query->row['payment_lastname'],
'payment_company' => $order_query->row['payment_company'],
'payment_address_1' => $order_query->row['payment_address_1'],
'payment_address_2' => $order_query->row['payment_address_2'],
'payment_postcode' => $order_query->row['payment_postcode'],
'payment_city' => $order_query->row['payment_city'],
'payment_zone_id' => $order_query->row['payment_zone_id'],
'payment_zone' => $order_query->row['payment_zone'],
'payment_zone_code' => $payment_zone_code,
'payment_country_id' => $order_query->row['payment_country_id'],
'payment_country' => $order_query->row['payment_country'],
'payment_iso_code_2' => $payment_iso_code_2,
'payment_iso_code_3' => $payment_iso_code_3,
'payment_address_format' => $order_query->row['payment_address_format'],
'payment_method' => $order_query->row['payment_method'],
'comment' => $order_query->row['comment'],
'total' => $order_query->row['total'],
'order_status_id' => $order_query->row['order_status_id'],
'language_id' => $order_query->row['language_id'],
'currency_id' => $order_query->row['currency_id'],
'currency_code' => $order_query->row['currency_code'],
'currency_value' => $order_query->row['currency_value'],
'date_modified' => $order_query->row['date_modified'],
'date_added' => $order_query->row['date_added'],
'ip' => $order_query->row['ip']
);
} else {
return false;
}
} // getOrder
public function getOrderProducts($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_product
WHERE order_id = '" . (int)$order_id . "'
");
return $query->rows;
} // getOrderProducts
public function getOrderOptions($order_id, $order_product_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_option
WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$order_product_id . "'
");
return $query->rows;
} // getOrderOptions
public function getOrderTotals($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_total
WHERE order_id = '" . (int)$order_id . "'
ORDER BY sort_order
");
return $query->rows;
} // getOrderTotals
public function getOrderHistories($order_id) {
$query = $this->db->query("
SELECT date_added, os.name AS status, oh.comment, oh.notify
FROM " . DB_PREFIX . "order_history oh
LEFT JOIN " . DB_PREFIX . "order_status os ON oh.order_status_id = os.order_status_id
WHERE oh.order_id = '" . (int)$order_id . "'
AND os.language_id = '" . (int)$this->config->get('config_language_id') . "'
ORDER BY oh.date_added
"); // AND oh.notify = '1'
return $query->rows;
} // getOrderHistories
public function getOrderDownloads($order_id) {
$query = $this->db->query("
SELECT *
FROM " . DB_PREFIX . "order_download
WHERE order_id = '" . (int)$order_id . "'
ORDER BY name
");
return $query->rows;
} // getOrderDownloads
public function getTotalOrders() {
$query = $this->db->query("
SELECT COUNT(*) AS total
FROM `" . DB_PREFIX . "order`
WHERE customer_id = '" . (int)$this->customer->getId() . "' AND order_status_id > '0'
");
return $query->row['total'];
} // getTotalOrders
public function getTotalOrderProductsByOrderId($order_id) {
$query = $this->db->query("
SELECT COUNT(*) AS total
FROM " . DB_PREFIX . "order_product
WHERE order_id = '" . (int)$order_id . "'
");
return $query->row['total'];
} // getTotalOrderProductsByOrderId } // class ?>
Now add language file to catalog> language> english> account>
<?php // Heading $_['heading_title'] = 'Order Tracking'; // Text $_['text_account'] = 'Account'; // Entry $_['entry_email'] = 'E-Mail Address:'; $_['entry_ip'] = 'IP Address:'; $_['entry_order_id'] = 'Order Number:'; $_['text_err'] = '<span style="color:red;"> <<< </span>'; $_['text_ip'] = 'eg. 123.345.456.678 - Find this on you order email in the \'Order Details\' section:'; $_['text_order_id'] = 'eg. 123 - Find this on you order email in the \'Order Details\' section:'; // Error $_['error_login'] = 'Warning: No match for E-Mail Address and/or Order Number.'; ?>
Now add tlp file to catalog> view> theme> default> template> account> guest_login.tlp with form action and submit button then add this java script:
<script type="text/javascript"><!-- $('#login input').keydown(function(e) {
if (e.keyCode == 13) {
$('#login').submit();
} }); //--></script>
Now add another file to show result. Catalog> view> theme> default> template> account> guest_history.tlp
Checked in OpenCart 1.5.6.3 with custom theme.
I am looking for a way to add a field in the admin for my information pages. I just need it in the admin and not looking to show any data from the field on front end.
To explain better the list page for my information pages is set up like this:
Information Title | Sort Order | Action
I want to add an identifying blurb that will display before the title in admin so at a glance I can look and see which store (I'm running multi-store) that info page is assigned to. I'm guessing the actual field would need to be added to the add/edit form and then somehow told to display that field input on the list page.
I do have vQmod installed and have looked at the documentation but I just can't wrap my head around this.
I would REALLY appreciate any help on this.
Here's the code from information.php.
<?php
class ModelCatalogInformation extends Model {
public function getInformation($information_id) {
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) LEFT JOIN " . DB_PREFIX . "information_to_store i2s ON (i.information_id = i2s.information_id) WHERE i.information_id = '" . (int)$information_id . "' AND id.language_id = '" . (int)$this->config->get('config_language_id') . "' AND i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1'");
//return $query->row;
$r = $query->row;
$r['title'] = preg_replace('/ ## .+/','',$r['title']);
return $r;
}
public function getInformations() {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) LEFT JOIN " . DB_PREFIX . "information_to_store i2s ON (i.information_id = i2s.information_id) WHERE id.language_id = '" . (int)$this->config->get('config_language_id') . "' AND i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1' ORDER BY i.sort_order, LCASE(id.title) ASC");
//return $query->rows;
$result = $query->rows;
foreach ($result as $key => $r){
$result[$key] = preg_replace('/ ## .+/','',$r['title']);
}
return $result;
}
public function getInformationLayoutId($information_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int)$information_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
return $query->row['layout_id'];
} else {
return $this->config->get('config_layout_information');
}
}
}
?>
When you mentioned checking the vQmod cache it dawned on me that I'm using a mod that hides info pages from the menu by using -1 sort order. Here's the information.php from the cache folder.
<?php
class ModelCatalogInformation extends Model {
public function getInformation($information_id) {
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) LEFT JOIN " . DB_PREFIX . "information_to_store i2s ON (i.information_id = i2s.information_id) WHERE i.information_id = '" . (int)$information_id . "' AND id.language_id = '" . (int)$this->config->get('config_language_id') . "' AND i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1'");
return $query->row;
}
public function getInformations() {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) LEFT JOIN " . DB_PREFIX . "information_to_store i2s ON (i.information_id = i2s.information_id) WHERE id.language_id = '" . (int)$this->config->get('config_language_id') . "' AND i2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND i.status = '1' AND i.sort_order <> '-1' ORDER BY i.sort_order, LCASE(id.title) ASC");
return $query->rows;
}
public function getInformationLayoutId($information_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information_to_layout WHERE information_id = '" . (int)$information_id . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
return $query->row['layout_id'];
} else {
return $this->config->get('config_layout_information');
}
}
}
?>
If I understand your purpose correctly, I have an easier solution for you.
Add your description in the Title field , use some unique token to indicate the beginning of this description, it will not render in the front end, Example:
I use ## here as token.
My Title ## This page is for Store 1
then edit catalog/model/catalog/information, in function getInformation() find line:
return $query->row;
replace with:
//return $query->row;
$r = $query->row;
$r['title'] = preg_replace('/ ## .+/','',$r['title']);
return $r;
in function getInformations() find line:
return $query->rows;
replace with:
//return $query->rows;
$result = $query->rows;
foreach ($result as $key => $r){
$result[$key] = preg_replace('/ ## .+/','',$r['title']);
}
return $result;
You're done.
This works perfectly for the sidebox Info display, however if you are using a theme with columns and pulling in the Info links to display there, it only pulls in the first letter of each link title.
Here is the code for the footer. I am using the identical setup as flightoffancy in same cart version:
This is from catalog/controller/common/footer:
$this->load->model('catalog/information');
$this->data['informations'] = array();
foreach ($this->model_catalog_information->getInformations() as $result) {
if ($result['bottom']) {
$this->data['informations'][] = array(
'title' => $result['title'],
'href' => $this->url->link('information/information', 'information_id=' . $result['information_id'])
);
}
}
$this->data['contact'] = $this->url->link('information/contact');
$this->data['return'] = $this->url->link('account/return/insert', '', 'SSL');
$this->data['sitemap'] = $this->url->link('information/sitemap');
$this->data['manufacturer'] = $this->url->link('product/manufacturer');
$this->data['voucher'] = $this->url->link('account/voucher', '', 'SSL');
$this->data['affiliate'] = $this->url->link('affiliate/account', '', 'SSL');
$this->data['special'] = $this->url->link('product/special');
$this->data['account'] = $this->url->link('account/account', '', 'SSL');
$this->data['order'] = $this->url->link('account/order', '', 'SSL');
$this->data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
$this->data['newsletter'] = $this->url->link('account/newsletter', '', 'SSL');
I want to add countdown timer in special module(opencart 1.5.3.1) which displayed in homepage. looks like this
http://opencart-themes.com/index.php?route=product/product&product_id=109
anyone willing to help me? I tried a few times based on your code. it doesn't work.I really appreciate you can help me on this.
Thanks, here is code:
public function updateViewed($product_id) {
$this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = (viewed + 1) WHERE product_id = '" . (int)$product_id . "'");
}
public function getProduct($product_id) {
if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getCustomerGroupId();
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
if ($query->num_rows) {
$query->row['price'] = ($query->row['discount'] ? $query->row['discount'] : $query->row['price']);
$query->row['rating'] = (int)$query->row['rating'];
return $query->row;
} else {
return false;
}
}
Firstly you have to fetch date_start and date_end from the database. Edit catalog/model/catalog/product.php.
Change
public function getProduct($product_id) {
if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getCustomerGroupId();
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");
To
public function getProduct($product_id) {
if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getCustomerGroupId();
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT date_start FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_start, (SELECT date_end FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_ends, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");
Note: if you have edits in this and would like to preserve them, I only added the parts for those 2 values.
Then you need to send the value to the view file, you can do so in catalog/controller/module/special.php
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
Change to:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
'date_start' => $result['date_start'],
'date_end' => $result['date_end'],
);
In catalog/view/theme/*your_theme*/template/module/special.tpl we need to do a few things. We need to Add the countdown script, add the countdown timer, and pull the values.
1) Add the script - There's also an if statement to only put the script if there is at least one special. Put this in the top of your tpl
<?php if ($products) { ?>
<script type="text/javascript">
jQuery.fn.countdown = function (date, options, dateparse) {
options = jQuery.extend({
lang:{
years: [' year, ', ' years, '],
months: [' month, ', ' months, '],
days: [' day, ', ' days, '],
hours: [':', ':'],
minutes: [':', ':'],
seconds: ['', ''],
plurar: function(n) {
return (n == 1 ? 0 : 1);
}
},
prefix: "end: ",
finish: "End!",
redirect: '',
dateparse: "2050-01-01 00:00:00"
}, options);
var timestamp = Date.parse(options.dateparse);
var timeDifference = function(begin, end) {
if(end < begin){
return false;
}
var diff = {
seconds: [end.getSeconds() - begin.getSeconds(), 60],
minutes: [end.getMinutes() - begin.getMinutes(), 60],
hours: [end.getHours() - begin.getHours(), 24],
days: [end.getDate() - begin.getDate(), new Date(begin.getYear(), begin.getMonth(), 0).getDate()],
months: [end.getMonth() - begin.getMonth()-1, 12],
years: [end.getYear() - begin.getYear(), 0]
};
var result = new Array();
var flag = false;
for(i in diff){
if((i=='seconds' || i=='minutes') && diff[i][0]==0){
result.push('00' + options.lang[i][options.lang.plurar(diff[i][0])]);
}else{
if(flag){
diff[i][0]--;
flag = false;
}
if(diff[i][0] < 0){
flag = true;
diff[i][0] += diff[i][1];
}
if(!diff[i][0]) continue;
if(i=='days' && diff[i][0]<0){
diff['days'][0]=Math.abs(1+diff['days'][0]);
diff['months'][0]++;
}
if(i=='years' && diff[i][0]<0)
return '';
if((i=='seconds' || i=='minutes') && diff[i][0]<10)
diff[i][0] = '0' + diff[i][0];
if(diff[i][0]!=0)
result.push(diff[i][0] + '' + options.lang[i][options.lang.plurar(diff[i][0])]);
}
}
return result.reverse().join('');
};
var timeCurrent = function(date){
var hou = date.getHours().toString();
var min = date.getMinutes().toString();
var sec = date.getSeconds().toString();
hou = (hou<10)?0+hou:hou;
min = (min<10)?0+min:min;
sec = (sec<10)?0+sec:sec;
return hou+':'+min+':'+sec;
};
var elem = $(this);
var timeUpdate = function(){
dateJS = new Date();
timestamp = parseInt(timestamp) + 1000;
dateJS.setTime(timestamp);
/*if(elem.parents('.timedependent-form-content').find('#currentTime').length)
elem.parents('.timedependent-form-content').find('#currentTime').html(timeCurrent(dateJS));*/
var s = timeDifference(dateJS, date);
if(s.length){
elem.html(options.prefix + s);
}else{
clearInterval(timer);
elem.html(options.finish);
if(options.redirect != '')
window.location.href = options.redirect;
}
};
timeUpdate();
var timer = setInterval(timeUpdate, 1000);
};
</script>
<?php } ?>
Change
<?php foreach ($products as $product) { ?>
To:
<?php $now = time();
$count = 0;
foreach ($products as $product) {
$count++; ?>
Add this where you like:
<?php $time_remaining = $result['date_end'];
$countdown = strtotime("$time_remaining"); ?>
<div class="timerbar">
<h2 id="product<?php echo $count; ?>"></h2>
</div><br/>
<script>
jQuery("#product<?php echo $count; ?>").countdown(new Date(<?php echo date('Y, m, d, H, i, s',$countdown); ?>), {
prefix:"",
finish:"Expired",
redirect:"",
dateparse:"<?php echo date('d F Y H:i:s',$now); ?>",
lang:{
years: [' year, ', ' years, '],
months: [' month, ', ' months, '],
days: [' day, ', ' days, '],
hours: [':', ':'],
minutes: [':', ':'],
seconds: ['', ''],
plurar: function(n) {
return (n == 1 ? 0 : 1);
}
}});
</script>
To customize the output:
finish = Expired text
redirect = type url if you want it to redirect on expiration
lang = Change countdown output
#Cleverbot answer is great but there is some missing or some error code was founded and the correct answer is as following :
First step:
Edit catalog/model/catalog/product.php.
change
public function getProduct($product_id) {
if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getCustomerGroupId();
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");
to
public function getProduct($product_id) {
if ($this->customer->isLogged()) {
$customer_group_id = $this->customer->getCustomerGroupId();
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT date_start FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_start, (SELECT date_end FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS date_ends, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.sort_order, p.date_expires >= NOW(), p.date_expires <= NOW() DESC");
and in same place file under above code search about
'special' => $query->row['special'],
Then after Add this code
'date_ends' => $query->row['date_ends'],
'date_start' => $query->row['date_start'],
Second Step:
Then you need to send the value to the view file, you can do so in catalog/controller/module/special.php
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
to this one
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
'date_start' => $result['date_start'],
'date_ends' => $result['date_ends'],
);
Third Step
In catalog/view/theme/your_theme/template/module/special.tpl we need to do a few things. We need to Add the countdown script, add the countdown timer, and pull the values.
1) Add countdown script
put the following code in the top of special.tpl file (important)
<?php if ($products) { ?>
<script type="text/javascript">
jQuery.fn.countdown = function (date, options, dateparse) {
options = jQuery.extend({
lang:{
years: [' year, ', ' years, '],
months: [' month, ', ' months, '],
days: [' day, ', ' days, '],
hours: [':', ':'],
minutes: [':', ':'],
seconds: ['', ''],
plurar: function(n) {
return (n == 1 ? 0 : 1);
}
},
prefix: "end: ",
finish: "End!",
redirect: '',
dateparse: "2050-01-01 00:00:00"
}, options);
var timestamp = Date.parse(options.dateparse);
var timeDifference = function(begin, end) {
if(end < begin){
return false;
}
var diff = {
seconds: [end.getSeconds() - begin.getSeconds(), 60],
minutes: [end.getMinutes() - begin.getMinutes(), 60],
hours: [end.getHours() - begin.getHours(), 24],
days: [end.getDate() - begin.getDate(), new Date(begin.getYear(), begin.getMonth(), 0).getDate()],
months: [end.getMonth() - begin.getMonth()-1, 12],
years: [end.getYear() - begin.getYear(), 0]
};
var result = new Array();
var flag = false;
for(i in diff){
if((i=='seconds' || i=='minutes') && diff[i][0]==0){
result.push('00' + options.lang[i][options.lang.plurar(diff[i][0])]);
}else{
if(flag){
diff[i][0]--;
flag = false;
}
if(diff[i][0] < 0){
flag = true;
diff[i][0] += diff[i][1];
}
if(!diff[i][0]) continue;
if(i=='days' && diff[i][0]<0){
diff['days'][0]=Math.abs(1+diff['days'][0]);
diff['months'][0]++;
}
if(i=='years' && diff[i][0]<0)
return '';
if((i=='seconds' || i=='minutes') && diff[i][0]<10)
diff[i][0] = '0' + diff[i][0];
if(diff[i][0]!=0)
result.push(diff[i][0] + '' + options.lang[i][options.lang.plurar(diff[i][0])]);
}
}
return result.reverse().join('');
};
var timeCurrent = function(date){
var hou = date.getHours().toString();
var min = date.getMinutes().toString();
var sec = date.getSeconds().toString();
hou = (hou<10)?0+hou:hou;
min = (min<10)?0+min:min;
sec = (sec<10)?0+sec:sec;
return hou+':'+min+':'+sec;
};
var elem = $(this);
var timeUpdate = function(){
dateJS = new Date();
timestamp = parseInt(timestamp) + 1000;
dateJS.setTime(timestamp);
/*if(elem.parents('.timedependent-form-content').find('#currentTime').length)
elem.parents('.timedependent-form-content').find('#currentTime').html(timeCurrent(dateJS));*/
var s = timeDifference(dateJS, date);
if(s.length){
elem.html(options.prefix + s);
}else{
clearInterval(timer);
elem.html(options.finish);
if(options.redirect != '')
window.location.href = options.redirect;
}
};
timeUpdate();
var timer = setInterval(timeUpdate, 1000);
};
</script>
<?php } ?>
2) Add the countdown timer and pull the values.
Change
<?php foreach ($products as $product) { ?>
to
<?php $now = time();
$count = 0;
foreach ($products as $product) {
$count++; ?>
Add this where you like:
<?php $time_remaining = $product['date_ends'];
$countdown = strtotime("$time_remaining"); ?>
<div class="timerbar">
<h2 id="product<?php echo $count; ?>"></h2>
</div><br/>
<script>
jQuery("#product<?php echo $count; ?>").countdown(new Date(<?php echo date('Y, m, d, H, i, s',$countdown); ?>), {
prefix:"",
finish:"Expired",
redirect:"",
dateparse:"<?php echo date('d F Y H:i:s',$now); ?>",
lang:{
years: [' year, ', ' years, '],
months: [' month, ', ' months, '],
days: [' day, ', ' days, '],
hours: [':', ':'],
minutes: [':', ':'],
seconds: ['', ''],
plurar: function(n) {
return (n == 1 ? 0 : 1);
}
}});
</script>
To customize the output:
finish = Expired text
redirect = type url if you want it to redirect on expiration
lang = Change countdown output
All of These codes is working well with me , hope to work with you
i tried it with opencart v.1.5.6.4 and it is work