Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Categories are alphabetized in x-cart 4.0

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 07-28-2004, 03:15 AM
 
TeeJay TeeJay is offline
 

Advanced Member
  
Join Date: Oct 2002
Location: UK
Posts: 85
 

Default Categories are alphabetized in x-cart 4.0

I need my categories to be sorted by the position number and not alphabetically (the default).
I cannot find a setting for this anywhere in admin ?

Upgrading to x-cart version 4.0

Any ideas

Thanks
__________________
X-Cart 4.0

Windoze XP Pro
Sick and tired of figuring out code just wanna get on with my life and selling my goods, it\'s raining here too
Reply With Quote
  #2  
Old 07-28-2004, 03:22 AM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

here you go,

this was the last post before yours

http://forum.x-cart.com/viewtopic.php?t=11876&highlight=
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #3  
Old 07-28-2004, 04:29 AM
 
TeeJay TeeJay is offline
 

Advanced Member
  
Join Date: Oct 2002
Location: UK
Posts: 85
 

Default

Thanks for the quick response Shan
I haven't tried to apply any patches before and I'm having problems doing so.....

I copied the patch text from the post you linked to into notepad and saved it on my local machine (Windows XP Pro) as below.

Quote:
Index: include/categories.php
================================================== =================
retrieving revision 1.64
diff -u -r1.64 categories.php
--- include/categories.php 12 Jul 2004 06:50:34 -0000 1.64
+++ include/categories.php 19 Jul 2004 07:11:25 -0000
@@ -63,11 +63,13 @@
global $user_account;
$customer_search_condition = " AND avail='Y' AND (membership='".addslashes($user_account["membership"])."' OR membership='')";
$search_condition .= $customer_search_condition;
- if ($flag == "all" || $flag == NULL)
+ if ($flag == "all")
$sort_condition = " ORDER BY category";
else
$sort_condition = " ORDER BY order_by, category";
}
+ elseif (defined('MANAGE_CATEGORIES'))
+ $sort_condition = " ORDER BY category, order_by";

if ($short_list)
$to_search = "categoryid,parentid,categoryid_path,category,prod uct_count,avail,order_by";

I then tried to apply the patch from the admin area and got this result:

Quote:
Checking patch.pl permissions: /home/*********/public_html/patch.pl ... OK

File Status
include/categories.php could not patch


Status legend:
OK - file ready to patch,
checksum error - patch contents is corrupted,
non-writable - please give those files a write permissions,
not a file - the target is not a file,
not exists - file is missing,
could not patch - patch cannot be applied to this file automatically because it was significantly modified, the patch for this file should be applied manually,
already patched - file was already patched.

Any ideas on this (I have tried searching for "applying patches")
__________________
X-Cart 4.0

Windoze XP Pro
Sick and tired of figuring out code just wanna get on with my life and selling my goods, it\'s raining here too
Reply With Quote
  #4  
Old 07-28-2004, 04:31 AM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

you could do the patch by hand or wait for the official upgrade to 4.0.1 to come out. should be any day soon
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
  #5  
Old 07-28-2004, 04:38 AM
 
TeeJay TeeJay is offline
 

Advanced Member
  
Join Date: Oct 2002
Location: UK
Posts: 85
 

Default

Thanks Shan
I'd attempt to manual change it as I'm now stuck it this point and and cannot continue with much else until it's resolved.
Trouble is I can't make head nor tail of the patch text and what to alter etc.
If anyone wants to help here is my original categories script

Quote:
<?php
/************************************************** ***************************\
+-----------------------------------------------------------------------------+
| X-Cart |
| Copyright (c) 2001-2004 Ruslan R. Fazliev <rrf@rrf.ru> |
| All rights reserved. |
+-----------------------------------------------------------------------------+
| PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php |
| |
| THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. |
| FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING |
| AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). |
| PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT |
| CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, |
| COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY |
| (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS |
| LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS |
| AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND |
| OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE |
| THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. |
| |
| The Initial Developer of the Original Code is Ruslan R. Fazliev |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2004 |
| Ruslan R. Fazliev. All Rights Reserved. |
+-----------------------------------------------------------------------------+
\************************************************* ****************************/

