CartGiỏ hàng khách hàng

Lấy báo giá giỏ hàng (Quote)

Đồng bộ thông tin checkout vào cart và tính lại giá (khuyến mãi, phí ship, điểm/loyalty).

Endpoint

PUT /site/customercarts/{uuid}/getquote

Headers

KeyValueBắt buộcMô tả
SiteTenantId{tenant_id}CóID của công ty/tenant.
SiteAuthorization{jwt_token}KhôngToken khách hàng (nếu đã đăng nhập).

Workflow & Logic

API này dùng để tính quote cho giỏ hàng trước khi checkout. Request sẽ đồng bộ các thông tin giao hàng/thanh toán vào cart, sau đó tính lại:

  • Giá bán theo chính sách giá (website/customer type).
  • Phí vận chuyển (khi shipping_type = delivery và đủ dữ liệu).
  • Khuyến mãi (bundle evaluate + cart evaluate).
  • Quy đổi điểm tích lũy (loyalty redeem evaluate) nếu có redeem_points.

Quy trình xử lý

  1. Lấy & kiểm tra giỏ hàng theo uuid

    • Hệ thống tìm cart theo uuid trong shop hiện tại (SiteTenantId).
    • Nếu cart đã gắn với một khách hàng, khách hàng khác đang đăng nhập không dùng được cart này. Khách chưa đăng nhập vẫn dùng được cart bằng uuid.
    • Nếu không tồn tại → trả lỗi error_cart_not_found.
  2. Ghi đè thông tin checkout từ request vào cart

    • Ghi các field billing/shipping (billing_full_name, shipping_address, shipping_region_id, ...).
    • Ghi store_id, pickup_store_id, shipping_type, shipping_profile_rate_id.
    • Ghi payment_method, coupon_code, redeem_points, thông tin hóa đơn (tax_*).
    • Lưu ý: các field không gửi lên sẽ bị ghi đè thành rỗng/0, nên Frontend cần gửi đầy đủ trạng thái checkout mỗi lần gọi.
    • Toàn bộ thao tác này không tạo order, chỉ sync trạng thái checkout vào cart.
  3. Enrich cart data & tính tổng tiền hàng

    • Hệ thống:

      • Chuẩn hóa danh sách item (details[]) từ data trong cart.
      • Áp dụng chính sách giá đang active (active_price_policy_id).
      • Tính price_sell, total_weight, total_item, loại bỏ item không hợp lệ.
  4. Tính phí vận chuyển tạm thời

    • Nếu shipping_type = delivery và có đủ shipping_address, shipping_region_id > 0 và shipping_profile_rate_id > 0:

      • Tính phí theo cấu hình vận chuyển của shop (giá trị đơn, khối lượng, khu vực) và lấy phí của rate có id = shipping_profile_rate_id, gán price_shipping, price_shipping_original.
      • Danh sách rate hợp lệ để khách chọn lấy qua Tính phí vận chuyển.
    • Nếu thiếu thông tin bắt buộc → phí ship = 0, nhưng cart vẫn được quote.

  5. Chạy promotion engine

    • Bước 1 – Bundle evaluate:

      • Áp dụng khuyến mãi theo bundle, cập nhật lại đơn giá từng dòng bundle.
      • Bổ sung bundles_map để track các bundle đang áp dụng.
    • Bước 2 – Cart evaluate:

      • Áp dụng khuyến mãi cấp cart (order / shipping / coupon) dựa trên payload cuối cùng.
      • Cập nhật promotionengine và các trường price_discount_order, price_discount_shipping, price_discount_coupon, price_discount.
  6. Đánh giá loyalty (nếu có điểm redeem)

    • Đánh giá số điểm redeem_points theo chương trình tích điểm của shop.
    • Nếu approved, hệ thống tính price_discount_loyalty và cộng vào tổng giảm giá, trừ vào price_final.
  7. Gắn thông tin quote & trả về kết quả

    • Build price_quote gồm payload, payload_hash, payload_length, date_expired (60 giây sau thời điểm quote) để đảm bảo tính toàn vẹn khi checkout.
    • Trả về toàn bộ cart đã quote (cart object + details + promotionengine + loyalty + price_quote).

Request Body

Body là JSON chứa thông tin checkout để hệ thống sync vào cart và tính quote.

