mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +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>
|
</Link>
|
||||||
{options && options.length > 0 ? (
|
{options && options.length > 0 ? (
|
||||||
<div className="">
|
<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
|
<span
|
||||||
key={`${item.id}-${option.name}`}
|
key={`${item.id}-${option.name}`}
|
||||||
className="text-sm font-semibold text-accents-7"
|
className="text-sm font-semibold text-accents-7"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user