feat(MED-100): update montonio redirect
This commit is contained in:
@@ -392,7 +392,7 @@ export async function setAddresses(currentState: unknown, formData: FormData) {
|
||||
* @param cartId - optional - The ID of the cart to place an order for.
|
||||
* @returns The cart object if the order was successful, or null if not.
|
||||
*/
|
||||
export async function placeOrder(cartId?: string) {
|
||||
export async function placeOrder(cartId?: string, options: { revalidateCacheTags: boolean } = { revalidateCacheTags: true }) {
|
||||
const id = cartId || (await getCartId());
|
||||
|
||||
if (!id) {
|
||||
@@ -406,21 +406,26 @@ export async function placeOrder(cartId?: string) {
|
||||
const cartRes = await sdk.store.cart
|
||||
.complete(id, {}, headers)
|
||||
.then(async (cartRes) => {
|
||||
const cartCacheTag = await getCacheTag("carts");
|
||||
revalidateTag(cartCacheTag);
|
||||
if (options?.revalidateCacheTags) {
|
||||
const cartCacheTag = await getCacheTag("carts");
|
||||
revalidateTag(cartCacheTag);
|
||||
}
|
||||
return cartRes;
|
||||
})
|
||||
.catch(medusaError);
|
||||
|
||||
if (cartRes?.type === "order") {
|
||||
const orderCacheTag = await getCacheTag("orders");
|
||||
revalidateTag(orderCacheTag);
|
||||
if (options?.revalidateCacheTags) {
|
||||
const orderCacheTag = await getCacheTag("orders");
|
||||
revalidateTag(orderCacheTag);
|
||||
}
|
||||
|
||||
removeCartId();
|
||||
redirect(`/home/order/${cartRes?.order.id}/confirmed`);
|
||||
} else {
|
||||
throw new Error("Cart is not an order");
|
||||
}
|
||||
|
||||
return cartRes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -134,3 +134,24 @@ export const listProductsWithSort = async ({
|
||||
queryParams,
|
||||
}
|
||||
}
|
||||
|
||||
export const listProductTypes = async (): Promise<{ productTypes: HttpTypes.StoreProductType[]; count: number }> => {
|
||||
const next = {
|
||||
...(await getCacheOptions("productTypes")),
|
||||
};
|
||||
|
||||
return sdk.client
|
||||
.fetch<{ product_types: HttpTypes.StoreProductType[]; count: number }>(
|
||||
"/store/product-types",
|
||||
{
|
||||
next,
|
||||
cache: "force-cache",
|
||||
query: {
|
||||
fields: "id,value,metadata",
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(({ product_types, count }) => {
|
||||
return { productTypes: product_types, count };
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user