fix(medusa, types): fix promotion HTTP types in cart (#11304)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2025-02-05 12:31:24 +02:00
1 parent d348204fe5
commit 9f1a3b2a42
4 files changed
+61 -6

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
---
"@medusajs/types": patch
"@medusajs/medusa": patch
---
fix(medusa, types): fix promotion HTTP types in cart
@@ -1,3 +1,4 @@
import { ApplicationMethodTypeValues } from "../../../promotion"
import { StorePaymentCollection } from "../../payment" import { StorePaymentCollection } from "../../payment"
import { StoreProduct, StoreProductVariant } from "../../product" import { StoreProduct, StoreProductVariant } from "../../product"
import { StoreRegion } from "../../region" import { StoreRegion } from "../../region"
@@ -37,6 +38,10 @@ export interface StoreCart extends Omit<BaseCart, "items"> {
* The cart's region * The cart's region
*/ */
region?: StoreRegion region?: StoreRegion
/**
* The promotions applied to the cart.
*/
promotions: StoreCartPromotion[]
} }
export interface StoreCartLineItem export interface StoreCartLineItem
extends Omit<BaseCartLineItem, "product" | "variant" | "cart"> { extends Omit<BaseCartLineItem, "product" | "variant" | "cart"> {
@@ -80,3 +85,37 @@ export interface StoreCartShippingMethod extends BaseCartShippingMethod {
shipping_method: StoreCartShippingMethod shipping_method: StoreCartShippingMethod
})[] })[]
} }
export interface StoreCartPromotion {
/**
* The promotion's ID.
*/
id: string
/**
* The promotion's code.
*/
code?: string
/**
* Whether the promotion is applied automatically (without the customer needing to enter a code).
*/
is_automatic?: boolean
/**
* How the promotion is applied.
*/
application_method?: {
/**
* The amount to be discounted.
*/
value: string
/**
* The application method's type. If it's `fixed`, the promotion discounts a fixed amount.
* If it's `percentage`, the promotion discounts a percentage.
*/
type: ApplicationMethodTypeValues
/**
* The currency code of the discount.
*
* @example usd
*/
currency_code: string
}
}
@@ -172,3 +172,17 @@ export interface StoreAddAddress {
*/ */
metadata?: Record<string, unknown> | null metadata?: Record<string, unknown> | null
} }
export interface StoreCartRemovePromotion {
/**
* The promotion codes to remove from the cart.
*/
promo_codes: string[]
}
export interface StoreCartAddPromotion {
/**
* The promotion codes to add to the cart.
*/
promo_codes: string[]
}
@@ -2,14 +2,10 @@ import { updateCartPromotionsWorkflow } from "@medusajs/core-flows"
import { PromotionActions } from "@medusajs/framework/utils" import { PromotionActions } from "@medusajs/framework/utils"
import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http" import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
import { refetchCart } from "../../helpers" import { refetchCart } from "../../helpers"
import {
StoreAddCartPromotionsType,
StoreRemoveCartPromotionsType,
} from "../../validators"
import { HttpTypes } from "@medusajs/framework/types" import { HttpTypes } from "@medusajs/framework/types"
export const POST = async ( export const POST = async (
req: MedusaRequest<StoreAddCartPromotionsType>, req: MedusaRequest<HttpTypes.StoreCartAddPromotion>,
res: MedusaResponse<HttpTypes.StoreCartResponse> res: MedusaResponse<HttpTypes.StoreCartResponse>
) => { ) => {
const workflow = updateCartPromotionsWorkflow(req.scope) const workflow = updateCartPromotionsWorkflow(req.scope)
@@ -33,7 +29,7 @@ export const POST = async (
} }
export const DELETE = async ( export const DELETE = async (
req: MedusaRequest<StoreRemoveCartPromotionsType>, req: MedusaRequest<HttpTypes.StoreCartRemovePromotion>,
res: MedusaResponse<{ res: MedusaResponse<{
cart: HttpTypes.StoreCart cart: HttpTypes.StoreCart
}> }>