Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 03-09-2020 13:40:18

garden1
Member
Registered: 02-06-2020
Posts: 61

Ordering Categories Alphabetically

We are constantly updating our categories and products, and my partner wanted to keep categories sorted alphabetically.  I created the following simple php script that I can run anytime to reorder the category displays by name.  Use at your own risk. (Just make a new .php file in your public folder, called whatever you like and add the following code.)





Code:

<?php

//---This simple script re-orders the category displays alphabetically---
//-------

$servername = "localhost";
$username = "databaseuser";
$password = "databasepassword";
$dbname = "databaseuser";

// ----Create connection----
$conn = new mysqli($servername, $username, $password, $dbname);

// --- Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully <br /> <br />";


//--- Get Category IDs and names  -  data ordered alphabetically by name
$sql = "SELECT id, name FROM ecom_cat ORDER BY name";
$result = $conn->query($sql);


//--- initialize counter
$tempvarcounter = 0;



if ($result->num_rows > 0) {
    
    while($row = $result->fetch_assoc()) {
    
         $tempvarcounter = $tempvarcounter + 10;
         $sql = "UPDATE ecom_cat SET sortorder=".$tempvarcounter.", manussortorder=".$tempvarcounter.", xsortorder=".$tempvarcounter.", addlsortorder=".$tempvarcounter." WHERE id='".$row["id"]."'";
         
         echo $sql . "<br />";
         echo $conn->query($sql) ."<br />";
    }
} else {
    echo "0 results";
}



$conn->close();
?>

Offline

 

#2 03-09-2020 14:01:49

zanart
Member
From: bedford
Registered: 04-02-2008
Posts: 1638
Website

Re: Ordering Categories Alphabetically

You could just edit the catlist function in ECOM_Cat.php and change the sortfield variable from sortorder to name.
This should just ensure any category list is sorted by the Name column in the database table.


- Euorpacart 8

Online

 

#3 03-09-2020 14:41:31

garden1
Member
Registered: 02-06-2020
Posts: 61

Re: Ordering Categories Alphabetically

Indeed.  Using the display order numbers allows for easy customization later if something needs to be added/altered.  ..like let's say a category begins with an open quote or number:  It will be sorted to the beginning regardless of its first real letter.  After using this sort, I can go back in and manually put it where it should be.

Last edited by garden1 (03-09-2020 14:42:30)

Offline

 

#4 03-10-2020 07:33:20

nigel
Member
From: Peterborough, UK
Registered: 04-27-2008
Posts: 401
Website

Re: Ordering Categories Alphabetically

On a slightly different note, is it possible to sort the shipping options displayed in the shopping cart by Name as opposed to Price? At the moment the shipping options are listed as cheapest first but I would prefer to have them listed alphabetically.
Thanks in advance!!

Offline

 

#5 03-10-2020 07:53:57

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19482
Website

Re: Ordering Categories Alphabetically

nigel wrote:

On a slightly different note, is it possible to sort the shipping options displayed in the shopping cart by Name as opposed to Price? At the moment the shipping options are listed as cheapest first but I would prefer to have them listed alphabetically.
Thanks in advance!!

Customers would find that confusing and you'd be dealing with issues changing shipping methods and order totals.  And you might see order numbers actually reduce.  You want to show them in price order, with the first being the cheapest and preselected to give the lowest total possible on the first checkout page.


Nick Hendler

Offline

 

Board footer