Nhảy đến nội dung

getBlocks

Lấy tất cả các đối tượng khối.

Mô tả

Phương thức này trả về mảng tất cả các đối tượng khối và tổng số. Nó trả về một Promise mà khi hoàn thành sẽ trả về một đối tượng IBlocksResponse.

Blocks.getBlocks(

type*, langCode, offset, limit

);

Sơ đồ tham số

Sơ đồ

type(bắt buộc): BlockType
Các giá trị khả dụng: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none"
ví dụ: 'product'

langCode: string
Mã ngôn ngữ. Mặc định: "en_US"
ví dụ: "en_US"

offset: number
Tham số cho phân trang. Mặc định: 0
ví dụ: 0

limit: number
Tham số cho phân trang. Mặc định: 30
ví dụ: 30

Mặc định, bạn có thể lấy 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 Blocks.getBlocks('forTextBlock');

Ví dụ với thuộc tính

const response = await Blocks.getBlocks('forTextBlock', 'en_US', 0, 30);

Ví dụ phản hồi

{
"items": [
{
"id": 3,
"localizeInfos": {
"title": "Block"
},
"version": 0,
"position": 1,
"identifier": "block",
"type": "common_block",
"templateIdentifier": null,
"isVisible": true,
"attributeValues": {}
},
{
"id": 4,
"localizeInfos": {
"title": "test"
},
"version": 31,
"position": 2,
"identifier": "test",
"type": "common_block",
"templateIdentifier": null,
"isVisible": true,
"attributeValues": {
"block-text": {
"type": "string",
"value": "some text",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
},
"interval": {
"type": "timeInterval",
"value": [
{
"values": [
{
"id": "bbc82c9f-1bc4-4c86-b83c-c062016eb7cb",
"dates": [
"2025-04-14T00:00:00.000Z",
"2025-04-14T00:00:00.000Z"
],
"times": [
[
{
"hours": 9,
"minutes": 0
},
{
"hours": 10,
"minutes": 0
}
],
[
{
"hours": 10,
"minutes": 0
},
{
"hours": 11,
"minutes": 0
}
],
[
{
"hours": 11,
"minutes": 0
},
{
"hours": 12,
"minutes": 0
}
],
"..."
],
"intervals": [],
"exceptions": [],
"intervalId": "c6466cd8-c55d-4583-97c5-42b684210f12",
"inEveryWeek": true,
"inEveryMonth": true,
"timeIntervals": [
[
"2025-04-07T09:00:00.000Z",
"2025-04-07T10:00:00.000Z"
],
[
"2025-04-07T10:00:00.000Z",
"2025-04-07T11:00:00.000Z"
],
[
"2025-04-07T11:00:00.000Z",
"2025-04-07T12:00:00.000Z"
],
"..."
]
}
],
"intervalId": "c6466cd8-c55d-4583-97c5-42b684210f12"
}
],
"isIcon": false,
"position": 1,
"additionalFields": [],
"isProductPreview": false
}
}
}
],
"total": 2
}

Sơ đồ phản hồi

Sơ đồ: IBlocksResponse

total: number
Tổng số bản ghi tìm thấy.
ví dụ: 100

items: IBlockEntity[]
Mảng các thực thể khối.
ví dụ:

[
{
"attributeValues": [],
"id": 1,
"identifier": "block1",
"isVisible": true,
"localizeInfos": {
"key": "value"
},
"position": 1,
"templateIdentifier": null,
"type": "product",
"version": 1,
"countElementsPerRow": 3,
"quantity": 9,
"similarProducts": {
"total": 0,
"items": []
},
"products": [
{
"id": 1,
"name": "Product 1"
},
{
"id": 2,
"name": "Product 2"
}
]
}
]