#
# $Id: categories.php,v 1.64 2004/07/12 06:50:34 max Exp $
#

if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }

#
# Functions definition
#

#
# This function builds the categories list within specified category ($cat)
#
function func_get_categories_list($cat=0, $short_list=true, $flag=NULL) {
global $current_area, $sql_tbl, $shop_language;

$cat = intval($cat);

$all_categories = array();
$categories = array();
$subcategories = array();

$search_condition = "1";

if ($flag == "root")
$search_condition .= " AND parentid='0'";
elseif ($flag == "level")
$search_condition .= " AND parentid='$cat'";

if ($current_area == "C") {
global $user_account;
$customer_search_condition = " AND avail='Y' AND (membership='".addslashes($user_account["membership"])."' OR membership='')";
$search_condition .= $customer_search_condition;
if ($flag == "all" || $flag == NULL)
$sort_condition = " ORDER BY category";
else
$sort_condition = " ORDER BY order_by, category";
}

if ($short_list)
$to_search = "categoryid,parentid,categoryid_path,category,prod uct_count,avail,order_by";
else
$to_search = "*";

if (defined('NEED_PRODUCT_CATEGORIES')) {
global $productid;
$to_search = explode(",", $to_search);
foreach ($to_search as $k=>$v)
$to_search[$k] = $sql_tbl["categories"].".".$v;
$to_search = implode(",", $to_search);
$_categories = func_query("SELECT $to_search, $sql_tbl[products_categories].productid, $sql_tbl[products_categories].main FROM $sql_tbl[categories] LEFT JOIN $sql_tbl[products_categories] ON $sql_tbl[categories].categoryid=$sql_tbl[products_categories].categoryid AND $sql_tbl[products_categories].productid='$productid' GROUP BY $sql_tbl[categories].categoryid");
}
else
$_categories = func_query("SELECT $to_search FROM $sql_tbl[categories] WHERE ".$search_condition.$sort_condition);

if (is_array($_categories)) {

$_category_names = array();
if ($flag == "all" || $flag == NULL) {
foreach ($_categories as $k=>$v) {
$_category_names[$v["categoryid"]] = $v["category"];
}
}

foreach ($_categories as $k=>$category) {

if ($flag == "all" || $flag == NULL) {
#
# Get the full path for category name
#
$path = explode("/", $category["categoryid_path"]);
$category_path = array();
$continue = false;
foreach ($path as $i=>$catid) {
if (empty($_category_names[$catid])) {
$continue = true;
break;
}
$category_path[] = $_category_names[$catid];
}
if ($continue)
continue;
$category["category_path"] = implode("/",$category_path);

}

if ($current_area == "C") {
#
# Get the international category name
#
$int_res = func_query_first("SELECT category FROM $sql_tbl[categories_lng] WHERE code='$shop_language' AND categoryid='$category[categoryid]'");
if (!empty($int_res["category"]))
$category["category"] = $int_res["category"];
}

#
# Count the subcategories for "root" and "level" flag values
#
if ($flag == "level" || $flag == "root" || $flag == NULL)
$category["subcategory_count"] = array_pop(func_query_first("SELECT COUNT(*) FROM $sql_tbl[categories] WHERE 1 $customer_search_condition AND categoryid!='$category[categoryid]' AND categoryid_path LIKE '$category[categoryid_path]/%'"));

$all_categories[] = $category;
if (($flag == "root" || $flag == NULL) && $category["parentid"] == 0)
$categories[] = $category;
if (($flag == "level" || $flag == NULL) && $category["parentid"] == $cat)
$subcategories[] = $category;
}

if (($flag == "all" || $flag == NULL) and !empty($all_categories)) {
function func_categories_sort($a, $b) {
return strcmp($a["category_path"], $b["category_path"]);
}
usort($all_categories, "func_categories_sort");
}
}

$return["all_categories"] = $all_categories;
$return["categories"] = $categories;
$return["subcategories"] = $subcategories;

return $return;
}

