Replace entire repo content with correct code from /root/shahikitchen-website/
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { CartRepository } from '@/domain/cart/repository';
|
||||
import type { CartItem } from '@/domain/cart/entities';
|
||||
import { STORAGE_KEYS } from '@/domain/shared/constants';
|
||||
|
||||
export class LocalStorageCartRepository implements CartRepository {
|
||||
load(): CartItem[] {
|
||||
if (typeof window === 'undefined') return [];
|
||||
|
||||
const raw = localStorage.getItem(STORAGE_KEYS.cart);
|
||||
if (!raw) return [];
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as CartItem[];
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
save(items: CartItem[]): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
localStorage.setItem(STORAGE_KEYS.cart, JSON.stringify(items));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user