Skip to content

order

Order

Overview

k.commerce.order provides order-related operations, including query, creation, payment, delivery, cancellation and other functions.

list()

Get the order list.

ts
k.api.get(() => {
    const result = k.commerce.order.list({
        startDate: new Date('2025-01-01'),
        endDate: new Date('2025-12-31'),
        paid: false,
        delivered: false,
        canceled: false,
        pageIndex: 1,
        pageSize: 10
    })
    return result
})

parameter:

ParameterTypeRequiredDescription
query.customerIdstringnoCustomer ID
query.paidbooleannoHas it been paid?
query.deliveredbooleannoHas it been shipped?
query.canceledbooleannoHas it been cancelled?
query.startDateDatenostart time
query.endDateDatenoDeadline
query.pageIndexnumbernoPage number, default 1
query.pageSizenumbernoNumber of items per page, default 10

return:

ts
{
    list: OrderDetail[];  // Order list
    count: number;        // Total count
    pageIndex: number;    // Current page number
    pageSize: number;     // Items per page
}

get()

Get the specified order details.

ts
k.api.get(() => {
    const order = k.commerce.order.get('order-id')
    return { id: order.id, totalAmount: order.totalAmount }
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID

Return: OrderDetail

create()

Create an order.

ts
k.api.post(() => {
    // Create a cart and add a product
    const cartId = k.commerce.cart.create()
    const product = k.commerce.product.create({
        title: 'Order Test Product',
        description: 'Test',
        price: 99.9,
        active: true,
        seoName: 'order-test-' + Date.now(),
        featuredImage: ''
    } as any)
    k.commerce.product.createVariant(product.id, {
        sku: 'ORD-SKU-001',
        price: 99.9,
        inventory: 100,
        barcode: '',
        active: true,
        selectedOptions: []
    } as any)
    const refreshed = k.commerce.product.get(product.id)
    k.commerce.cart.addOrUpdateLine(cartId, refreshed.variants[0].id, 1)

    // Create the order
    const order = k.commerce.order.create(cartId, {
        address: {
            country: 'China',
            province: 'Fujian',
            city: 'Xiamen',
            address1: 'address1',
            address2: '',
            zip: '361000',
            firstName: 'firstName',
            lastName: 'lastName',
            phone: '13800138000',
            isDefault: true
        },
        note: 'test order'
    })
    return { orderId: order.id }
})

parameter:

ParameterTypeRequiredDescription
cartIdstringyesCart ID
optionsobjectyesOrder options
options.addressAddressyesShipping address
options.extensionFieldsKeyValue[]noextension fields
options.notestringnoRemark
options.scheduledDeliveryTimeDatenoEstimated delivery time

Return: OrderDetail

cancel()

Cancel order.

ts
k.api.post(() => {
    k.commerce.order.cancel('order-id', 'cancel reason')
    return 'success'
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID
reasonstringyesReason for cancellation

Return: void

delete()

Delete order.

ts
k.api.post(() => {
    k.commerce.order.delete('order-id')
    return 'success'
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID

Return: void

pay()

Pay for your order.

ts
k.api.post(() => {
    k.commerce.order.pay('order-id', 'alipay')
    return 'success'
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID
paymentMethodstringyesPayment method

Return: void

delivery()

Order shipped.

ts
k.api.post(() => {
    const shipping = k.commerce.shipping.list()[0]
    k.commerce.order.delivery('order-id', shipping.id, 'SF123456789')
    return 'success'
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID
shippingCarrierstringyesLogistics company
trackingNumberstringyesLogistics order number

Return: void

reopen()

Reopen a canceled order.

ts
k.api.post(() => {
    k.commerce.order.reopen('order-id')
    return 'success'
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID

Return: void

updateAddress()

Update the order shipping address.

ts
k.api.post(() => {
    k.commerce.order.updateAddress('order-id', {
        country: 'China',
        province: 'Fujian',
        city: 'Xiamen',
        address1: 'address1',
        address2: '',
        zip: '361000',
        firstName: 'firstName',
        lastName: 'lastName',
        phone: '13800138000',
        isDefault: true
    })
    return 'success'
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID
addressAddressyesShipping address

Return: void

updateShippingInfo()

Update order shipping information.

ts
k.api.post(() => {
    const order = k.commerce.order.get('order-id')
    const lineId = order.lines[0].id
    const shipping = k.commerce.shipping.list()[0]

    k.commerce.order.updateShippingInfo('order-id', lineId, {
        shippingCarrier: shipping.id,
        trackingNumber: 'SF123456789'
    })
    return 'success'
})

parameter:

ParameterTypeRequiredDescription
orderIdstringyesOrder ID
orderLineIdstringyesOrder item ID
optionsobjectyesShipping options
options.shippingCarrierstringnoLogistics company
options.trackingNumberstringnoLogistics order number
options.digitalItemsDigitalOrderItem[]nodigital products

Return: void

structure

OrderDetail Property

PropertyDescriptionType
IDOrder IDstring
customercustomer informationCustomer
pointsDeductionAmountPoints deduction amountnumber
earnPointsearn pointsnumber
redeemPointsRedeem pointsnumber
totalAmountTotal order amountnumber
taxAmounttaxnumber
originalAmountoriginal amountnumber
shippingAmountDelivery amountnumber
insuranceAmountInsurance amountnumber
subtotalAmountSubtotal amountnumber
originalSubtotalAmountOriginal subtotal amountnumber
totalQuantitytotal quantitynumber
currencycurrencystring
paidHas it been paid?boolean
paidAtpayment timeDate
paymentMethodPayment methodstring
deliveredHas it been shipped?boolean
partialDeliveredWhether to partially shipboolean
trackingNumberLogistics order numberstring
shippingCarrierLogistics companystring
shippingAtShipping timeDate
scheduledDeliveryTimeEstimated delivery timeDate
canceled canceledHas it been cancelled?boolean
cancelReasonReason for cancellationstring
cancelAtCancellation timeDate
createdAtcreation timeDate
updatedAtUpdate timeDate
shippingAddressShipping addressAddress
noteRemarkstring
linesOrder itemsOrderLine
ipIP addressstring
countrynationstring
sourcesourcestring
clientInfoClient informationClientInfo
extensionButtonExtension button{ text: string, url: string }
discountAllocationsAutomatic discount informationDiscountAllocation[]
shippingAllocationsShipping method listShippingAllocation[]
extensionFieldsextension fieldsKeyValue[]

Customer attribute

PropertyDescriptionType
IDCustomer IDstring
emailCustomer emailstring
firstNameCustomer namestring
lastNameCustomer last namestring
phoneCustomer phone numberstring

Address property

PropertyDescriptionType
IDAddress IDstring
isDefaultWhether the default addressboolean
countrynationstring
provinceprovincestring
cityCitystring
address1Address 1string
address2Address 2string
firstNameConsignee namestring
lastNameConsignee's last namestring
phoneTelephonestring
zippost codestring

OrderLine Property

PropertyDescriptionType
IDOrder item IDstring
totalAmountTotal amount of order itemsnumber
taxAmountOrder product taxnumber
originalAmountOriginal amount of order itemsnumber
quantityOrder quantitynumber
totalQuantityTotal quantity of items orderednumber
priceOrder item pricenumber
originalPriceOriginal price of order itemsnumber
titleOrder product namestring
imageOrder product picturesstring
productIdProduct IDstring
variantIdVariant IDstring
skuProduct SKUstring
orderIdOrder IDstring
optionsProduct options{ name: string, value: string }[]
discountAllocationsAutomatic discount informationDiscountAllocation[]
groupNameProduct group namestring
isMainIs it the main product?boolean
noteNotes on order itemsstring
extensionButtonExtension button{ text: string, url: string }
trackingNumberLogistics order numberstring
shippingCarrierLogistics companystring
shippingAtShipping timeDate
deliveredHas it been shipped?boolean
digitalItemsDigital product listDigitalOrderItem[]
autoDeliveryWhether to ship automaticallyboolean
isDigitalIs it a digital product?boolean
maxDownloadCountMaximum number of downloadsnumber
maxDownloadDayMaximum download daysnumber
errorMessageerror messagestring

ClientInfo Property

PropertyDescriptionType
platformplatformstring
oSoperating systemstring
deviceequipmentstring
applicationApplication informationApplicationInfo

ApplicationInfo Property

PropertyDescriptionType
isWebBrowserIs it a web browser?boolean
nameApplication namestring
versionApplication versionstring