I'm really confused as to why the sort order isn't part of the category instead.
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
I've found these old things -
https://www.opencart.com/index.php?rout ... n_id=14137
https://www.youtube.com/watch?v=owyY7LSyYfI
So now I'm poking around in the code. Can anyone save me some time and tell me what file returns the sort order?
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
/var/www/html/catalog/model/catalog/product.php
public function getProducts($data = array())
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
in 2012 on youtube?it seems this question has come up quite a few times
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Search and you will find more. Still no solution? Seems like major platform problem for big stores. I'll try and come up with some hacks, but it'd be nice to know if this is going to be fixed.
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
My guess is that's why nobody bothered.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
As I mentioned before, OC is making me learn PHP, I'm usually using Perl. I couldn't seem to get one value from the sql query, so there's an unneeded foreach loop, but since it only ever loops once it's not a major problem. If someone knows the proper code, I'd like to see it to understand it. ---- No idea how to make extensions yet, so here's the code.
Code: Select all
// ######################################################################################################
// ## START: New sort code that looks for a meta tag in the section description to sort the products.
// ## Put in the category description via the admin panel source view. Note you must unview source view
// ## for it to save in the admin panel.
// ## <meta name="sortorder" content="21536,16146,16133">
// ######################################################################################################
$sortflag = 0;
if ( (isset($data['sort']) && in_array($data['sort'], $sort_data) && ($data['sort'] == 'p.sort_order')) || !(isset($data['sort']) && in_array($data['sort'], $sort_data)) ){
$description = '';
$sortordersql = "select description from oc_category_description where category_id=".$data['filter_category_id']." limit 1";
$query = $this->db->query($sortordersql);
foreach ($query->rows as $result) {
$description = $result['description'];
}
$pattern = '/<meta.*?name="sortorder".*?content="(.*)?">/i';
$matches = array();
$sortorder = '';
if ( preg_match($pattern, $description, $matches) ){
$sortorder = $matches[1];
}
if(!empty($sortorder)){
$sql .= " ORDER BY IF(FIELD(p.product_id,$sortorder)=0,1,0),FIELD(p.product_id,$sortorder)";
$sortflag = 1;
}
}
if (!$sortflag) {
// ##################################################################################
// ## START: Original unmodified sorting code
// ##################################################################################
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)";
} else {
$sql .= " ORDER BY " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.sort_order";
}
// ##################################################################################
// ## END: Original unmodified sorting code
// ##################################################################################
}
// ######################################################################################################
// ## END: New sort code that looks for a meta tag in the section description to sort the products.
// ######################################################################################################
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
EDIT: Here is the code using a comment tag instead of a meta tag
Code: Select all
// ######################################################################################################
// ## START: New sort code that looks for a meta tag in the section description to sort the products.
// ## Put in the category description via the admin panel source view. Note you must unview source view
// ## for it to save in the admin panel.
// ## <!-- name="sortorder" content="21536,16146,16133" -->
// ######################################################################################################
$sortflag = 0;
if ( (isset($data['sort']) && in_array($data['sort'], $sort_data) && ($data['sort'] == 'p.sort_order')) || !(isset($data['sort']) && in_array($data['sort'], $sort_data)) ){
$description = '';
$sortordersql = "select description from oc_category_description where category_id=".$data['filter_category_id']." limit 1";
$query = $this->db->query($sortordersql);
foreach ($query->rows as $result) {
$description = $result['description'];
}
$pattern = '/<!--.*?name="sortorder".*?content="(.*)?".*?-->/i';
$matches = array();
$sortorder = '';
if ( preg_match($pattern, $description, $matches) ){
$sortorder = $matches[1];
}
if(!empty($sortorder)){
$sql .= " ORDER BY IF(FIELD(p.product_id,$sortorder)=0,1,0),FIELD(p.product_id,$sortorder)";
$sortflag = 1;
}
}
if (!$sortflag) {
// ##################################################################################
// ## START: Original unmodified sorting code
// ##################################################################################
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)";
} else {
$sql .= " ORDER BY " . $data['sort'];
}
} else {
$sql .= " ORDER BY p.sort_order";
}
// ##################################################################################
// ## END: Original unmodified sorting code
// ##################################################################################
}
// ######################################################################################################
// ## END: New sort code that looks for a meta tag in the section description to sort the products.
// ######################################################################################################
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
<meta name="sortorder" content="21536,16146,16133">
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Yes, change "21536,16146,16133" to whatever id's you're using. It will sort the id's there first, skip any numbers that aren't in the category, and list whatever isn't listed in the sort order after.
Working example here (although this link will not be the same in a few days) -
http://carguygarage.org/index.php?route ... 5053_34518
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
Still, if you have the product_id's at hand, I would simply create a table with category_id and product sort order, import the product_id's and use those entries while doing the query sort.
category_id
24
product_sort
21536,16146,16133
category_id
46
product_sort
x,y,x
then you can later add a nice admin interface to it.
saves you a huge meta tag if your category gets larger.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
/var/www/html/catalog/model/catalog/catalog.php
change this function
Code: Select all
public function getCategories($parent_id = 0) {
$sqlquery = "SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND c.status = '1' ";
$description = '';
$sortordersql = "select description from oc_category_description where category_id=".$parent_id." limit 1";
$query = $this->db->query($sortordersql);
foreach ($query->rows as $result) {
$description = $result['description'];
}
$pattern = '/<!--.*?name="sortorder".*?content="(.*)?".*?-->/i';
$matches = array();
$sortorder = '';
if ( preg_match($pattern, $description, $matches) ){
$sortorder = $matches[1];
}
;
if(!empty($sortorder)){
$sqlquery .= " ORDER BY IF(FIELD(c.category_id,$sortorder)=0,1,0),FIELD(c.category_id,$sortorder)";
} else {
$sqlquery .= " ORDER BY c.sort_order, LCASE(cd.name)";
}
$query = $this->db->query($sqlquery);
return $query->rows;
}
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
Code: Select all
INSERT INTO `oc_event` (`code`, `trigger`, `action`, `status`) VALUES ('cgg_product_sort', 'catalog/model/catalog/product/getProducts/after', 'extension/module/cgg_product_sort/cggProductSort', 1);
Code: Select all
<?php
class ControllerExtensionModulecggProductSort extends Controller {
public function cggProductSort(&$route, &$args, &$output) {
ob_start();
var_dump($route);
$dump_route = ob_get_clean();
ob_start();
var_dump($args);
$dump_args = ob_get_clean();
ob_start();
var_dump($output);
$dump_output = ob_get_clean();
ob_start();
var_dump($this);
$data_dump = ob_get_clean();
$data_dump = "ROUTE:\n$dump_route\n\nARGS:\n$dump_args\n\nOUTPUT:\n$dump_output";
file_put_contents('/var/www/html/test.txt', $data_dump );
}
}
Jim
https://www.carguygarage.com
Yahoo Store since 2006 moved to OpenCart on January 24, 2020
https://www.opencart.com/index.php?rout ... 751&page=8
Works like a dream
Users browsing this forum: No registered users and 212 guests