Merge branch 'develop' into MED-177

This commit is contained in:
Danel Kungla
2025-10-21 17:27:54 +03:00
131 changed files with 2202 additions and 921 deletions

View File

@@ -23,7 +23,9 @@ import { getRegion } from './regions';
* @param cartId - optional - The ID of the cart to retrieve.
* @returns The cart object if found, or null if not found.
*/
export async function retrieveCart(cartId?: string) {
export async function retrieveCart(
cartId?: string,
): Promise<(StoreCart & { promotions: StoreCartPromotion[] }) | null> {
const id = cartId || (await getCartId());
if (!id) {
@@ -135,13 +137,21 @@ export async function addToCart({
quantity: number;
countryCode: string;
}) {
const logger = await getLogger();
const ctx = {
variantId,
quantity,
countryCode,
};
if (!variantId) {
logger.error(ctx, 'Missing variant ID when adding to cart');
throw new Error('Missing variant ID when adding to cart');
}
const cart = await getOrSetCart(countryCode);
if (!cart) {
logger.error(ctx, 'Error retrieving or creating cart');
throw new Error('Error retrieving or creating cart');
}

View File

@@ -6,7 +6,11 @@ import { HttpTypes } from '@medusajs/types';
import { getAuthHeaders, getCacheOptions } from './cookies';
export const retrieveOrder = async (id: string, allowCache = true) => {
export const retrieveOrder = async (
id: string,
allowCache = true,
fields = '*payment_collections.payments,*items,*items.metadata,*items.variant,*items.product',
) => {
const headers = {
...(await getAuthHeaders()),
};
@@ -19,8 +23,7 @@ export const retrieveOrder = async (id: string, allowCache = true) => {
.fetch<HttpTypes.StoreOrderResponse>(`/store/orders/${id}`, {
method: 'GET',
query: {
fields:
'*payment_collections.payments,*items,*items.metadata,*items.variant,*items.product',
fields,
},
headers,
next,
@@ -59,7 +62,18 @@ export const listOrders = async (
credentials: 'include',
})
.then(({ orders }) => orders)
.catch((err) => medusaError(err));
.catch((err) => {
console.error('Error receiving orders', { err });
return medusaError(err);
});
};
export const listOrdersByIds = async (ids: string[]) => {
try {
return Promise.all(ids.map((id) => retrieveOrder(id)));
} catch (error) {
console.error('response Error', error);
}
};
export const createTransferRequest = async (