opencart custom download file error - opencart

i am looking to make download files in product page without login or registration in opencart as public download link, after doing the coding am not getting the right download file and also a unknow and unformatted file is downloaded. what i get screnshot
model file
public function getProductDownloads($product_id) {
$query = $this->db->query("SELECT d.download_id, d.filename, d.mask, dd.name FROM " . DB_PREFIX . "download d LEFT JOIN " . DB_PREFIX . "download_description dd USING ( download_id ) LEFT JOIN " . DB_PREFIX . "product_to_download p2d USING ( download_id ) WHERE p2d.product_id = '" . (int)$product_id . "'");
return $query->rows;
}
public function getDownload($download_id) {
$query = $this->db->query("SELECT d.filename, d.mask, dd.name FROM " . DB_PREFIX . "download d LEFT JOIN " . DB_PREFIX . "download_description dd ON (d.download_id = dd.download_id) where d.download_id AND dd.download_id = '" . (int)$download_id . "'");
return $query->rows;
}
controller file
$data['downloads'] = array();
$results = $this->model_catalog_product->getProductDownloads($this->request->get['product_id']);
foreach ($results as $result) {
$data['downloads'][] = array(
'filename' => $result['filename'],
'name' => $result['name'],
'href' => $this->url->link('product/product/download', 'download_id=' . $result['download_id'], 'SSL')
);
}
/*download*/
public function download() {
$this->load->model('catalog/product');
if (isset($this->request->get['download_id'])) {
$download_id = $this->request->get['download_id'];
} else {
$download_id = 0;
}
$download_info = $this->model_catalog_product->getDownload($download_id);
if ($download_info) {
$file = DIR_DOWNLOAD . $download_info['filename'];
$mask = basename($download_info['mask']);
if (!headers_sent()) {
if (file_exists($file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
if (ob_get_level()) {
ob_end_clean();
}
readfile($file, 'rb');
exit();
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
} else {
$this->response->redirect($this->url->link('common/home', '', 'SSL'));
}
}
}
view file
<?php foreach ($downloads as $download) { ?>
<?php echo $download['filename']; ?><br/>
<?php echo $download['name']; ?><br/>
download<br/>
<?php } ?>

You have to make some changes in controller file. I have changed your code. Just replace following code with download function. Hope this could help.
public function download() {
$this->load->model('catalog/product');
if (isset($this->request->get['download_id'])) {
$download_id = $this->request->get['download_id'];
} else {
$download_id = 0;
}
$download_info = $this->model_catalog_product->getDownload($download_id);
if ($download_info) {
$file = DIR_DOWNLOAD . $download_info[0]['filename'];
$mask = basename($download_info[0]['mask']);
if (!headers_sent()) {
if (file_exists($file)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
if (ob_get_level()) {
ob_end_clean();
}
readfile($file, 'rb');
exit();
} else {
exit('Error: Could not find file ' . $file . '!');
}
} else {
exit('Error: Headers already sent out!');
}
} else {
$this->response->redirect($this->url->link('common/home', '', 'SSL'));
}
}`

Related

Opencart: How to show all status orders in Order List Page

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.

OpenCart syntax error, unexpected T_VARIABLE, expecting T_FUNCTION

I get this error when someone try to go to checkout in my opencart store:
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /public_html/vqmod/vqcache/vq2-catalog_model_checkout_order.php on line 197
Here is the like 197 from vq2-catalog_model_checkout_order.php file
$order_query = $this->db->query("SELECT *, (SELECT os.name FROM `" . DB_PREFIX . "order_status` os WHERE os.order_status_id = o.order_status_id AND os.language_id = o.language_id) AS order_status FROM `" . DB_PREFIX . "order` o WHERE o.order_id = '" . (int)$order_id . "'");
$category_query = $this->db->query("SELECT cd.name FROM `" . DB_PREFIX . "product_to_category` pc INNER JOIN `" . DB_PREFIX . "category_description` cd ON pc.category_id = cd.category_id WHERE pc.product_id = '" . (int)$product['product_id'] . "' AND cd.language_id = '" . (int)$language_id . "'");
$i = 0;
foreach ($category_query->rows as $category) {
$i++;
if ($i <= 5) {
$category_data .= $category['name'] . '/';
}
}
$category_data = rtrim($category_data, '/');
if ($option_data) {
$name = utf8_substr($product['name'] . ' - ' . $option_data, 0, 80);
} else {
$name = utf8_substr($product['name'], 0, 80);
}
$products[] = array(
'name' => $name,
'sku' => $product['model'],
'category' => $category_data,
'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), false, $order_query->row['currency_value']),
'quantity' => $product['quantity']
);
}
return array(
'order_id' => $order_query->row['order_id'],
'store_name' => $order_query->row['store_name'],
'products' => $products,
'total' => $this->currency->format($order_query->row['total'], false, $order_query->row['currency_value']),
'currency_code' => $order_query->row['currency_code']
);
} else {
return false;
}
}
$order_query = $this->db->query("SELECT *, (SELECT os.name FROM `" . DB_PREFIX . "order_status` os WHERE os.order_status_id = o.order_status_id AND os.language_id = o.language_id) AS order_status FROM `" . DB_PREFIX . "order` o WHERE o.order_id = '" . (int)$order_id . "'");
if ($order_query->num_rows) {
$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 = '';
}
$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 = '';
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($order_query->row['language_id']);

Opencart Info Page

OK, I have been searching for quite some time, and this has me baffled.
I'm trying to add an ad that will pull up more info in the main content section.
If you look at http://teachingforapples.com/ , you'll see 2 links below the orange ad on the left. The only difference between those links is the information ID. However, they behave very differently. The one that says 'about' opens inside the main content area, but the one that says 'referral' opens full window.
There's nothing in the document content that would change this behavior.
The links are made exactly the same in the code except for the ID #.
The generated code shows the same kind of link, neither one has a target attrib.
I can't find anything in any of the modules that has logic code that looks at the doc id #.
So, I started looking at the database. I looked at all the information tables, but don't see anything different between the 2 pages.
Can someone point me in the right direction please? I feel that it must be something simple, but I just can't find it.
Thanks
P.S. the Information module is NOT installed.
Here's the information.php file.
<?php
class ControllerInformationInformation extends Controller {
public function index() {
$this->language->load('information/information');
$this->load->model('catalog/information');
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
} else {
$information_id = 0;
}
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$this->document->setTitle($information_info['title']);
$this->data['breadcrumbs'][] = array(
'text' => $information_info['title'],
'href' => $this->url->link('information/information', 'information_id=' . $information_id),
'separator' => $this->language->get('text_separator')
);
$this->data['info_id'] = $information_id;
$this->data['heading_title'] = $information_info['title'];
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
$this->data['continue'] = $this->url->link('common/home');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/information.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/information.tpl';
} else {
$this->template = 'default/template/information/information.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->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_error'),
'href' => $this->url->link('information/information', 'information_id=' . $information_id),
'separator' => $this->language->get('text_separator')
);
$this->document->setTitle($this->language->get('text_error'));
$this->data['heading_title'] = $this->language->get('text_error');
$this->data['text_error'] = $this->language->get('text_error');
$this->data['button_continue'] = $this->language->get('button_continue');
$this->data['continue'] = $this->url->link('common/home');
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());
}
}
public function info() {
$this->load->model('catalog/information');
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
} else {
$information_id = 0;
}
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$output = '<html dir="ltr" lang="en">' . "\n";
$output .= '<head>' . "\n";
$output .= ' <title>' . $information_info['title'] . '</title>' . "\n";
$output .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
$output .= ' <meta name="robots" content="noindex">' . "\n";
$output .= '</head>' . "\n";
$output .= '<body>' . "\n";
$output .= ' <h1>' . $information_info['title'] . '</h1>' . "\n";
$output .= html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8') . "\n";
$output .= ' </body>' . "\n";
$output .= '</html>' . "\n";
$this->response->setOutput($output);
}
}
}
?>

Error occurs with while Loop PHP / MySQL NuSOAP

I have created a PHP / MySQL based web service. I wrote client.php as mentioned here
and server.php as below:
<?php
require_once("lib/nusoap.php");
$host = $_SERVER['HTTP_HOST'];
$miURL = 'http://'.$host.'/WS-Demo';
$server = new nusoap_server();
$server->configureWSDL('L3M_WebService', $miURL);
$server->wsdl->schemaTargetNamespace=$miURL;
$server->register('getDemoData',
array('fldpara' => 'xsd:Array', 'tblpara' => 'xsd:Array', 'cndpara' => 'xsd:Array'),
array('return' => 'xsd:string'),
$miURL);
function decryptRJ256($string_to_decrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$string_to_decrypt = base64_decode($string_to_decrypt);
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
$rtn = rtrim($rtn, "\4");
return($rtn);
}
function encryptRJ256($string_to_encrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
$rtn = base64_encode($rtn);
return($rtn);
}
function getDemoData($flds, $tbls, $cnds){
$mysqli = new mysqli("localhost", "root", "", "test");
for($i=0;$i< count($flds); $i++) {
$flds[$i] = decryptRJ256($flds[$i]);
}
for($i=0;$i< count($tbls); $i++) {
$tbls[$i] = decryptRJ256($tbls[$i]);
}
for($i=0;$i< count($cnds); $i++) {
$cnds[$i] = decryptRJ256($cnds[$i]);
}
if(! empty($flds)) {
$what = implode(", ", $flds);
} else {
$what = "*";
}
if(! empty($tbls)) {
$from = implode(", ", $tbls);
}else {
$err = 1;
}
if(! empty($cnds)) {
$cond = " WHERE ";
$cond .= $cnds[0] . " = '" . $cnds[1] . "'";
} else {
$cond = "";
}
$sql = "SELECT ".$what." FROM ".$from . $cond;
$rsGetData = $mysqli->query($sql);
$responseData = '<?xml version="1.0" encoding="UTF-8"?>
<L3MDataSets>';
while($rowGetData = $rsGetData->fetch_assoc()) {
$responseData .= '<L3DataSet>';
foreach($rowGetData as $k => $v) {
$responseData .= '<' . $k . '>' . $v . '</' . $k . '>';
}
$responseData .= '</L3DataSet>';
}
$responseData .= '</L3MDataSets>';
$responseData = encryptRJ256($responseData);
$responseString = new soapval('return', 'xsd:string', $responseData );
return $responseData;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
From the Above code in the getDemoData function, if I remove the while loop, it gives the proper output. But when I put back the while loop it shows me output as "-Error: Response not of type text/xml: text/html" even if the SQL query is correct. I have copied and paste the generated SQL query which works in phpMyAdmin.

opencart site upgrade from version1.4.x to 1.5.x

I have upgrade my opencart site version 1.4.9.2 to version1.5.X,
I upgrade the database but don't know how to upgrade the files.
If there is any script regarding this please send me.
I use the script to update the table:-
<?php
# Upgrade Script Beta v2
// Run full install if config doesn't exist
if (!file_exists('../config.php')) {
header('Location: ./index.php');
exit;
}
set_error_handler("myErrorHandler");
// Configuration
require_once('../config.php');
// Startup
require_once(DIR_SYSTEM . 'startup.php');
// Get Path & Url
$errors = array();
$baseurl=(isset($_SERVER['HTTPS']) ? 'https' :'http'). '://' . $_SERVER['HTTP_HOST'] . str_replace('/install','',dirname($_SERVER['REQUEST_URI']));
chdir('..');
$basepath=getcwd();
chdir(dirname(__FILE__));
if (!$link = #mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD)) {
$errors[] = 'Could not connect to the database server using the username and password provided.';
} else {
if (!#mysql_select_db(DB_DATABASE, $link)) {
$errors[] = 'The database could selected, check you have permissions, and check it exists on the server.';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Installation</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>OpenCart 1.x Upgrade Script (BETA)</h1>
<div id="container">
<?php
function myErrorHandler($errno, $errstr, $errfile, $errline) {
echo "LINE $errline: [$errno] $errstr<br/>";
return;
}
if (empty($errors)) {
// Run upgrade script
$file='upgrade-14x-to-15x.no-opt.sql';
if (!file_exists($file)) {
$errors[] = 'Upgrade SQL file '.$file.' could not be found.';
} else {
mysql_query('set character set utf8', $link);
if ($sql=file($file)) {
$query = '';
foreach($sql as $line) {
// Hacks for compatibility (needs to be improved)
$line = str_replace("oc_", DB_PREFIX, $line);
$line = str_replace(" order ", " `order` ", $line);
$line = str_replace(" ssl ", " `ssl` ", $line);
$line = str_replace("NOT NULL DEFAULT ''", "NOT NULL", $line);
$line = str_replace("NOT NULL DEFAULT NULL", "NOT NULL", $line);
$line = str_replace("NOT NULL DEFAULT 0 COMMENT '' auto_increment", "NOT NULL COMMENT '' auto_increment", $line);
$line = trim($line);
//$line = str_replace(";", "", $line);
if ((substr(trim($line), 0, 2) == '--') || (substr(trim($line), 0, 1) == '#')) { continue; }
if (preg_match('/^ALTER TABLE (.+?) ADD PRIMARY KEY/', $line, $matches)) {
$res = mysql_query(sprintf("SHOW KEYS FROM %s",$matches[1]), $link);
$info = mysql_fetch_assoc(mysql_query(sprintf("SHOW KEYS FROM %s",$matches[1]), $link));
if ($info['Key_name'] == 'PRIMARY') { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) ADD (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) > 0) { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) DROP (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) <= 0) { continue; }
}
if (preg_match('/INNER JOIN (.+?) /', $line, $matches)) {
$xx = #mysql_query(sprintf("SHOW TABLES LIKE '%s'", str_replace('`', '', $matches[1])), $link);
if ($xx && mysql_num_rows($xx) <= 0) { continue; }
}
if (preg_match('/^DROP TABLE (.+?);/', $line, $matches)) {
if (preg_match('/^DROP TABLE IF EXISTS (.+?);/', $line, $matches2)) {
//if (mysql_num_rows(#mysql_query(sprintf("DESC %s", str_replace('`', '', $matches2[1])), $link)) <= 0) { continue; }
} else {
if (mysql_num_rows(#mysql_query(sprintf("SHOW TABLES LIKE '%s'", str_replace('`', '', $matches[1])), $link)) <= 0) { continue; }
}
}
if (strpos($line, 'ALTER TABLE') !== FALSE && strpos($line, 'DROP') !== FALSE && strpos($line, 'PRIMARY') === FALSE) {
$params = explode(' ', $line);
if ($params[3] == 'DROP') {
if (mysql_num_rows(#mysql_query("SHOW COLUMNS FROM $params[2] LIKE '$params[4]'", $link)) <= 0) { continue; }
}
}
if (preg_match('/^ALTER TABLE ([^\s]+) DEFAULT (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW TABLES LIKE '%s'", str_replace('`', '', $matches[1])), $link)) <= 0) { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) MODIFY (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) <= 0) { continue; }
}
if (preg_match('/^ALTER TABLE (.+?) CHANGE (.+?) (.+?) /', $line, $matches)) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[2])), $link)) <= 0) {
continue;
}
// if it does exist, be sure the new name doesn't also exist. If so, then just delete it.
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $matches[3])), $link)) > 0) {
#mysql_query(sprintf("ALTER TABLE %s DROP %s", $matches[1], str_replace('`', '', $matches[2])), $link); //Drop the column if it was supposed to be changed to a column that already exists
continue;
}
}
if (preg_match('/^DELETE FROM (.+?) WHERE (.+?) /', $line, $matches)) {
if (preg_match('~ WHERE (.*);$~', $line, $matches2)) {
if (preg_match_all('~`([^`]+)`~', $matches2[1], $matched)) {
$notfound = 0;
foreach ($matched[1] as $m) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1],str_replace('`', '', $m)), $link)) <= 0) {
$notfound++;
}
}
if ($notfound) { continue; }
}
}
}
if (preg_match('/^INSERT INTO (.+?) \(([^)]+)\) /', $line, $matches)) {
$parts = explode(",", str_replace("`", "", $matches[2]));
$notfound = 0;
foreach ($parts as $m) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[1], trim($m)), $link)) <= 0) {
$notfound++;
}
}
if ($notfound) { continue; }
}
if (preg_match('/^INSERT INTO (.+?) \(([^)]+)\) SELECT ([^FROM]+) FROM `([^`]+)`/', $line, $matches)) {
$parts = explode(",", str_replace("`", "", $matches[3]));
$notfound = 0;
foreach ($parts as $m) {
if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'", $matches[4], trim($m)), $link)) <= 0) {
$notfound++;
}
}
if ($notfound) { continue; }
}
//if (preg_match('/^ALTER TABLE (.+?) DEFAULT (.+?) /',$line,$matches)) {
// if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'",$matches[1],str_replace('`','',$matches[2])), $link)) <= 0) { continue; }
//}
//if (preg_match('/^ALTER TABLE (.+?) ALTER (.+?) /',$line,$matches)) {
// if (mysql_num_rows(#mysql_query(sprintf("SHOW COLUMNS FROM %s LIKE '%s'",$matches[1],str_replace('`','',$matches[2])), $link)) <= 0) { continue; }
//}
if (!empty($line)) {
$query .= $line;
if (preg_match('/;\s*$/', $line)) {
if (mysql_query($query, $link) === false) {
$errors[] = 'Could not execute this query: ' . $query . ' ' . mysql_error($link);
}
$query = '';
}
}
}
}
}
}
// Check if there are any products associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "product_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT product_id FROM " . DB_PREFIX . "product", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $product) {
mysql_query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '".$product['product_id']."', store_id = '0'", $link);
}
}
// Check if there are any informations associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "information_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT information_id FROM " . DB_PREFIX . "information", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $information) {
mysql_query("INSERT INTO " . DB_PREFIX . "information_to_store SET information_id = '".$information['information_id']."', store_id = '0'", $link);
}
}
// Check if there are any categories associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "category_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT category_id FROM " . DB_PREFIX . "category", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $category) {
mysql_query("INSERT INTO " . DB_PREFIX . "category_to_store SET category_id = '".$category['category_id']."', store_id = '0'", $link);
}
}
// Check if there are any manufacturers associated with a store (pre-1.4.1)
$info = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "manufacturer_to_store", $link));
// If not, then add them all to the default
if (!$info) {
$resource = mysql_query("SELECT manufacturer_id FROM " . DB_PREFIX . "manufacturer", $link);
$data = array();
$i = 0;
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
foreach ($data as $manufacturer) {
mysql_query("INSERT INTO " . DB_PREFIX . "manufacturer_to_store SET manufacturer_id = '".$manufacturer['manufacturer_id']."', store_id = '0'", $link);
}
}
######################################
# START 1.5.x UPGRADE CODE
######################################
/**
* Convert Store table to Setting table
*/
$sql = "SELECT * FROM " . DB_PREFIX . "store";
$resource = mysql_query($sql, $link);
if ($resource) {
if (is_resource($resource)) {
$i = 0;
$data = array();
while ($result = mysql_fetch_assoc($resource)) {
$data[$i] = $result;
$i++;
}
mysql_free_result($resource);
}
}
// Only run if coming from 1.4.x to 1.5.x. Skip if coming from another 1.5.x version
if ($data && isset($data[0]['zone_id'])) {
$storedata = array();
foreach ($data as $d) {
$storedata[$d['store_id']] = $d;
unset($storedata[$d['store_id']]['store_id']);
}
foreach ($storedata as $store_id => $value) {
// Verify the store id doesn't already exist
$qry = mysql_fetch_assoc(mysql_query("SELECT * FROM " . DB_PREFIX . "setting WHERE store_id = '" . (int)$store_id . "'", $link));
if ($qry) { continue; }
// New store fields
if (!isset($value['address'])) { $value['address'] = '' ;}
if (!isset($value['email'])) { $value['email'] = '' ;}
if (!isset($value['telephone'])) { $value['telephone'] = '' ;}
if (!isset($value['fax'])) { $value['fax'] = '' ;}
if (!isset($value['layout'])) { $value['layout'] = '' ;}
if (!isset($value['image_compare_height'])) { $value['image_compare_height'] = '' ;}
if (!isset($value['image_compare_width'])) { $value['image_compare_width'] = '' ;}
if (!isset($value['image_manufacturer_height'])) { $value['image_manufacturer_height'] = '' ;}
if (!isset($value['image_manufacturer_width'])) { $value['image_manufacturer_width'] = '' ;}
if (!isset($value['image_wishlist_height'])) { $value['image_wishlist_height'] = '' ;}
if (!isset($value['image_wishlist_width'])) { $value['image_wishlist_width'] = '' ;}
// special case
if (!isset($value['use_ssl'])) { $value['use_ssl'] = $value['ssl'] ;}
if (!isset($value['ssl'])) {
if ($value['use_ssl']) {
$value['ssl'] = str_replace('http://', 'https://', $value['url']);
} else {
$value['ssl'] = $value['url'];
}
mysql_query("INSERT INTO " . DB_PREFIX . "store SET `ssl` = '" . $value['ssl'] . "' WHERE store_id = '" . (int)$store_id . "', `group` = 'config'", $link);
}
foreach ($value as $k => $v) {
mysql_query("INSERT INTO " . DB_PREFIX . "setting SET `key` = 'config_" . $k . "', `value` = '" . $v . "', store_id = '" . (int)$store_id . "', `group` = 'config'", $link);
}
}
$sql = "ALTER TABLE `" . DB_PREFIX . "store`
DROP `title`,
DROP `meta_description`,
DROP `template`,
DROP `country_id`,
DROP `zone_id`,
DROP `language`,
DROP `currency`,
DROP `tax`,
DROP `customer_group_id`,
DROP `customer_price`,
DROP `customer_approval`,
DROP `guest_checkout`,
DROP `account_id`,
DROP `checkout_id`,
DROP `stock_display`,
DROP `stock_check`,
DROP `stock_checkout`,
DROP `order_status_id`,
DROP `logo`,
DROP `icon`,
DROP `image_thumb_width`,
DROP `image_thumb_height`,
DROP `image_popup_width`,
DROP `image_popup_height`,
DROP `image_category_width`,
DROP `image_category_height`,
DROP `image_product_width`,
DROP `image_product_height`,
DROP `image_additional_width`,
DROP `image_additional_height`,
DROP `image_related_width`,
DROP `image_related_height`,
DROP `image_cart_width`,
DROP `image_cart_height`,
DROP `catalog_limit`,
DROP `cart_weight`,
AUTO_INCREMENT=1;";
mysql_query($sql, $link);
}
/**
* Convert Options to Global Options
*/
/*
# Convert options over.. big job
ALTER TABLE `oc_order_option`
ADD `product_option_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER order_product_id,
ADD `type` varchar(32) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER value,
MODIFY `value` text NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin,
DROP `price`,
DROP `prefix`;
ALTER TABLE `oc_product_option`
ADD `option_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER product_id,
ADD `option_value` text NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER option_id,
ADD `required` int(1) NOT NULL DEFAULT 0 COMMENT '' AFTER option_value,
DROP `sort_order`;
DROP TABLE `oc_product_option_description`;
ALTER TABLE `oc_product_option_value`
ADD `option_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER product_id,
ADD `option_value_id` int(11) NOT NULL DEFAULT 0 COMMENT '' AFTER option_id,
ADD `price_prefix` varchar(1) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER price,
ADD `points` int(8) NOT NULL DEFAULT 0 COMMENT '' AFTER price_prefix,
ADD `points_prefix` varchar(1) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER points,
ADD `weight` decimal(15,8) NOT NULL DEFAULT '' COMMENT '' AFTER points_prefix,
ADD `weight_prefix` varchar(1) NOT NULL DEFAULT '' COMMENT '' COLLATE utf8_bin AFTER weight,
MODIFY `quantity` int(3) NOT NULL DEFAULT 0 COMMENT '',
ALTER `subtract` DROP DEFAULT,
DROP `prefix`,
DROP `sort_order`;
DROP TABLE `oc_product_option_value_description`;
write this back to the config.php
// HTTP
define('HTTP_SERVER', 'http://localhost/v150/');
define('HTTP_IMAGE', 'http://localhost/v150/image/');
define('HTTP_ADMIN', 'http://localhost/v150/admin/');
// HTTPS
define('HTTPS_SERVER', 'http://localhost/v150/');
define('HTTPS_IMAGE', 'http://localhost/v150/image/');
*/
if (!empty($errors)) { //has to be a separate if
?>
<p>The following errors occured:</p>
<?php foreach ($errors as $error) {?>
<div class="warning"><?php echo $error;?></div><br />
<?php } ?>
<p>The above errors occurred because the script could not properly determine the existing state of those db elements. Your store may not need those changes. Please post any errors on the forums to ensure that they can be addressed in future versions!</p>
</div>
<?php } else { ?>
<h2>SUCCESS!!! Click here to goto your store</h2>
<?php } ?>
<div class="center">OpenCart.com</div>
</body>
</html>
Please try this script. Instructions also available. http://forum.opencart.com/viewtopic.php?t=50292
I dont know a script that is able to update the Opencart files. You simply need to empty your FTP and upload the 1.5.x package. If you're using any (custom) modules, you'll need to re-install them. But be carefull, because modules developed for 1.4.x are not automatically compatible with 1.5.x.