xStore.collections
Bộ sưu tập — nhóm sản phẩm do chủ cửa hàng tự gom, độc lập với cây danh mục.
Phương thức
| Phương thức | Cú pháp | Mô tả | Từ phiên bản |
|---|---|---|---|
list |
xStore.collections.list({ limit }): Promise<CursorPaginatedResponse<Collection>> |
Danh sách bộ sưu tập đang hiển thị. | 2.1 |
getBySlug |
xStore.collections.getBySlug(slug): Promise<Collection> |
Chi tiết bộ sưu tập theo slug. | 2.1 |
Ví dụ đầy đủ
<script>
// Bộ sưu tập là dữ liệu tham chiếu có giới hạn: gọi một lần, dùng lại.
async function renderCollections() {
const bst = await xStore.collections.list({ limit: 50 });
document.getElementById('collections').innerHTML = bst.items.map((b) =>
`<a href="${b.url ?? '#'}">${b.title}</a>`).join('');
}
// Trang bộ sưu tập: slug → id, rồi lọc sản phẩm theo id đó.
async function renderCollectionPage(slug) {
const bst = await xStore.collections.getBySlug(slug);
const sp = await xStore.products.list({ collection: bst.id, limit: 24 });
console.log(bst.title, sp.items.length);
}
renderCollections();
</script>
Thư viện gọi tới /api/... trên chính tên miền cửa hàng, nên không cần khai báo địa chỉ máy chủ ở bất kỳ đâu.
Xem thêm Sự kiện để giao diện tự cập nhật sau mỗi thao tác.