#
# This function gathering the current category data
#
function func_get_category_data($cat) {
global $current_area, $sql_tbl, $shop_language;
global $xcart_dir, $current_location, $config;

$cat = intval($cat);

if ($current_area == "C")
$search_condition = "AND avail='Y' AND (membership='".addslashes($user_account["membership"])."' OR membership='')";

$category = func_query_first("SELECT * FROM $sql_tbl[categories] WHERE categoryid='$cat' $search_condition");

if (!empty($category)) {

#
# Get the array of all parent categories
#
$_cat_sequense = explode("/", $category["categoryid_path"]);

#
# Generate category sequence, i.e.
# Books, Books/Poetry, Books/Poetry/Philosophy ...
#
foreach ($_cat_sequense as $k=>$v) {
$_cat_name = array_pop(func_query_first("SELECT category FROM $sql_tbl[categories] WHERE categoryid='$v'"));
if ($current_area == "C") {
#
# Get the international category name for category location
#
$int_res = array_pop(func_query_first("SELECT category FROM $sql_tbl[categories_lng] WHERE code='$shop_language' AND categoryid='$v'"));
if (!empty($int_res["category"]))
$_cat_name = $int_res["category"];
}

$category["category_location"][] = array($_cat_name, "home.php?cat=$v");
}

if ($current_area == "C") {

#
# Check if all parent categories are enabled
#
if (func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[categories] WHERE categoryid IN (".implode(",", $_cat_sequense).") AND avail='N'") > 0) {
return false;
}

#
# Get the international category name and description
#
$int_res = func_query_first("SELECT * FROM $sql_tbl[categories_lng] WHERE code='$shop_language' AND categoryid='$cat'");
if (!empty($int_res["category"])) {
$category["category_name_orig"] = $category["category"];
$category["category"] = $int_res["category"];
}
if (!empty($int_res["description"]))
$category["description"] = $int_res["description"];
}

if ($config["Images"]["icons_location"] == "FS")
$image_field = "image_path";
else
$image_field = "image";

$_cat_sequense = array_reverse($_cat_sequense);
foreach ($_cat_sequense as $k=>$v) {
$category_icon = func_query_first("SELECT $sql_tbl[icons].$image_field, $sql_tbl[categories].image_x, $sql_tbl[categories].image_y FROM $sql_tbl[icons], $sql_tbl[categories] WHERE $sql_tbl[icons].categoryid='$v'");
if (!empty($category_icon[$image_field])) {
$category["image_x"] = $category_icon["image_x"];
$category["image_y"] = $category_icon["image_y"];
break;
}
}

if ($config["Images"]["icons_location"] == "FS") {
#
# Correct the icon URL or path if icon is located in File system
#
$category["image_path"] = $category_icon[$image_field];
if (eregi("^(http|ftp)://", $category["image_path"])) {
# image_path is an URL
$category["icon_url"] = $category["image_path"];
}
elseif (!strncmp($xcart_dir, $category["image_path"], strlen($xcart_dir))) {
# image_path is an locally placed image
$category["icon_url"] = $current_location.substr($category["image_path"], strlen($xcart_dir));
}
}

#
# Count the subcategories
#
$category["subcategory_count"] = array_pop(func_query_first("SELECT COUNT(*) FROM $sql_tbl[categories] WHERE categoryid!='$cat' AND categoryid_path LIKE '$category[categoryid_path]/%' $search_condition"));

return $category;
}

return false;
}

#
# Main code
#

$cat = intval($cat);


