Lewati ke konten utama

getBlocks

Mengambil semua objek blok.

Deskripsi

Metode ini mengembalikan array dari semua objek blok dan totalnya. Ini mengembalikan sebuah Promise yang menyelesaikan menjadi objek IBlocksResponse.

Blocks.getBlocks(

type, langCode, offset, limit

);

Skema parameter

Skema

type: BlockType
Tipe blok opsional untuk difilter. Nilai yang tersedia: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none". Jika diabaikan, blok dari semua tipe akan dikembalikan
contoh: 'product'

langCode: string
Kode bahasa. Default: "en_US"
contoh: "en_US"

offset: number
Parameter untuk paginasi. Default: 0
contoh: 0

limit: number
Parameter untuk paginasi. Default: 30
contoh: 30

Secara default, Anda dapat mengambil 10 objek. Ini disebabkan oleh batasan jumlah rekaman dalam pengaturan izin modul.
Agar paginasi berfungsi dengan benar, Anda perlu mengonfigurasi Izin modul sesuai kebutuhan Anda di bagian yang sesuai.

Contoh

Contoh minimal

const response = await Blocks.getBlocks('forTextBlock');

Contoh dengan atribut

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

Contoh respons

{
"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
}

Skema respons

Skema: IBlocksResponse

total: number
Jumlah total rekaman yang ditemukan.
contoh: 100

items: IBlockEntity[]
Array dari entitas blok.
contoh:

[
{
"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"
}
]
}
]

items.attributeValues: IAttributeValues
Peta nilai atribut yang dikunci oleh penanda; objek kosong jika tidak ada.
contoh:

{
"block-text": {
"type": "string",
"value": "some text",
"isIcon": false,
"position": 0,
"additionalFields": [],
"isProductPreview": false
}
}

items.id: number
Pengidentifikasi unik dari blok.
contoh: 1234

items.localizeInfos: ILocalizeInfo
Informasi lokalisasi untuk blok.
contoh:

{
"key": "value"
}

items.version: number
Versi dari entitas blok.
contoh: 1

items.identifier: string
Pengidentifikasi string unik untuk blok.
contoh: "block1"

items.type: BlockType
Tipe dari blok.
contoh: "product"

items.position: number
Posisi blok untuk pengurutan.
contoh: 1

items.templateIdentifier: string | null
Pengidentifikasi untuk template yang digunakan oleh blok, atau null jika tidak berlaku.
contoh: "template1"

items.isVisible: boolean
Menunjukkan apakah blok terlihat.
contoh: true

items.countElementsPerRow: number
Jumlah elemen yang ditampilkan per baris dalam blok, jika berlaku.
contoh: 3

items.quantity: number
Jumlah item dalam blok, jika berlaku.
contoh: 5

items.similarProducts: IProductsResponse
Respons yang berisi produk serupa yang terkait dengan blok.
contoh:

{
"total": 10,
"items": []
}

items.products: IProductsEntity[]
Array dari entitas produk yang terkait dengan blok.
contoh:

[
{
"id": 1,
"name": "Product 1"
},
{
"id": 2,
"name": "Product 2"
}
]