update order

This commit is contained in:
Danel Kungla
2025-10-22 15:25:17 +03:00
parent fb44ef577a
commit cc1de3e2f3
4 changed files with 29 additions and 7 deletions

View File

@@ -1,20 +1,31 @@
import { cache } from 'react';
import { getProductCategories, listProducts } from '@lib/data';
import {
getProductCategories,
listProductTypes,
listProducts,
} from '@lib/data';
import { findProductTypeIdByHandle } from '~/lib/utils';
import { isPaymentRequiredForService } from './actions';
import { loadCountryCodes } from './load-analyses';
async function categoryLoader({ handle }: { handle: string }) {
const [response, countryCodes] = await Promise.all([
const [response, countryCodes, { productTypes }] = await Promise.all([
getProductCategories({
handle,
limit: 1,
}),
loadCountryCodes(),
listProductTypes(),
]);
const category = response.product_categories[0];
const countryCode = countryCodes[0]!;
const ttoServiceTypeId = findProductTypeIdByHandle(
productTypes,
'tto-service',
);
if (!response.product_categories?.[0]?.id) {
return { category: null };
@@ -29,6 +40,9 @@ async function categoryLoader({ handle }: { handle: string }) {
const productsWithNoRequiredPayment = categoryProducts.filter(
async (product) => {
if (product.type_id !== ttoServiceTypeId) {
return false;
}
if (product.metadata?.serviceIds) {
const serviceIds: number[] = JSON.parse(
product.metadata.serviceIds as string,