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
Bookmarks