Sort values of structure with arrays
Hi
For a shopping cart I'm using a structure with arrays to store the items in the cart. I tried to use StructSort but did not work...
This is how I store the items in the cart:
<cfscript>
if (not(isdefined("session.cart"))) { // Check to make sure that the Shopping cart structure exists.
session.cart = structnew();
// The item structure we are going to use to store the items in the cart
// is going to have four parts...
// 1. The item id
// 2. The item name
// 3. The price per unit
// 4. The quantity
tempvalue = listtoarray('#attributes.id#,#attributes.name#,#attributes.price#,#attributes.quantity#');
// if the item is not yet in the cart, simply add it to the cart
if (not(structKeyExists(session.cart, attributes.name))) {
StructInsert(session.cart,attributes.name,tempvalue);
}
// if the item is already in the cart, update the item quantity
else {
tempvalue[4]=session.cart[attributes.name][4]+attributes.quantity;
StructUpdate(session.cart,attributes.name,tempvalue);
}
</cfscript>
Any help will be appreciated.
Thank you.
TJ
