Results 1 to 2 of 2
  1. #1

    Default Alphabetical order on customer order

    Hello

    what do i have to modify to get products listed by alphabetical order on the customer invoice?

    actually products are listed in the order the customer add them to his basket...

    thanks

    L.
    Last edited by wirefram; 6 Jun 2011 at 04:35 PM. Reason: error file name

  2. #2
    Join Date
    Feb 2010
    Posts
    154
    Plugin Contributions
    0

    Default Re: Alphabetical order on customer order

    wirefram,

    I don't know what this will do in regards to the customer invoice, but the following will force the shopping cart to be sorted into alphabetical order based on the name of the product...

    I haven't looked into the appropriate overrides for this, so note that this is modifying core zencart files (which is not a good idea)...

    Edit this file:

    /includes/classes/shopping_cart.php

    Look somewhere around line 1060 for the following: function get_products(

    At the bottom of that function (about line 1213) replace...

    PHP Code:

    return $products_array;

    with...

    PHP Code:

        
    return $this->array_natsort($products_array"id""name");
      }
      
      
    /**
     * @return Returns the array sorted as required
     * @param $aryData Array containing data to sort
     * @param $strIndex Name of column to use as an index
     * @param $strSortBy Column to sort the array by
     * @param $strSortType String containing either asc or desc [default to asc]
     * @desc Naturally sorts an array using by the column $strSortBy
     */
    function array_natsort($aryData$strIndex$strSortBy$strSortType=false)
    {
        
    //    if the parameters are invalid
        
    if (!is_array($aryData) || !$strIndex || !$strSortBy)
            
    //    return the array
            
    return $aryData;
            
        
    //    create our temporary arrays
        
    $arySort $aryResult = array();
        
        
    //    loop through the array
        
    foreach ($aryData as $aryRow)
            
    //    set up the value in the array
            
    $arySort[$aryRow[$strIndex]] = $aryRow[$strSortBy];
            
        
    //    apply the natural sort
        
    natsort($arySort);

        
    //    if the sort type is descending
        
    if ($strSortType=="desc")
            
    //    reverse the array
            
    arsort($arySort);
            
        
    //    loop through the sorted and original data
        
    foreach ($arySort as $arySortKey => $arySorted)
            foreach (
    $aryData as $aryOriginal)
                
    //    if the key matches
                
    if ($aryOriginal[$strIndex]==$arySortKey)
                    
    //    add it to the output array
                    
    array_push($aryResult$aryOriginal);

        
    //    return the return
        
    return $aryResult;

    The above function was copied from the PHP manual (http://www.php.net/manual/en/function.natsort.php). I'm just applying it to the contents of the shopping cart.

    Ideally there would be an option in the admin interface to allow sorting of the cart to be enabled/disabled. Maybe someone else could have a go at that ;-)

    Celtic
    Last edited by Celtic; 7 Jun 2011 at 01:16 AM.

 

 

Similar Threads

  1. categories alphabetical order
    By saaliha in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 16 Jan 2011, 05:13 AM
  2. Currencies Displayed in Alphabetical Order
    By coolglobal in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 6
    Last Post: 12 Jan 2011, 07:01 PM
  3. Sort order // coming out alphabetical?
    By jaggers in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 24 Nov 2007, 08:10 PM
  4. Sort Categories by Alphabetical Order
    By brooklyn in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 23 Jun 2006, 05:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR