22 lines
546 B
TypeScript
22 lines
546 B
TypeScript
// Function to get a unique identifier for a cart item
|
|
export function getUniqueItemKey(item: any, boxGroupId?: string, index?: number): string {
|
|
// Start with the merchandise id
|
|
let key = item.merchandise.id;
|
|
|
|
// Add the item's own id if available
|
|
if (item.id) {
|
|
key = `${key}-${item.id}`;
|
|
}
|
|
|
|
// Add box group id if it's part of a box
|
|
if (boxGroupId) {
|
|
key = `${boxGroupId}-${key}`;
|
|
}
|
|
|
|
// Add index as fallback to ensure uniqueness
|
|
if (index !== undefined) {
|
|
key = `${key}-${index}`;
|
|
}
|
|
|
|
return key;
|
|
}
|