OMSĐơn hàng
Cập nhật đơn hàng
Thay đổi thông tin đơn hàng
API này cho phép cập nhật các thông tin cơ bản của đơn hàng như thông tin khách hàng, địa chỉ giao hàng, phương thức thanh toán, trạng thái và các thông tin khác. Việc cập nhật chi tiết sản phẩm trong đơn hàng có thể yêu cầu các API chuyên biệt khác.
Endpoint
PUT /v1/orders/:id
Path Parameters
| Tên | Kiểu | Bắt buộc | Mô tả |
|---|---|---|---|
id | int | Có | ID đơn hàng |
Headers
| Tên | Bắt buộc | Mô tả |
|---|---|---|
Authorization | Có | <JWT> của người dùng có quyền sửa đơn (order.edit) tại cửa hàng của đơn |
Content-Type | Có | application/json |
Request Payload
JSON Object Payload:
{
"company_id": 10311,
"creator_id": 1,
"id": 10002414,
"source": 1,
"source_name": "",
"store_id": 32,
"pickup_store_id": 0,
"shift_id": 0,
"warehouse_id": 33,
"quantity": 7,
"weight": 2700,
"price_policy_id": 1,
"price_sell": 1963600,
"price_discount_order": 98180,
"price_discount_coupon": 0,
"price_discount_shipping": 12000,
"price_discount_manual": 0,
"price_discount_loyalty": 0,
"price_discount_giftcard": 0,
"price_discount": 110180,
"price_shipping": 20000,
"price_final": 1873420,
"quantity_fulfilled": 7,
"weight_fulfilled": 2700,
"price_sell_fulfilled": 1963600,
"price_shipping_fulfilled": 20000,
"price_discount_order_fulfilled": 98180,
"price_discount_coupon_fulfilled": 0,
"price_discount_shipping_fulfilled": 12000,
"price_discount_manual_fulfilled": 0,
"price_discount_fulfilled": 110180,
"price_handling_fulfilled": 0,
"price_tax_fulfilled": 0,
"price_final_fulfilled": 1873420,
"promotion_coupon": "",
"promotion_id": 0,
"billing_full_name": "Hoàng Văn Hải",
"billing_phone": "0909876543",
"billing_email": "",
"billing_address": "15 Trần Phú",
"billing_region_id": 88831,
"billing_sub_region_id": 88810507,
"billing_sub_sub_region_id": 88811332,
"payment_method": 11,
"payment_status": 1,
"fulfillment_status": 13,
"exception_status": 0,
"exception_count_total": 0,
"exception_count_unresolved": 0,
"shipping_type": 3,
"shipping_address_id": 0,
"shipping_full_name": "Hoàng Văn Hải",
"shipping_phone": "0909876543",
"shipping_email": "",
"shipping_address": "15 Trần Phú",
"shipping_region_id": 88831,
"shipping_sub_region_id": 888303,
"shipping_sub_sub_region_id": 88811296,
"shipping_address_line_2": "",
"shipping_instruction": "",
"shipping_legacy_province_name": "",
"shipping_legacy_district_name": "",
"shipping_legacy_ward_name": "",
"shipping_carrier_id": 23,
"shipping_status": 9,
"tax_name": "",
"tax_is_company": 0,
"tax_code": "",
"tax_address": "",
"tax_email": "",
"tax_invoice_type": 7,
"tax_invoice_status": 1,
"file_id_list": [],
"date_ship_requested": 1761498000,
"date_ship_committed": 1761498000,
"note": "",
"tag": "",
"count_return_order": 0,
"origin_order_id": 0,
"status": 13,
"aff_id": 0,
"aff_code_id": 0,
"aff_code": "",
"aff_click_token": "",
"details": [
{
"company_id": 10311,
"creator_id": 0,
"order_id": 10002414,
"product_id": 486,
"product_variant_id": 948,
"id": 3787,
"type": 1,
"item_type": 1,
"item_serial_number": "",
"item_option_value_id_list": [4, 13],
"sku": "2397540229784",
"item_option_value_text": "Đen, M",
"item_name": "PUMA - Áo khoác nam thể thao cổ trụ phối zip Fit Woven Half Zip Training 522129",
"item_quantity": 3,
"item_weight": 400,
"item_unit_price_original": 599000,
"item_unit_price": 479200,
"price_discount": 359400,
"price_tax": 0,
"price_final": 1437600,
"tax_ratio": 11,
"tax_is_included": 1,
"note": "",
"promotion_id": 0,
"promotion_detail": [],
"is_catch_weight": 0,
"uom_id": 1000,
"uom_name": "Cái",
"uom_factor": 1,
"uom_quantity": 3,
"uom_unit_price": 479200,
"uom_unit_price_original": 599000,
"customize_required": 0,
"customize_description": "",
"file_id_list": [],
"file_list": [],
"item_quantity_fulfilled": 2,
"item_unit_price_fulfilled": 0,
"uom_quantity_fulfilled": 2,
"uom_unit_price_fulfilled": 0,
"price_sell_fulfilled": 0,
"price_tax_fulfilled": 0,
"price_final_fulfilled": 0,
"price_discount_fulfilled": 0,
"pick_detail_id_list": [],
"bundle_identifier": "",
"bundle_promotion_id": 0,
"bundle_promotion_product_id": 0,
"bundle_promotion_multiplier": 0,
"bundle_index": 0,
"bundle_allocation_rule": "",
"bundle_discount_allocated": 0,
"bundle_promotion_name": "",
"bundle_promotion_type": 0
}
]
}Workflow & Logic
company_idvàcreator_idlà bắt buộc (công ty và người dùng của phiên đăng nhập).- Các trường được cập nhật:
tag,note,warehouse_id,source,external_id,sale_id, thông tinbilling_*,payment_method,payment_status,fulfillment_status,shipping_type,pickup_store_id(khishipping_type= 1),store_id(khishipping_type= 9),shipping_carrier_id,shipping_status, thông tin người nhậnshipping_*, thông tin xuất hóa đơntax_*,file_id_list,date_ship_requested,date_ship_committed. Các trường khác trong payload (ví dụ các trường*_fulfilled,status) bị bỏ qua. - Giá đơn được tính lại phía server:
price_sell= tổnguom_unit_pricexuom_quantitycủadetails;price_discount= tổng các khoảnprice_discount_order,price_discount_coupon,price_discount_shipping(không vượt quáprice_shipping),price_discount_manual,price_discount_loyalty,price_discount_giftcard;price_final=price_sell+price_shipping-price_discount. detailslà danh sách đầy đủ dòng sản phẩm của đơn sau khi sửa: dòng cóid> 0 là dòng đã có (được cập nhật nếu đổi số lượng, đơn giá, IMEI, thông tin gia công hoặc file), dòng cóid= 0 là dòng mới, dòng đã có nhưng không xuất hiện trongdetailssẽ bị xóa. Không được thay đổi dòng sản phẩm khi đơn đã hoàn thành hoặc đã hủy.statuskhông được cập nhật trực tiếp qua API này. Khishipping_statuschuyển sangSHIPPING_STATUS_DELIVERED(21) và đơn chưa hoàn thành,statustự chuyển thànhSTATUS_COMPLETEnếupayment_statuslàPAYMENT_STATUS_COMPLETED, ngược lại làSTATUS_SHIPPED.
Lưu ý
Nếu payload có details, mọi dòng sản phẩm hiện có của đơn không nằm trong details sẽ bị xóa. Hãy luôn gửi đủ danh sách dòng sản phẩm (lấy từ GET /v1/orderdetails/order/:order_id) khi sửa đơn.
Response Schema
HTTP 200 - JSON Object
Error Codes
| HTTP | Code | Mô tả |
|---|---|---|
| 401 | error_jwt_is_required | Thiếu token xác thực |
| 404 | error_not_found | Không tìm thấy đơn hàng |
| 422 | error_company_id_required | Thiếu company_id |
| 422 | error_company_id_notfound | company_id không thuộc phiên đăng nhập |
| 422 | error_user_id_notfound | creator_id không hợp lệ |
| 422 | error_setting_fetch_error | Lỗi lấy cấu hình công ty |
| 422 | error_not_permission | Không có quyền chỉnh sửa đơn hàng tại cửa hàng này |
| 422 | error_details_have_invalid_data_line | Chi tiết đơn hàng có dữ liệu không hợp lệ (dòng id không thuộc đơn, hoặc biến thể không thuộc công ty) |
| 422 | error_not_permission_edit_detail | Không có quyền chỉnh sửa chi tiết đơn hàng |
| 422 | error_not_allow_change_detail_in_complete_or_cancel_order | Không được phép thay đổi chi tiết đơn hàng đã hoàn thành hoặc hủy |
| 422 | error_detail_item_required_imei (SKU: [sku]) | Sản phẩm IMEI bắt buộc phải có số IMEI |
| 422 | error_cancel_reason_require | Payload có status = 21 (hủy) nhưng thiếu cancel_reason |
| 422 | error_cancel_reason_not_exist | cancel_reason không hợp lệ |
| 422 | error_billing_region_id_not_exist | Vùng thanh toán không tồn tại |
| 422 | error_billing_sub_region_id_not_exist | Quận/huyện thanh toán không tồn tại |
| 422 | error_billing_sub_sub_region_id_not_exist | Phường/xã thanh toán không tồn tại |
| 422 | error_shipping_region_id_not_exist | Vùng giao hàng không tồn tại |
| 422 | error_shipping_sub_region_id_not_exist | Quận/huyện giao hàng không tồn tại |
| 422 | error_shipping_sub_sub_region_id_not_exist | Phường/xã giao hàng không tồn tại |
| 500 | error_delete_order_detail_id<id> / error_edit_order_detail_id<id> / error_add_order_detail_<product_variant_id> | Lỗi khi xóa / sửa / thêm dòng sản phẩm |
| 500 | error_edit | Lỗi khi lưu đơn hàng |