if ($cat > 0) {
#
# Get the current category data
#
if ($current_category = func_get_category_data($cat))
$smarty->assign("current_category", $current_category);
else {
if ($current_area == "A") {
$top_message["content"] = func_get_langvar_by_name("msg_category_not_exist") ;
$top_message["type"] = "E";
func_header_location("categories.php");
}
else
func_header_location("home.php");
}
}


#
# Gather the array of categories and extract into separated arrays:
# $all_categories, $categories and $subcategories
#
if ($current_area == "C" or defined('MANAGE_CATEGORIES'))
$_categories = func_get_categories_list($cat);
else
$_categories = func_get_categories_list($cat, true, "all");

extract($_categories);


#
# Prepare data for FancyCategories module
#
if ($current_area == "C" and !empty($active_modules["Fancy_Categories"]))
@include $xcart_dir."/modules/Fancy_Categories/fancy_categories.php";


$smarty->assign("allcategories", $all_categories);

$smarty->assign("categories", $categories);

if ($cat == 0)
$subcategories = $categories;

if (!empty($subcategories))
$smarty->assign("subcategories", $subcategories);

$smarty->assign("cat", $cat);

?>

and here is the patch script...

Quote:
Index: include/categories.php
================================================== =================
retrieving revision 1.64
diff -u -r1.64 categories.php
--- include/categories.php 12 Jul 2004 06:50:34 -0000 1.64
+++ include/categories.php 19 Jul 2004 07:11:25 -0000
@@ -63,11 +63,13 @@
global $user_account;
$customer_search_condition = " AND avail='Y' AND (membership='".addslashes($user_account["membership"])."' OR membership='')";
$search_condition .= $customer_search_condition;
- if ($flag == "all" || $flag == NULL)
+ if ($flag == "all")
$sort_condition = " ORDER BY category";
else
$sort_condition = " ORDER BY order_by, category";
}
+ elseif (defined('MANAGE_CATEGORIES'))
+ $sort_condition = " ORDER BY category, order_by";

if ($short_list)
$to_search = "categoryid,parentid,categoryid_path,category,prod uct_count,avail,order_by";

Many thanks
__________________
X-Cart 4.0

Windoze XP Pro
Sick and tired of figuring out code just wanna get on with my life and selling my goods, it\'s raining here too
Reply With Quote
  #6  
Old 07-28-2004, 12:20 PM
 
TeeJay TeeJay is offline
 

Advanced Member
  
Join Date: Oct 2002
Location: UK
Posts: 85
 

Default

Any volunteers ?
__________________
X-Cart 4.0

Windoze XP Pro
Sick and tired of figuring out code just wanna get on with my life and selling my goods, it\'s raining here too
Reply With Quote
  #7  
Old 04-14-2005, 01:59 PM
  wowfundraising's Avatar 
wowfundraising wowfundraising is offline
 

Newbie
  
Join Date: Mar 2005
Posts: 8
 

Default changing order of categories in admin area only

I don't know if this is what you are looking for or not... but it was something that I changed.

Within the admin area, when you click on "categories", it goes to the "Categories Management" page, url admin/categories.php.

I reorder my categories list quite a bit depending on new additions and what I want to promote more. It was getting difficult to scan this list alphabetically and type in all the "pos" numbers.

So... in include/categories.php, around line 71 (depending on what you've already modded) I did the following:

Code:
elseif (defined('MANAGE_CATEGORIES')) $sort_condition = " ORDER BY $sql_tbl[categories].order_by, $sql_tbl[categories].category"; // original code $sort_condition = " ORDER BY $sql_tbl[categories].category, $sql_tbl[categories].order_by";

Basically just reversed the sorts it was using. Now they display in order by "pos" instead of alphabetically.

Like I said, don't know if this is what you wanted. I did.

Scott
__________________
Version 4.0.12
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:10 AM.

   

 
X-Cart forums © 2001-2020