{
  "store_id": 1,
  "pickup_store_id": 0,
  "shipping_type": "delivery",
  "shipping_address_id": 0,
  "shipping_full_name": "Nguyễn Văn A",
  "shipping_phone": "0900000000",
  "shipping_email": "khachhang@example.com",
  "shipping_address": "12 Nguyễn Huệ, P. Bến Nghé",
  "shipping_region_id": 1,
  "shipping_sub_region_id": 0,
  "shipping_sub_sub_region_id": 0,
  "shipping_legacy_province_name": "",
  "shipping_legacy_district_name": "",
  "shipping_legacy_ward_name": "",
  "shipping_profile_rate_id": 0,
  "billing_full_name": "Nguyễn Văn A",
  "billing_phone": "0900000000",
  "billing_email": "khachhang@example.com",
  "billing_address": "12 Nguyễn Huệ, P. Bến Nghé",
  "billing_region_id": 1,
  "billing_sub_region_id": 0,
  "billing_sub_sub_region_id": 0,
  "birthday": "",
  "gender": 0,
  "payment_method": 0,
  "note": "",
  "coupon_code": "",
  "tax_name": "",
  "tax_address": "",
  "tax_email": "",
  "tax_code": "",
  "tax_is_company": 0,
  "redeem_points": 0,
  "gift_selections": []
}
  • shipping_type: delivery (giao hàng), pickup (nhận tại cửa hàng), instore.
  • payment_method: xem bảng payment_method.
  • gift_selections: (không bắt buộc) lựa chọn quà tặng khi chương trình khuyến mãi cho phép khách chọn quà.

Response Schema

HTTP 200 - Thành công

Trả về Customer Cart đã quote. Xem thêm Customer Cart Object Schema.

Các field chính

FieldKiểuMô tả
idintegerID cart.
uuidstringUUID cart.
company_idintegerTenant/company id.
customer_idintegerID khách hàng (0 nếu guest).
sourceintegerNguồn tạo cart.
store_idintegerStore xử lý đơn hàng.
pickup_store_idintegerStore pickup.
shipping_typestringdelivery / pickup / instore.
payment_methodintegerPhương thức thanh toán.
payment_statusintegerTrạng thái thanh toán.
notestringGhi chú đơn hàng.
coupon_codestringMã coupon.
redeem_pointsintegerĐiểm redeem yêu cầu.

Thông tin tổng tiền

FieldKiểuMô tả
price_sellintegerTổng tiền hàng (đã sync đơn giá theo policy/promotion).
price_shippingintegerPhí ship hiện tại (có thể = 0 nếu thiếu dữ liệu ship).
price_shipping_originalintegerPhí ship gốc trước khuyến mãi.
price_discount_orderintegerGiảm giá cấp đơn hàng.
price_discount_shippingintegerGiảm giá phí ship.
price_discount_couponintegerGiảm giá từ coupon.
price_discount_loyaltyintegerGiảm giá từ loyalty (nếu áp dụng).
price_discountintegerTổng giảm giá.
price_finalintegerTổng thanh toán cuối cùng.

Line items & enrich data

FieldKiểuMô tả
detailsarrayDanh sách item đã enrich (tên/ảnh/option/giá/promotionengine).
total_itemintegerTổng số item (tính từ details).
total_weightintegerTổng khối lượng (gram) hoặc tổng cân nặng quy đổi.
active_price_policy_idintegerPolicy giá đang áp dụng để tính details/giá.
website_price_policy_idintegerPolicy giá mặc định website (đối chiếu).
invalid_itemsarrayItem không hợp lệ bị loại khỏi quote.
invalid_items_explainobjectGiải thích invalid item (danh sách id/identifier).
bundles_mapobjectMap bundle identifier → snapshot/metadata bundle promotion.
gift_item_product_infoarray(Storefront) Danh sách product info của các gift item để UI hiển thị.

details[]

(chi tiết từng item)

Mỗi phần tử trong details[] là 1 line item đã enrich từ data trong cart, có thể là standalone item hoặc bundle item.

