diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx index e6820d32c..3d0240f92 100644 --- a/components/cart/CartItem/CartItem.tsx +++ b/components/cart/CartItem/CartItem.tsx @@ -116,15 +116,34 @@ const CartItem = ({ {options && options.length > 0 ? (
- {options.map((option: ItemOption, i: number) => ( - - {option.value} - {i === options.length - 1 ? '' : ', '} - - ))} + {/** attempt to sort the options array alphabetically by option name, that way options will always appear in the same order */} + {options + .sort((first: any, second: any) => { + if (first.name && second.name) { + return first.name < second.name + ? -1 + : first.name > second.name + ? 1 + : 0 + } else { + if (JSON.stringify(first) < JSON.stringify(second)) { + return -1 + } else if (JSON.stringify(first) > JSON.stringify(second)) { + return 1 + } else { + return 0 + } + } + }) + .map((option: ItemOption, i: number) => ( + + {option.value} + {i === options.length - 1 ? '' : ', '} + + ))}
) : null}