feat(medusa, core-workflows, product): slightly improve create cart workflow (#5725)
This commit is contained in:
@@ -364,11 +364,15 @@ class CartService extends TransactionBaseService {
|
||||
).id
|
||||
}
|
||||
|
||||
if (data.customer_id) {
|
||||
const customer = await this.customerService_
|
||||
.withTransaction(transactionManager)
|
||||
.retrieve(data.customer_id)
|
||||
.catch(() => undefined)
|
||||
if (data.customer_id || data.customer) {
|
||||
const customer =
|
||||
(data.customer ??
|
||||
(data.customer_id &&
|
||||
(await this.customerService_
|
||||
.withTransaction(transactionManager)
|
||||
.retrieve(data.customer_id)
|
||||
.catch(() => undefined)))) as Customer
|
||||
|
||||
rawCart.customer = customer
|
||||
rawCart.customer_id = customer?.id
|
||||
rawCart.email = customer?.email
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Cart, CartType } from "../models/cart"
|
||||
import { IsType } from "../utils/validators/is-type"
|
||||
import { Region } from "../models"
|
||||
import { ValidateNested } from "class-validator"
|
||||
import { CustomerTypes } from "@medusajs/types"
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function isCart(object: any): object is Cart {
|
||||
@@ -60,6 +61,7 @@ export type CartCreateProps = {
|
||||
shipping_address?: Partial<AddressPayload>
|
||||
gift_cards?: GiftCard[]
|
||||
discounts?: Discount[]
|
||||
customer?: CustomerTypes.CustomerDTO
|
||||
customer_id?: string
|
||||
type?: CartType
|
||||
context?: object
|
||||
|
||||
Reference in New Issue
Block a user