FieldKiểuMô tả
idintegerIndex của item trong cart.
row_identifierstringKhóa định danh dòng để promotion engine map kết quả.
product_idintegerID sản phẩm.
product_namestringTên sản phẩm.
product_variant_idintegerID biến thể.
is_base_uombooleantrue nếu đang ở UOM base/default.
uom_idintegerID đơn vị tính.
uom_namestringTên đơn vị tính.
uom_quantityintegerSố lượng theo UOM.
uom_unit_priceintegerĐơn giá sau khi áp dụng policy/promotion.
uom_unit_price_originalintegerĐơn giá gốc (đối chiếu), thường theo website price policy.
uom_unit_weightintegerTrọng lượng 1 UOM (gram) sau quy đổi.
selected_optionsarrayDanh sách option đã chọn của variant.
product_optionsarrayMetadata option (Color/Size...) tương ứng selected_options.
imagestringURL ảnh đại diện (variant ưu tiên, fallback product).
customize_requiredinteger1 nếu item yêu cầu tùy biến/ghi chú.
customize_descriptionstringNội dung tùy biến (nếu có).
file_id_listarrayDanh sách file đính kèm (nếu có).
weight_sale_modeintegerChế độ bán theo cân (mapping theo Product).
weight_preset_idstringID preset cân nặng (nếu dùng).
weight_preset_namestringTên preset cân nặng.
weight_preset_factorintegerHệ số quy đổi preset.
pricing_typeintegerKiểu tính giá (nếu có).
bundle_identifierstringBundle identifier (rỗng nếu không phải bundle).
bundle_promotion_idintegerID bundle promotion (0 nếu không phải bundle).
bundle_promotion_product_idintegerID promotion product trong bundle (nếu có).
bundle_promotion_multiplierintegerHệ số số lượng bundle.
bundle_indexintegerIndex item trong bundle (sau evaluate bundle).
bundle_allocation_rulestringRule phân bổ giảm giá của bundle (nếu có).
bundle_discount_allocatedintegerGiảm giá được phân bổ cho dòng bundle (nếu có).
promotionengineobjectKết quả promotion engine ở cấp line item (đặc biệt cho standalone item).

invalid_items[]

invalid_items[] là danh sách item bị loại trong bước enrich (do variant/product không tồn tại/không active, hoặc bundle identifier không hợp lệ...).

Ghi chú: đây là item “thô” theo cấu trúc trong cart.data, nên field có thể khác details[] và có thể thiếu một số metadata (tên/ảnh/đơn giá...).

FieldKiểuMô tả
product_variant_idintegerID biến thể.
product_idintegerID sản phẩm (thường có ở item bundle).
uom_idintegerID UOM.
uom_namestringTên UOM.
uom_quantityintegerSố lượng theo UOM.
selected_optionsarrayOption đã chọn.
weight_sale_modeintegerChế độ bán theo cân.
weight_preset_idstringID preset cân nặng.
weight_preset_namestringTên preset cân nặng.
weight_preset_factorintegerHệ số preset.
pricing_typeintegerKiểu tính giá (nếu có).
bundle_identifierstringBundle identifier (nếu là bundle item).
bundle_promotion_idintegerID bundle promotion (nếu là bundle item).
bundle_promotion_product_idintegerID promotion product trong bundle (nếu có).
bundle_promotion_multiplierintegerMultiplier của bundle (nếu có).

invalid_items_explain

Đối tượng này giúp UI/debug biết vì sao item bị loại và nhóm theo nguyên nhân.

FieldKiểuMô tả
invalid_product_id_listarrayDanh sách product_id không hợp lệ (không tồn tại/không active/không được hiển thị).
invalid_variant_id_listarrayDanh sách product_variant_id không hợp lệ.
invalid_bundle_identifier_listarrayDanh sách bundle_identifier không hợp lệ (liên quan item invalid).

bundles_map

bundles_map là map theo bundle_identifier để mô tả bundle promotion đã được apply sau bước bundle evaluate.

KeyValueMô tả
{bundle_identifier}objectSnapshot/metadata của bundle promotion tương ứng identifier đó.

Các field bên trong mỗi entry có thể thay đổi theo promotion engine, nhưng thường gặp:

FieldKiểuMô tả
promotion_snapshotobjectSnapshot promotion (ví dụ: id, name, type, ...).
itemsarrayDanh sách item thuộc bundle (nếu promotion engine trả về).

Khuyến mãi / Quote / Loyalty

FieldKiểuMô tả
promotionengineobjectQuyết định khuyến mãi cấp cart (order/shipping/coupon).
price_quoteobjectThông tin quote để đối chiếu khi checkout.
price_quote.date_expiredintegerTimestamp hết hạn quote (60 giây sau khi quote).
price_quote.payload_hashstringMD5 hash của payload quote.
price_quote.payload_lengthintegerĐộ dài payload quote.
price_quote.payloadstringPayload quote (JSON stringify).
loyaltyobjectKết quả loyalty redeem evaluate (có thể có warning).
contextobjectContext evaluate (shipping/payment/coupon/source...).

HTTP 422 - Lỗi dữ liệu / logic

Mã lỗiMô tả
error_cart_not_foundKhông tìm thấy giỏ hàng theo uuid.
error_calculate_shipping_price_response_no_data, error_calculate_shipping_price_request_errorKhông tính được phí vận chuyển.
error_from_promotionengines_controller_response_no_data, error_from_promotionengines_controller_request_errorKhông đánh giá được khuyến mãi.

Lỗi khi đánh giá điểm tích lũy không làm request thất bại, mà được trả trong loyalty.warning.

On this page