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ênKiểuBắt buộcMô tả
idintCóID đơn hàng

Headers

TênBắt buộcMô tả
AuthorizationCó<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-TypeCó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_id và creator_id là 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 tin billing_*, payment_method, payment_status, fulfillment_status, shipping_type, pickup_store_id (khi shipping_type = 1), store_id (khi shipping_type = 9), shipping_carrier_id, shipping_status, thông tin người nhận shipping_*, thông tin xuất hóa đơn tax_*, 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ổng uom_unit_price x uom_quantity của details; price_discount = tổng các khoản price_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.
  • details là 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 trong details sẽ bị xóa. Không được thay đổi dòng sản phẩm khi đơn đã hoàn thành hoặc đã hủy.
  • status không được cập nhật trực tiếp qua API này. Khi shipping_status chuyển sang SHIPPING_STATUS_DELIVERED (21) và đơn chưa hoàn thành, status tự chuyển thành STATUS_COMPLETE nếu payment_status là 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

Xem Order Object Schema

Error Codes

HTTPCodeMô tả
401error_jwt_is_requiredThiếu token xác thực
404error_not_foundKhông tìm thấy đơn hàng
422error_company_id_requiredThiếu company_id
422error_company_id_notfoundcompany_id không thuộc phiên đăng nhập
422error_user_id_notfoundcreator_id không hợp lệ
422error_setting_fetch_errorLỗi lấy cấu hình công ty
422error_not_permissionKhông có quyền chỉnh sửa đơn hàng tại cửa hàng này
422error_details_have_invalid_data_lineChi 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)
422error_not_permission_edit_detailKhông có quyền chỉnh sửa chi tiết đơn hàng
422error_not_allow_change_detail_in_complete_or_cancel_orderKhông được phép thay đổi chi tiết đơn hàng đã hoàn thành hoặc hủy
422error_detail_item_required_imei (SKU: [sku])Sản phẩm IMEI bắt buộc phải có số IMEI
422error_cancel_reason_requirePayload có status = 21 (hủy) nhưng thiếu cancel_reason
422error_cancel_reason_not_existcancel_reason không hợp lệ
422error_billing_region_id_not_existVùng thanh toán không tồn tại
422error_billing_sub_region_id_not_existQuận/huyện thanh toán không tồn tại
422error_billing_sub_sub_region_id_not_existPhường/xã thanh toán không tồn tại
422error_shipping_region_id_not_existVùng giao hàng không tồn tại
422error_shipping_sub_region_id_not_existQuận/huyện giao hàng không tồn tại
422error_shipping_sub_sub_region_id_not_existPhường/xã giao hàng không tồn tại
500error_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
500error_editLỗi khi lưu đơn hàng

On this page