add cart functionality for tto services

This commit is contained in:
Helena
2025-09-19 16:23:19 +03:00
parent 3c272505d6
commit b59148630a
26 changed files with 921 additions and 221 deletions

View File

@@ -8,10 +8,12 @@ import { listProductTypes } from '@lib/data/products';
import { Trans } from '@kit/ui/trans';
import { withI18n } from '~/lib/i18n/with-i18n';
import { findProductTypeIdByHandle } from '~/lib/utils';
import { getCartReservations } from '~/lib/services/reservation.service';
import Cart from '../../_components/cart';
import CartTimer from '../../_components/cart/cart-timer';
import { EnrichedCartItem } from '../../_components/cart/types';
export async function generateMetadata() {
const { t } = await createI18nServerInstance();
@@ -37,10 +39,6 @@ async function CartPage() {
productTypes,
'analysis-packages',
);
const ttoServiceTypeId = findProductTypeIdByHandle(
productTypes,
'tto-service',
);
const synlabAnalyses =
analysisPackagesTypeId && synlabAnalysisTypeId && cart?.items
@@ -54,14 +52,11 @@ async function CartPage() {
);
})
: [];
const ttoServiceItems =
ttoServiceTypeId && cart?.items
? cart?.items?.filter((item) => {
const productTypeId = item.product?.type_id;
return productTypeId && productTypeId === ttoServiceTypeId;
})
: [];
let ttoServiceItems: EnrichedCartItem[] = [];
if (cart?.items?.length) {
ttoServiceItems = await getCartReservations(cart);
}
const otherItemsSorted = ttoServiceItems.sort((a, b) =>
(a.updated_at ?? '') > (b.updated_at ?? '') ? -1 : 1,
);