mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Added a sort to the options before displaying
This commit is contained in:
parent
c577fd9fbb
commit
4fb9b69c95
@ -116,7 +116,26 @@ const CartItem = ({
|
||||
</Link>
|
||||
{options && options.length > 0 ? (
|
||||
<div className="">
|
||||
{options.map((option: ItemOption, i: number) => (
|
||||
{/** 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) => (
|
||||
<span
|
||||
key={`${item.id}-${option.name}`}
|
||||
className="text-sm font-semibold text-accents-7"
|
||||
|
Loading…
x
Reference in New Issue
Block a user