I have installed the SSL on my OpenCart project all the page are running on https except category and product pages it's running on httpss?
"Failed to load resource: net::ERR_UNKNOWN_URL_SCHEME
Mixed Content: The page at
'https://www.xxxyyzz.in/index.php?route=product/category&path=59_60'
was loaded over HTTPS, but requested an insecure image
'httpss://www.xxxyyzz.in/image/catalog/AjaxLoader.gif'. This content
should also be served over HTTPS."
only on my category pages all the links are runs over httpss i dont where can i change?
class ControllerProductCategory extends Controller {
public function index() {
$this->load->language('product/category');
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
if (isset($this->request->get['filter'])) {
$filter = $this->request->get['filter'];
} else {
$filter = '';
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
if (isset($this->request->get['limit'])) {
$limit = (int)$this->request->get['limit'];
} else {
$limit = $this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit');
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
if (isset($this->request->get['path'])) {
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$path = '';
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
foreach ($parts as $path_id) {
if (!$path) {
$path = (int)$path_id;
} else {
$path .= '_' . (int)$path_id;
}
$category_info = $this->model_catalog_category->getCategory($path_id);
if ($category_info) {
$data['breadcrumbs'][] = array(
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $path . $url)
);
}
}
} else {
$category_id = 0;
}
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$this->document->setTitle($category_info['meta_title']);
$this->document->setDescription($category_info['meta_description']);
$this->document->setKeywords($category_info['meta_keyword']);
$data['heading_title'] = $category_info['name'];
$data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
// Set the last category breadcrumb
$data['breadcrumbs'][] = array(
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'])
);
if ($category_info['image']) {
$data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_category_height'));
} else {
$data['thumb'] = '';
}
$data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
$data['compare'] = $this->url->link('product/compare');
$url = '';
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['categories'] = array();
$results = $this->model_catalog_category->getCategories($category_id);
foreach ($results as $result) {
$filter_data = array(
'filter_category_id' => $result['category_id'],
'filter_sub_category' => true
);
$data['categories'][] = array(
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
);
}
$data['products'] = array();
$filter_data = array(
'filter_category_id' => $category_id,
'filter_filter' => $filter,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
$text_percent = '';
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
$price_num = $this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'));
} else {
$price = false;
$price_num= false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
$special_num = $this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'));
} else {
$special = false;
$special_num = false;
}
if ($special_num && $price_num) {
$percent = round(($price_num-$special_num)/$price_num*100,0);
$text_percent = sprintf($this->language->get('text_label_sale'), $percent);
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'text_percent' => $text_percent,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
}
$url = '';
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['sorts'] = array();
$data['sorts'][] = array(
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=ASC' . $url)
);
$data['sorts'][] = array(
'text' => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=DESC' . $url)
);
$url = '';
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['limits'] = array();
$limits = array_unique(array($this->config->get('theme_' . $this->config->get('config_theme') . '_product_limit'), 25, 50, 75, 100));
sort($limits);
foreach($limits as $value) {
$data['limits'][] = array(
'text' => $value,
'value' => $value,
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=' . $value)
);
}
$url = '';
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
// http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
if ($page == 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id']), 'canonical');
} else {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
}
if ($page > 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . (($page - 2) ? '&page='. ($page - 1) : '')), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1)), 'next');
}
$data['sort'] = $sort;
$data['order'] = $order;
$data['limit'] = $limit;
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('product/category', $data));
} else {
$url = '';
if (isset($this->request->get['path'])) {
$url .= '&path=' . $this->request->get['path'];
}
if (isset($this->request->get['filter'])) {
$url .= '&filter=' . $this->request->get['filter'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_error'),
'href' => $this->url->link('product/category', $url)
);
$this->document->setTitle($this->language->get('text_error'));
$data['continue'] = $this->url->link('common/home');
$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('error/not_found', $data));
}
}
}
My version: 3.0.3.3
Access the path:
storage/modification/catalog/controller/product
Search this or similar:
$base_url = str_replace('http', 'https', $this->config->get('config_url'));
Add after this line:
$base_url = str_replace('httpss', 'https', $base_url);
I use an html string in php to display sql query results in a single column:
How can I use multiple columns to lay it out like this:
while($row = mysqli_fetch_array($q)){
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
$link = $row['link'];
$output .= '<a href="' . $link . '">
<h3>' . $title . '</h3>
<p>' . $desc . '</p>
</a>';
}
Credit to hungrykoala for help on this one
$i = 0 ;
$resultsPerRow = 2 ;
$output = '<tr>';
while($row = mysqli_fetch_array($q)){
$i++;
$id = $row['id'];
$title = $row['title'];
$desc = $row['description'];
$link = $row['link'];
$output .= '<td>' .$title. '<br>' .$desc. '</td>';
if ($i % $resultsPerRow == 0) {
$output .= '</tr><td><br></td><tr>';
}
}
echo($output);
Then output to a table tag
I have a good result using PDO query retrieve all data from database.
But, this only display the result with LIMIT like 10.
My questions now is how to paste this result for paginate?
I want to set result for 10 perpage and have prev 1 2 3 4 next for all data.
below script is good and fast result for me.
<?php
//load database connection
$host = "localhost";
$user = "root";
$password = "";
$database_name = "";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
// Search from MySQL database table
$search=$_POST['search'];
$query = $pdo->prepare("select * from table where colum1 LIKE '%$search%' OR colum2 LIKE '%$search%' LIMIT 0 , 10");
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();
// Display search result
if (!$query->rowCount() == 0) {
echo "Search found :<br/>";
echo "<table style=\"font-family:arial;color:#333333;\">";
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Title Books</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Author</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Price</td></tr>";
while ($results = $query->fetch()) {
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['name'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['description'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo "$".$results['thumb'];
echo "</td></tr>";
}
echo "</table>";
} else {
echo 'Nothing found';
}
?>
I would suggest that you create a class for pagination then include the class.
pagination.php
<?php
class paginate
{
private $pdo;
function __construct($pdo)
{
$this->db = $pdo;
}
public function dataview($query,$Search)
{
$stmt = $this->db->prepare($query);
$stmt->execute(arary($Search,$Search));
$results = $stmt->fetchall();
if (count($results) > 0) {?>
Search found : <br/>
<table style="font-family:arial;color:#333333;">";
<tr><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Title Books</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Author</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Price</td></tr>
<?php
foreach ($results as $row):
?>
<tr><td style="border-style:solid;border-width:1px;border-color:#98bf21;">
<?php echo $row['name'];?></td>
<td style="border-style:solid;border-width:1px;border-color:#98bf21;">;
<?php echo $row['description'];?>
</td>
<td style="border-style:solid;border-width:1px;border-color:#98bf21;">
<?php echo $row['thumb'];?>
</td></tr>
<?php
endforeach;
echo "</table>";
} else {
echo "<p> Nothing found </p>";
}
}
public function paging($query, $records_per_page)
{
$starting_position = 0;
if (isset($_GET['page_no'])) {
$starting_position = ($_GET["page_no"] - 1) * $records_per_page;
}
$query2 = $query . " limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query, $records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if ($total_no_of_records > 0) {
?>
<ul class="pagination"><?php
$total_no_of_pages = ceil($total_no_of_records / $records_per_page);
$current_page = 1;
if (isset($_GET["page_no"])) {
$current_page = $_GET["page_no"];
}
if ($current_page != 1) {
$previous = $current_page - 1;
echo "<li><a href='" . $self . "?page_no=1' >First</a></li>";
echo "<li><a href='" . $self . "?page_no=" . $previous . "'>Previous</a></li>";
}
for ($i = 1; $i <= $total_no_of_pages; $i++) {
if ($i == $current_page) {
echo "<li class='active'><a href='" . $self . "?page_no=" . $i . "' >" . $i . "</a></li>";
} else {
echo "<li><a href='" . $self . "?page_no=" . $i . "'>" . $i . "</a></li>";
}
}
if ($current_page != $total_no_of_pages) {
$next = $current_page + 1;
echo "<li><a href='" . $self . "?page_no=" . $next . "'>Next</a></li>";
echo "<li><a href='" . $self . "?page_no=" . $total_no_of_pages . "'>Last</a></li>";
}
?></ul>
<?php
}
}
}
?>
page.php
<?php
//your connection
$host = "localhost";
$user = "root";
$password = "";
$database_name = "";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
include_once'pagination.php';
$paginate = new paginate($pdo);
$search=$_POST['search'];
$Search = "%$search%";
$query = "SELECT * from table where colum1 LIKE ? OR colum2 LIKE ? ";
$records_per_page=10;
$newquery = $paginate->paging($query,$records_per_page,$Search);
$paginate->dataview($newquery,$Search);
$paginate->paginglink($query,$records_per_page);
?>
This should work. Suggestions/comments are welcome.
This is one of the projects I have used the above code to do a pagination :
or use jquery dataTables which will also work perfect
all u need is to download https://datatables.net/
With Datatables, simple download it then add required scripts and css, then on your table add an ID, then initialize datatable
$('#TableID').dataTable();
You might have to do the proper table markup,
<table>
<thead>
<tr>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text</td>
</tr>
</tbody>
I would like to run an update query for every row with a specific ID:
e.g.
$ids = array(111, 112, 113);
$query = "UPDATE mytable SET columnName = 'Y' WHERE id = :id1 or id = :id2 or id = :id3";
$stmt->bindParam(':id1', $ids[0], PDO::PARAM_INT);
$stmt->bindParam(':id2', $ids[1], PDO::PARAM_INT);
$stmt->bindParam(':id3', $ids[2], PDO::PARAM_INT);
This works fine if I know there are 3 ids to update, but how would I do this if the number of id fields is variable?
Something like this would do the trick.
$ids = array(111, 112, 113);
$valueString = "";
foreach($ids as $key => $val) {
$valueString .= ":id" . $key . " = " . $val;
if (end($ids) != $val) {
$valueString .= ", ";
}
}
$query = "UPDATE mytable SET columnName = 'Y' WHERE ". $valueString;
foreach($ids as $key => $val) {
$stmt->bindParam(':id' . $key, $val, PDO::PARAM_INT);
}
Ok, I would like to add one more sort variable on category pages, that is to sort by Manufacturer.
Running on 1.5.3.1 and have tried this:
1. catalog/controller/product/category.php
added the following:
$this->data['sorts'][] = array(
'text' => $this->language->get('text_manufacturer_asc'),
'value' => 'manufacturer-ASC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=manufacturer&order=ASC' . $url)
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_manufacturer_desc'),
'value' => 'manufacturer-DESC',
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=manufacturer&order=DESC' . $url)
);
catalog/language/*/product/category.php
added:
$_['text_manufacturer_asc'] = '▲ -Proizvođaču- ▲';
$_['text_manufacturer_desc'] = '▼ -Proizvođaču- ▼';
catalog/model/catalog/product.php
before: 'p.date_added' I inserted a line:
'manufacturer'
and few lines below I changed the block with the following one:
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
} elseif ($data['sort'] == 'p.price') {
$sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
} elseif ($data['sort'] == 'manufacturer') {
$sql .= " SELECT * FROM". DB_PREFIX . "product p ORDER BY manufacturer";
} else {
$sql .= " ORDER BY " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.sort_order";
}
But it is not working.
Error says:
PHP Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROMproduct p ORDER BY manufacturer ASC,...
and another one I have found:
PHP Notice: Error: Unknown column 'special' in 'order clause'<br />Error No: 1054<br />SELECT p.product_id, (SELECT AVG(rating) AS total FROM review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id)...
Can anybody help?
You are almost there but You will have to modify it a little bit more.
First, You really do not want to order by manufacturer ID stored in product.manufacturer_id but by manufacturer name. In this case we need to modify the query in catalog\model\catalog\product.php model in getProducts method - find this line:
$sql .= " 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) WHERE 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') . "'";
(should be line 89 in OC 1.5.5.1) and before it add:
$sql .= " LEFT JOIN " . DB_PREFIX . "manufacturer m ON p.manufacturer_id = m.manufacturer_id";
Also You'll need to allow manufacturer as a sorting option:
$sort_data = array(
'pd.name',
'p.model',
'p.quantity',
'p.price',
'rating',
'p.sort_order',
'p.date_added',
'manufacturer', // <== this is added
);
Now in the sorting section add sorting by manufacturer name:
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
$sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
} elseif ($data['sort'] == 'p.price') {
$sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
} elseif ($data['sort'] == 'manufacturer') { // <== this is added
$sql .= " ORDER BY m.name"; // <== this is added
} else {
$sql .= " ORDER BY " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.sort_order";
}
And that's it.