Merge pull request #76 from MR-medreport/improvements-0609

update order xml for live, allow adding discounts in cart
This commit is contained in:
2025-09-06 19:58:59 +00:00
committed by GitHub
5 changed files with 119 additions and 42 deletions

View File

@@ -87,7 +87,10 @@ export async function getOrSetCart(countryCode: string) {
return cart;
}
export async function updateCart({ id, ...data }: HttpTypes.StoreUpdateCart & { id?: string }) {
export async function updateCart(
{ id, ...data }: HttpTypes.StoreUpdateCart & { id?: string },
{ onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} },
) {
const cartId = id || (await getCartId());
if (!cartId) {
@@ -109,9 +112,13 @@ export async function updateCart({ id, ...data }: HttpTypes.StoreUpdateCart & {
const fulfillmentCacheTag = await getCacheTag("fulfillment");
revalidateTag(fulfillmentCacheTag);
onSuccess();
return cart;
})
.catch(medusaError);
.catch((e) => {
onError();
return medusaError(e);
});
}
export async function addToCart({
@@ -259,7 +266,10 @@ export async function initiatePaymentSession(
.catch(medusaError);
}
export async function applyPromotions(codes: string[]) {
export async function applyPromotions(
codes: string[],
{ onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} },
) {
const cartId = await getCartId();
if (!cartId) {
@@ -278,8 +288,13 @@ export async function applyPromotions(codes: string[]) {
const fulfillmentCacheTag = await getCacheTag("fulfillment");
revalidateTag(fulfillmentCacheTag);
onSuccess();
})
.catch(medusaError);
.catch((e) => {
onError();
return medusaError(e);
});
}
export async function applyGiftCard(code: string) {
@@ -427,7 +442,7 @@ export async function placeOrder(cartId?: string, options: { revalidateCacheTags
} else {
throw new Error("Cart is not an order");
}
return retrieveOrder(cartRes.order.id);
}