Merge pull request #76 from MR-medreport/improvements-0609
update order xml for live, allow adding discounts in cart
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user