Chi tiết sản phẩm

API để lấy thông tin chi tiết của một sản phẩm, bao gồm phân loại, thuộc tính và giá flash sale

Endpoint
GET https://api.socdo.vn/mini-app/v1/get-detail-product
        
Request Headers
Token-Seller: YOUR_TOKEN_SELLER
Shop-ID: 23933 (optional, có thể dùng query parameter)

Hoặc:

Authorization: Bearer YOUR_TOKEN_SELLER
Shop-ID: 23933 (optional, có thể dùng query parameter)
        
Query Parameters
Parameter Type Required Description
product_id int Yes ID của sản phẩm cần lấy chi tiết
shop_id int Yes ID của shop (có thể dùng header Shop-ID)
include_variants int No Có bao gồm phân loại sản phẩm (1: có, 0: không) - Mặc định: 1
Response Structure
{
    "success": true,
    "message": "Lấy chi tiết sản phẩm thành công",
    "data": {
        "id": 83063,
        "sp_id": 0,
        "shop_id": 23933,
        "title": "Vợt muỗi điện Syntex SM400",
        "image": "/uploads/minh-hoa/vot-muoi-dien-syntex-sm400.jpg",
        "image_url": "https://socdo.vn/uploads/minh-hoa/vot-muoi-dien-syntex-sm400.jpg",
        "link": "vot-muoi-dien-syntex-sm400",
        "link_aff": "",
        "category_shop": "14629",
        "status": 1,
        "stock": 99,
        "original_price": 500000,
        "current_price": 250000,
        "brand": "2888",
        "color": "0",
        "size": "0",
        "weight": "300",
        "images": "/uploads/minh-hoa/0/sm400-1757578479.jpg",
        "images_list": [
            "https://socdo.vn/uploads/minh-hoa/0/sm400-1757578479.jpg"
        ],
        "view": 10,
        "date_post": 1757578920,
        "active": 0,
        "weight_ship": 300,
        "warehouse_id": 240,
        "variants": [
            {
                "id": 7465,
                "product_id": 82957,
                "sku": "1373NW_250908105201_2",
                "color": "1194",
                "size": "0",
                "size_name": "+",
                "color_name": "60 viên",
                "weight": 200.00,
                "original_price": 1500000,
                "current_price": 1100000,
                "drop_price": 0,
                "ctv_price": 770000,
                "socdo_price": 0,
                "drop_min": 0,
                "stock": 10,
                "weight_ship": 563.00,
                "date_post": 1757303618,
                "image": "",
                "image_url": "",
                "attributes": [
                    {
                        "attribute_id": 1,
                        "attribute_name": "Màu sắc",
                        "value_id": 23,
                        "value_name": "Màu ghi"
                    },
                    {
                        "attribute_id": 2,
                        "attribute_name": "Kích thước",
                        "value_id": 25,
                        "value_name": "Xám đen"
                    }
                ],
                "flash_sale_price": 1000000,
                "flash_sale": true
            }
        ],
        "variants_count": 1,
        "flash_sale": true,
        "promotion_label": "Khuyến mãi hot"
    }
}
        
JavaScript Example
// Lấy chi tiết sản phẩm với phân loại
const response = await fetch('/mini-app/v1/get-detail-product?product_id=83063&shop_id=23933&include_variants=1', {
    method: 'GET',
    headers: {
        'Token-Seller': 'YOUR_TOKEN_SELLER',
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

// Lấy chi tiết sản phẩm không có phân loại
const simpleResponse = await fetch('/mini-app/v1/get-detail-product?product_id=83063&shop_id=23933&include_variants=0', {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer YOUR_TOKEN_SELLER',
        'Content-Type': 'application/json'
    }
});

// Kiểm tra flash sale
if (data.data.flash_sale) {
    console.log('Sản phẩm đang trong chương trình flash sale!');
    console.log('Nhãn khuyến mãi:', data.data.promotion_label);
}

// Hiển thị thông tin phân loại
data.data.variants.forEach(variant => {
    console.log(`Variant ${variant.id}:`, variant);
    if (variant.attributes && variant.attributes.length > 0) {
        console.log('Thuộc tính:', variant.attributes);
    }
});
        
cURL Example
# Lấy chi tiết sản phẩm
curl -X GET "https://api.socdo.vn/mini-app/v1/get-detail-product?product_id=83063&shop_id=23933" \
  -H "Token-Seller: YOUR_TOKEN_SELLER" \
  -H "Content-Type: application/json"

# Lấy chi tiết sản phẩm không có phân loại
curl -X GET "https://api.socdo.vn/mini-app/v1/get-detail-product?product_id=83063&shop_id=23933&include_variants=0" \
  -H "Authorization: Bearer YOUR_TOKEN_SELLER" \
  -H "Content-Type: application/json"

# Sử dụng header Shop-ID thay vì query parameter
curl -X GET "https://api.socdo.vn/mini-app/v1/get-detail-product?product_id=83063" \
  -H "Token-Seller: YOUR_TOKEN_SELLER" \
  -H "Shop-ID: 23933" \
  -H "Content-Type: application/json"
        
Chi tiết thuộc tính sản phẩm

Mỗi variant có thể có thông tin thuộc tính từ bảng attributesattribute_values:

  • Màu sắc: Lấy từ phanloai_sanpham_shop.colorattribute_values
  • Kích thước: Lấy từ phanloai_sanpham_shop.sizeattribute_values
  • Điều kiện ẩn: Nếu size = 0ten_size = '+', thuộc tính kích thước sẽ không được hiển thị
  • Flash Sale: Tự động kiểm tra và cập nhật giá nếu sản phẩm đang trong chương trình flash sale
Flash Sale Pricing

API tự động kiểm tra flash sale cho sản phẩm:

  • Điều kiện: Sản phẩm phải trong main_product của bảng deal
  • Thời gian: date_start ≤ thời gian hiện tại ≤ date_end
  • Status: status = 2 (Đăng sàn)
  • Giá mới: Lấy từ sub_product JSON với gia_cugia
  • Nhãn: Tự động thêm promotion_label: "Khuyến mãi hot"
  • Variants: Giá flash sale được áp dụng cho từng variant tương ứng
Cấu trúc dữ liệu Variant
Field Type Description
id int ID của variant
product_id int ID của sản phẩm chính
sku string Mã SKU của variant
color string ID màu sắc (tham chiếu attribute_values)
size string ID kích thước (tham chiếu attribute_values)
size_name string Tên kích thước
color_name string Tên màu sắc
original_price int Giá cũ (có thể bị flash sale ghi đè)
current_price int Giá hiện tại (có thể bị flash sale ghi đè)
flash_sale_price int Giá flash sale (chỉ có nếu đang flash sale)
flash_sale bool Đang trong flash sale?
stock int Số lượng tồn kho
attributes array Danh sách thuộc tính (màu sắc, kích thước)
Error Responses
// Product_ID không hợp lệ
HTTP 400
{
    "message": "Product_ID không hợp lệ"
}

// Không tìm thấy sản phẩm
HTTP 404
{
    "success": false,
    "message": "Không tìm thấy sản phẩm"
}

// Token không hợp lệ
HTTP 401
{
    "message": "Không tìm thấy Token-Seller"
}

// Shop_ID không khớp
HTTP 401
{
    "message": "Shop_ID không khớp với Token-Seller"
}

// Lỗi hệ thống
HTTP 500
{
    "success": false,
    "message": "Lỗi hệ thống",
    "error": "Chi tiết lỗi"
}