getProductsByIds
Lấy nhiều sản phẩm theo các id của chúng.
Mô tả
Phương thức này truy xuất các đối tượng sản phẩm dựa trên các định danh (id) của chúng từ API. Nó trả về một Promise mà khi giải quyết sẽ trả về các đối tượng IProductsEntity cho sản phẩm.
Products.getProductsByIds(
ids,
langCode,
userQuery
);
Sơ đồ tham số
Sơ đồ
ids(bắt buộc): string
Các định danh trang sản phẩm mà bạn muốn tìm mối quan hệ
ví dụ: "12345,67890"
langCode: string
Mã ngôn ngữ. Mặc định "en_US"
userQuery: IProductsQuery
Các tham số truy vấn tùy chọn
ví dụ:
{
"limit": 30,
"offset": 0,
"sortOrder": "DESC",
"sortKey": "id",
"signPrice": "orders",
"templateMarker": "template_12345",
"statusMarker": "in_stock",
"conditionValue": "new",
"conditionMarker": "eq",
"attributeMarker": "color"
}
userQuery.offset(bắt buộc): number
Tham số cho phân trang. Mặc định: 0.
userQuery.limit(bắt buộc): number
Tham số cho phân trang. Mặc định: 30.
userQuery.sortOrder(bắt buộc): string
Thứ tự sắp xếp "DESC" | "ASC". Mặc định: "DESC".
userQuery.sortKey(bắt buộc): string
Trường để sắp xếp (mặc định - null). Các giá trị có thể: "id", "position", "title", "date", "price". Mặc định: null.
userQuery.signPrice: string
Dấu giá. Mặc định: null.
userQuery.templateMarker: string | null
Dấu hiệu mẫu trang sản phẩm, mặc định null.
ví dụ: "template_12345"
userQuery.statusMarker: string | null
Dấu hiệu trạng thái trang sản phẩm, mặc định null.
ví dụ: "in_stock"
userQuery.conditionValue: string | null
Giá trị mà bạn đang tìm kiếm, mặc định null.
ví dụ: "new"
userQuery.attributeMarker: string | null
Định danh văn bản của thuộc tính đã được lập chỉ mục mà theo đó các giá trị được lọc, mặc định null.
ví dụ: "color"
userQuery.conditionMarker: string | null
Dấu hiệu của điều kiện lọc mà theo đó các giá trị được lọc, mặc định null.
ví dụ: "equals"
userQuery.langCode: string
Mã ngôn ngữ. Mặc định: "en_US".
userQuery.ids: string
Danh sách các id sản phẩm phân cách bằng dấu phẩy — được sử dụng bởi getProductsByIds.
ví dụ: "1,2,3"
Mặc định, bạn có thể truy xuất 10 đối tượng. Điều này là do giới hạn bản ghi trong cài đặt quyền của mô-đun.
Để phân trang hoạt động chính xác, bạn cần cấu hình Quyền mô-đun theo nhu cầu của bạn trong phần tương ứng.
Ví dụ
Ví dụ tối thiểu
const response = await Products.getProductsByIds('1, 5, 8');
Ví dụ với các thuộc tính
const userQuery = {
"offset": 0,
"limit": 30,
"sortOrder": "DESC",
"sortKey": "id"
};
const response = await Products.getProductsByIds('1, 5, 8', 'en_US', userQuery);
Sử dụng bộ lọc để tìm các sản phẩm cụ thể:
attributeMarker: Định danh văn bản của thuộc tính đã được lập chỉ mục mà theo đó các giá trị được lọc. conditionMarker: Loại điều kiện áp dụng cho giá trị thuộc tính.
| Dấu hiệu | Ý nghĩa | Ví dụ |
|---|---|---|
| eq | Bằng | statusId = 1 (chỉ hoạt động) |
| neq | Không bằng | category ≠ "archived" |
| in | Chứa (một trong số) | category in ["electronics", "books"] |
| nin | Không chứa | brand not in ["fake_brand"] |
| exs | Tồn tại (có giá trị) | Có mô tả |
| nexs | Không tồn tại | Không có hình ảnh |
conditionValue: Giá trị để so sánh.
Ví dụ phản hồi
[
{
"id": 2954,
"attributeSetIdentifier": "products",
"localizeInfos": {
"title": "Box"
},
"statusLocalizeInfos": {
"title": "Sale"
},
"isVisible": true,
"statusIdentifier": "sale",
"position": 2,
"templateIdentifier": "my-template",
"shortDescTemplateIdentifier": "My template description",
"price": 51,
"additional": {
"prices": {
"min": 51,
"max": 150
}
},
"sku": null,
"isSync": true,
"categories": [
"catalog"
],
"paymentStages": [
{
"title": "Part A",
"marker": "part_a",
"value": 100
},
{
"title": "Part B",
"marker": "part_b",
"value": 200
}
],
"rating": {
"votes": 42,
"value": 4.5,
"like": 10,
"dislike": 2,
"method": "weighted"
},
"attributeValues": {
"product-name": {
"type": "string",
"value": "product-name",
"isIcon": false,
"position": 0,
"additionalFields": {},
"isProductPreview": false
},
"price": {
"type": "integer",
"value": 51,
"isIcon": false,
"position": 1,
"additionalFields": {},
"isProductPreview": false
},
"currency_products": {
"type": "string",
"value": "usd",
"isIcon": false,
"position": 2,
"additionalFields": {},
"isProductPreview": false
},
"img": {
"type": "image",
"value": {
"size": 241636,
"filename": "files/project/product/2954/image/7e0a6a70-a23d-410f-8b6a-f8b4f7483244.png",
"contentType": "image/png",
"downloadLink": "https://your-project.oneentry.cloud/cloud-static/files/project/product/2954/image/7e0a6a70-a23d-410f-8b6a-f8b4f7483244.png"
},
"isIcon": false,
"position": 3,
"additionalFields": {},
"isProductPreview": false
}
},
"productPages": [
{
"id": 2847,
"pageId": 10,
"productId": 2954,
"positionId": 3190,
"categoryPath": "catalog"
}
],
"blocks": [
"product_block",
"product_block"
],
"signedPrice": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"moduleFormConfigs": [
{
"id": 12,
"formIdentifier": "review",
"moduleIdentifier": "catalog",
"isGlobal": false,
"isClosed": false,
"isModerate": false,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "catalog",
"isNested": true
}
],
"formDataCount": 374,
"ratingCalculation": "average",
"allowHalfRatings": true,
"maxRatingScale": 5,
"isAnonymous": true,
"allowRerating": true,
"isRating": true,
"entityFormDataCount": {
"2954": 374
},
"nestedEntityIdentifiers": [
"catalog"
],
"exceptionIds": []
}
],
"discountConfig": {
"discounts": [
{
"id": 5,
"identifier": "summer-sale",
"type": "DISCOUNT",
"localizeInfos": {
"title": "Summer Sale"
},
"startDate": "2026-01-01T06:32:19.736Z",
"endDate": "2026-01-28T06:32:22.632Z",
"discountValue": {
"value": 30,
"maxAmount": 0,
"discountType": "FIXED_PRICE",
"applicability": "TO_PRODUCT"
},
"exclusions": [
{
"id": 2
}
],
"position": 3,
"conditionLogic": "OR",
"gifts": [
{
"id": 3,
"localizeInfos": {
"title": "hhh222"
},
"attributeSetIdentifier": "attr-set-1",
"statusIdentifier": null,
"statusLocalizeInfos": {},
"templateIdentifier": null,
"price": 90,
"sku": null,
"attributeValues": {
"price1": {
"type": "integer",
"value": "90",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
}
},
"isVisible": true
}
],
"conditions": [
{
"conditionType": "PRODUCT",
"entityIds": [
{
"id": 4,
"isNested": false
},
{
"isNested": false
}
],
"value": null
},
{
"conditionType": "ATTRIBUTE",
"entityIds": [
{
"isNested": false
}
],
"value": {
"value": "100",
"condition": "eq"
}
}
]
}
],
"discountPrice": 90,
"settings": {
"allowStacking": true,
"maxDiscountValue": 30,
"allowGiftStacking": false
}
}
},
{
"id": 2955,
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Product"
},
"statusLocalizeInfos": {
"title": "Sale"
},
"isVisible": true,
"statusIdentifier": "sale",
"position": 1,
"templateIdentifier": null,
"shortDescTemplateIdentifier": null,
"price": null,
"additional": {
"prices": {
"min": 51,
"max": 150
}
},
"sku": null,
"isSync": false,
"categories": [
"catalog"
],
"paymentStages": null,
"rating": {},
"attributeValues": {},
"productPages": [
{
"id": 2848,
"pageId": 10,
"productId": 2955,
"positionId": 3191,
"categoryPath": "catalog"
}
],
"blocks": [
"product_block",
"product_block"
],
"moduleFormConfigs": [
{
"id": 12,
"formIdentifier": "review",
"moduleIdentifier": "catalog",
"isGlobal": false,
"isClosed": false,
"isModerate": false,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "catalog",
"isNested": true
}
],
"formDataCount": 374,
"ratingCalculation": "average",
"allowHalfRatings": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"2954": 374
},
"nestedEntityIdentifiers": [
"catalog"
],
"exceptionIds": []
}
],
"discountConfig": {}
}
]
Sơ đồ phản hồi
Sơ đồ: IProductsEntity[]
id: number
Định danh duy nhất.
ví dụ: 12345
localizeInfos: ILocalizeInfo
Tên của các sản phẩm, tính đến việc địa phương hóa.
ví dụ:
statusIdentifier: string | null
Các định danh trạng thái trang sản phẩm (có thể là null).
ví dụ: "in_stock"
statusLocalizeInfos: ILocalizeInfo
Tên trạng thái đã được địa phương hóa cho sản phẩm.
ví dụ: { "title": "Sale" }
attributeSetIdentifier: string | null
Tập hợp các id thuộc tính.
ví dụ: "set_12345"
position: number
Số thứ tự mục (để sắp xếp).
ví dụ: 1
price: number | null
Giá trị của giá trang sản phẩm lấy từ chỉ mục.
ví dụ: 150.00
additional: object
Giá trị bổ sung từ chỉ mục.
ví dụ: { prices: { min: 5 max: 150 } }
sku: string | null
SKU sản phẩm (Đơn vị giữ hàng), có thể là null.
ví dụ: "SKU_12345"
isSync: boolean
Chỉ báo về việc lập chỉ mục trang.
ví dụ: true
attributeValues: AttributeType
Mảng các giá trị thuộc tính từ chỉ mục, được đại diện.
ví dụ:
[
{
"id": "color",
"value": "red"
}
]
categories: string[]
Các danh mục sản phẩm.
ví dụ:
[
1,
2,
3
]
isVisible: boolean
Dấu hiệu về tính khả thi của trang.
ví dụ: true
moduleFormConfigs: Array<IFormConfig>
Cấu hình biểu mẫu mô-đun (tùy chọn).
rating: IRating
Dữ liệu đánh giá.
isPositionLocked: boolean
Chỉ báo khóa vị trí sắp xếp (tùy chọn).
ví dụ: false
relatedIds: number[]
Các id của các trang sản phẩm liên quan.
ví dụ:
[
12345,
67890
]
paymentStages: unknown
Dữ liệu các giai đoạn thanh toán (có thể là null).
ví dụ: null
discountConfig: Record<string, unknown>
Đối tượng cấu hình giảm giá.
ví dụ:
templateIdentifier: string | null
Id người dùng của mẫu liên kết.
ví dụ: "template_12345"
shortDescTemplateIdentifier: string | null
Id người dùng của mẫu liên kết cho mô tả ngắn.
ví dụ: "short_desc_template_12345"
signedPrice: string
Dấu giá.
productPages: IProductPageRef[]
Mảng các tham chiếu trang sản phẩm liên kết sản phẩm với các trang của nó.
ví dụ:
[
{
"id": 16,
"pageId": 4,
"productId": 15,
"positionId": 244,
"categoryPath": "products"
}
]
productPages.id: number
Định danh duy nhất của bản ghi liên kết sản phẩm với trang.
ví dụ: 16
productPages.pageId: number
Định danh của trang mà sản phẩm được liên kết tới.
ví dụ: 4
productPages.productId: number
Định danh của sản phẩm.
ví dụ: 15
productPages.positionId: number
Định danh vị trí sắp xếp trong trang.
ví dụ: 244
productPages.categoryPath: string
Đường dẫn danh mục của trang mà sản phẩm thuộc về.
ví dụ: "products"
blocks: string[]
Mảng các định danh khối.
ví dụ:
[
"block_12345",
"block_67890"
]