fix(medusa, types): fix promotion HTTP types in cart (#11304)
This commit is contained in:
6
.changeset/friendly-jars-matter.md
Normal file
6
.changeset/friendly-jars-matter.md
Normal 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 { StoreProduct, StoreProductVariant } from "../../product"
|
||||
import { StoreRegion } from "../../region"
|
||||
@@ -37,6 +38,10 @@ export interface StoreCart extends Omit<BaseCart, "items"> {
|
||||
* The cart's region
|
||||
*/
|
||||
region?: StoreRegion
|
||||
/**
|
||||
* The promotions applied to the cart.
|
||||
*/
|
||||
promotions: StoreCartPromotion[]
|
||||
}
|
||||
export interface StoreCartLineItem
|
||||
extends Omit<BaseCartLineItem, "product" | "variant" | "cart"> {
|
||||
@@ -80,3 +85,37 @@ export interface StoreCartShippingMethod extends BaseCartShippingMethod {
|
||||
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
|
||||
}
|
||||
|
||||
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 { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
|
||||
import { refetchCart } from "../../helpers"
|
||||
import {
|
||||
StoreAddCartPromotionsType,
|
||||
StoreRemoveCartPromotionsType,
|
||||
} from "../../validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: MedusaRequest<StoreAddCartPromotionsType>,
|
||||
req: MedusaRequest<HttpTypes.StoreCartAddPromotion>,
|
||||
res: MedusaResponse<HttpTypes.StoreCartResponse>
|
||||
) => {
|
||||
const workflow = updateCartPromotionsWorkflow(req.scope)
|
||||
@@ -33,7 +29,7 @@ export const POST = async (
|
||||
}
|
||||
|
||||
export const DELETE = async (
|
||||
req: MedusaRequest<StoreRemoveCartPromotionsType>,
|
||||
req: MedusaRequest<HttpTypes.StoreCartRemovePromotion>,
|
||||
res: MedusaResponse<{
|
||||
cart: HttpTypes.StoreCart
|
||||
}>
|
||||
|
||||
Reference in New Issue
Block a user