导航
Menu API 用于获取店铺的导航菜单,以及某个菜单内的层级菜单项。两个 endpoint 匿名访客都可以调用。
所有 Ajax API 请求应使用多语言 URL,以便为访客提供一致的体验。
获取导航菜单列表
GET /{locale}/api/front/menus
获取店铺的导航菜单列表,每个菜单都带层级菜单项。没有参数。
请求示例
fetch(window.SHOPLAZZA.routes.root + '/api/front/menus')
.then((response) => response.json())
.then((data) => {
// do something...
});
响应
- 数据结构
- 示例
- Array [
- Array [
- ]
- ]
data object[]
响应数据主体。
idstring
导航菜单的 ID。
titlestring
导航菜单的名称。
categorynumber
children object[]
该导航项下的子项。
idnumber
导航项的 ID。
titlestring
导航项展示的文字。
origin_typenumber
typestring
导航项指向的资源类型,例如 home、page、collection。
source_idstring
导航项指向资源的 ID。
urlstring
导航项指向的相对地址。
pidnumber
父级导航项的 ID,0 表示顶级导航项。
statusnumber
disablednumber
targetstring
导航项的打开方式,例如 _blank 表示新标签页打开。
url_obj object
导航项的结构化链接信息。
typestring
导航项指向的资源类型,例如 home、page、collection。
source_idstring
导航项指向资源的 ID。
urlstring
导航项指向的相对地址。
titlestring
导航项展示的文字。
expandedboolean
msgstring
响应返回的结果说明。
statenumber
请求结果标识,success 或 0 表示请求成功。
{
"data": [
{
"id": "header",
"title": "Main menu",
"category": 1,
"children": [
{
"id": 83850217,
"title": "Home",
"origin_type": 15,
"type": "home",
"source_id": "0",
"url": "/",
"pid": 0,
"status": 0,
"disabled": 0,
"target": "",
"url_obj": {
"type": "home",
"source_id": "0",
"url": "/",
"title": ""
},
"expanded": true
},
{
"id": 83850219,
"title": "New Arrivals",
"origin_type": 3,
"type": "page",
"source_id": "0",
"url": "",
"pid": 0,
"status": 0,
"disabled": 0,
"target": "",
"url_obj": {
"type": "page",
"source_id": "0",
"url": "",
"title": ""
},
"expanded": true,
"children": [
{
"id": 83850221,
"title": "Collection",
"origin_type": 2,
"type": "collection",
"source_id": "0",
"url": "",
"pid": 83850219,
"status": 0,
"disabled": 0,
"target": "",
"url_obj": {
"type": "collection",
"source_id": "0",
"url": "",
"title": ""
},
"expanded": true
}
]
}
]
}
],
"msg": "请求成功",
"state": 0
}
获取单个导航菜单
GET /{locale}/api/front/menus/{menu_id}
获取单个导航菜单及其层级菜单项。menu_id 取菜单的 handle,例如 header 或 footer。
请求示例
fetch(window.SHOPLAZZA.routes.root + '/api/front/menus/header')
.then((response) => response.json())
.then((data) => {
// do something...
});
请求参数
menu_idstring
菜单的 handle,例如 header。
响应
- 数据结构
- 示例
- Array [
- ]
data object
响应数据主体。
idstring
导航菜单的 ID。
titlestring
导航菜单的名称。
categorynumber
children object[]
该导航项下的子项。
idnumber
导航项的 ID。
titlestring
导航项展示的文字。
origin_typenumber
typestring
导航项指向的资源类型,例如 home、page、collection。
source_idstring
导航项指向资源的 ID。
urlstring
导航项指向的相对地址。
pidnumber
父级导航项的 ID,0 表示顶级导航项。
statusnumber
disablednumber
targetstring
导航项的打开方式,例如 _blank 表示新标签页打开。
url_obj object
导航项的结构化链接信息。
typestring
导航项指向的资源类型,例如 home、page、collection。
source_idstring
导航项指向资源的 ID。
urlstring
导航项指向的相对地址。
titlestring
导航项展示的文字。
expandedboolean
msgstring
响应返回的结果说明。
statenumber
请求结果标识,success 或 0 表示请求成功。
{
"data": {
"id": "header",
"title": "Main menu",
"category": 1,
"children": [
{
"id": 83850217,
"title": "Home",
"origin_type": 15,
"type": "home",
"source_id": "0",
"url": "/",
"pid": 0,
"status": 0,
"disabled": 0,
"target": "",
"url_obj": {
"type": "home",
"source_id": "0",
"url": "/",
"title": ""
},
"expanded": true
},
{
"id": 83850219,
"title": "New Arrivals",
"origin_type": 3,
"type": "page",
"source_id": "0",
"url": "",
"pid": 0,
"status": 0,
"disabled": 0,
"target": "",
"url_obj": {
"type": "page",
"source_id": "0",
"url": "",
"title": ""
},
"expanded": true,
"children": [
{
"id": 83850221,
"title": "Collection",
"origin_type": 2,
"type": "collection",
"source_id": "0",
"url": "",
"pid": 83850219,
"status": 0,
"disabled": 0,
"target": "",
"url_obj": {
"type": "collection",
"source_id": "0",
"url": "",
"title": ""
},
"expanded": true
}
]
}
]
},
"msg": "请求成功",
"state": 0
}