商品推荐
你可以通过关联商品查询 Ajax API,获得传入的商品内容相关的商品详细信息
请求信息
GET
https://{handle}.myshopline.com/api/product/recommendations/products.json
请求参数:
参数名 | 参数类型 | 是否数组 | 是否必填 | 示例 | 描述 |
---|---|---|---|---|---|
product_id | String | 否 | 是 | 16063124956315768682381690 | 产品ID |
limit | String | 否 | 否 | 10 | 【1,20】的整数,不传或非法的设置为20 |
intent | String | 否 | 否 | related | 用于生成产品推荐的推荐意图。
|
响应信息
响应body:
一级参数名 | 二级参数名 | 三级参数名 | 参数类型 | 是否数组 | 示例 | 描述 |
---|---|---|---|---|---|---|
message | String | 否 | ||||
description | String | 否 | ||||
products | Object | |||||
id | String | 否 | 产品ID | |||
title | String | 否 | 产品标题 | |||
handle | String | 否 | 产品的handle | |||
url | String | 否 | 产品的相对路径,格式为: /products/handle | |||
description | String | 否 | 产品的描述 | |||
brand | String | 否 | 品牌名称 | |||
tags | List<String> | 否 | 产品的标签数组 | |||
images | List<String> | 否 | 产品主图数组 | |||
featured_image | String | 否 | 产品的特色图,等同于images[0] | |||
medias | Object | |||||
resource | String | 否 | 以 URL 形式表示的资源位置 | |||
cover | String | 否 | 以 URL 形式表示的封面图位置 | |||
type | String | 否 | 媒体资源类型 | |||
alt | String | 否 | 具有图像特征或内容的单词或短语 | |||
sold_out | Boolean | 否 | 是否售罄 | |||
price | Long | 否 | 产品售价,等同于price_min | |||
price_min | Long | 否 | 产品的最小售价 | |||
price_max | Long | 否 | 产品的最大售价 | |||
price_varies | Boolean | 否 | 表明产品变体的最小售价和最大售价是否一致 | |||
compare_at_price | Long | 否 | 变体的原价,等同于 compareAtPriceMin | |||
compare_at_price_min | Long | 否 | 变体的最小原价 | |||
compare_at_price_max | Long | 否 | 变体的最大原价 | |||
compare_at_price_varies | Boolean | 否 | 表明产品变体的最小原价和最大原价是否一致 | |||
created_at | Date | 否 | 产品创建时间 | |||
published_at | Date | 否 | 产品发布时间 | |||
options | Object | 选项数组 | ||||
name | String | 否 | 选项名称 | |||
values | List<String> | 否 | 选项值数组 | |||
values_images | Map<String,String> | 否 | 选项值和选项值图片的映射字典 | |||
variants | Object | 变体数组 | ||||
id | String | 否 | 变体ID | |||
barcode | String | 否 | 条形码 | |||
title | String | 否 | 变体标题 | |||
option1 | String | 否 | 变体的第1个选项值 | |||
option2 | String | 否 | 变体的第2个选项值 | |||
option3 | String | 否 | 变体的第3个选项值 | |||
option4 | String | 否 | 变体的第4个选项值 | |||
option5 | String | 否 | 变体的第5个选项值 | |||
sku | String | 否 | 变体的SKU码 | |||
featured_image | String | 否 | 变体图片 | |||
name | String | 否 | 变体名称,格式为:产品标题 · 变体标题 | |||
public_title | String | 否 | 公共标题,等同于 variant.title | |||
options | List<String> | 否 | 变体选项数组 | |||
weight | BigDecimal | 否 | 重量 | |||
weight_unit | String | 否 | 重量单位 | |||
price | Long | 否 | 变体售价,单位为:最小货币精度 | |||
compare_at_price | Long | 否 | 变体原价,单位为:最小货币精度 | |||
inventory_policy | String | 否 | 是否允许超卖,continue:允许,deny:不允许 | |||
inventory_tracker | Boolean | 否 | 是否追踪库存,默认为false |
请求、响应示例
场景1:获取和请求的商品相似的商品
请求
fetch("https://{handle}.myshopline.com/recommendations/products.json?product_id=1515707502717517&limit=2")
响应
{
"products": [
{
"id": "16050982612893754143333867",
"title": "Fashion Women Dresses Summer Boho Dot Print High Waist Shirt Dress",
"handle": "fashion-women-dresses-summer-boho-dot-print-high-waist-shirt-dress",
"url": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"description": "",
"brand": "aliexpress",
"images": [
"https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png"
],
"price": 2499,
"options": [
{
"name": "Size",
"values": [
"S",
"M",
"L",
"XL"
],
"values_images": {
"S": "",
"L": "",
"XL": "",
"M": ""
}
},
{
"name": "Color",
"values": [
"Green",
"Black",
"Navy blue",
"Orange",
"White",
"Yellow"
],
"values_images": {
"Navy blue": "",
"White": "",
"Yellow": "",
"Black": "",
"Orange": "",
"Green": ""
}
}
],
"variants": [
{
"id": "18050982612895096320523867",
"title": "S · Green",
"option1": "S",
"option2": "Green",
"name": "Fashion Women Dresses Summer Boho Dot Print High Waist Shirt Dress · S · Green",
"options": [
"S",
"Green"
],
"price": 2499,
"featured_image": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"public_title": "S · Green",
"compare_at_price": 2799,
"inventory_policy": "deny",
"inventory_tracker": false
}
],
"medias": [
{
"resource": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"type": "IMAGE"
}
],
"sold_out": false,
"price_min": 2499,
"price_max": 2499,
"price_varies": true,
"compare_at_price": 2799,
"compare_at_price_min": 2799,
"compare_at_price_max": 2799,
"compare_at_price_varies": true,
"created_at": "2021-10-14T18:42:42.172+0800",
"published_at": "2022-06-10T17:16:06.225+0800"
},
{
"id": "16050982612893754143333867",
"title": "Fashion Women Dresses Summer Boho Dot Print High Waist Shirt Dress",
"handle": "fashion-women-dresses-summer-boho-dot-print-high-waist-shirt-dress",
"url": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"description": "",
"brand": "aliexpress",
"images": [
"https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png"
],
"price": 2499,
"options": [
{
"name": "Size",
"values": [
"S",
"M",
"L",
"XL"
],
"values_images": {
"S": "",
"L": "",
"XL": "",
"M": ""
}
},
{
"name": "Color",
"values": [
"Green",
"Black",
"Navy blue",
"Orange",
"White",
"Yellow"
],
"values_images": {
"Navy blue": "",
"White": "",
"Yellow": "",
"Black": "",
"Orange": "",
"Green": ""
}
}
],
"variants": [
{
"id": "18050982612895096320523867",
"title": "S · Green",
"option1": "S",
"option2": "Green",
"name": "Fashion Women Dresses Summer Boho Dot Print High Waist Shirt Dress · S · Green",
"options": [
"S",
"Green"
],
"price": 2499,
"featured_image": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"public_title": "S · Green",
"compare_at_price": 2799,
"inventory_policy": "deny",
"inventory_tracker": false
}
],
"medias": [
{
"resource": "https://img.myshopline.com/image/official/e46e6189dd5641a3b179444cacdcdd2a.png",
"type": "IMAGE"
}
],
"sold_out": false,
"price_min": 2499,
"price_max": 2499,
"price_varies": true,
"compare_at_price": 2799,
"compare_at_price_min": 2799,
"compare_at_price_max": 2799,
"compare_at_price_varies": true,
"created_at": "2021-10-14T18:42:42.172+0800",
"published_at": "2022-06-10T17:16:06.225+0800"
}
]
}
场景2:请求的商品ID不存在
请求
fetch("https://{handle}.myshopline.com/recommendations/products.json?product_id=unrealproducthandle&limit=2")
响应
{
"message": "Not found",
"description": "No product with id unrealproducthandle is published in the online store."
}
请求信息
通过关联商品查询Ajax API,获得使用特定商品的商品推荐的 HTML
GET
https://{handle}.myshopline.com/recommendations/products
请求参数:
/recommendations/products 接口支持与 /recommendations/products.json 接口相同的请求参数,此外还支持以下参数
参数名 | 参数类型 | 是否数组 | 是否必填 | 示例 | 描述 |
---|---|---|---|---|---|
section_id | String | 否 | 是 | 使用特定商品的商品推荐渲染指定的 section 的 id |
请求、响应示例
场景1:获取和请求的商品相似的商品,并返回之相关的 product-recommendations
section
请求
fetch("https://{handle}.myshopline.com/recommendations/products?section_id=product-recommendations&product_id=16062607064082767035242730&limit=4")
响应
<div id="shopline-section-product-recommendations" class="shopline-section section"><link rel="dns-prefetch" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:500|Poppins:300&display=swap" media="all"><script src="https://cdn-theme.myshopline.com/cdn/shop/staging/dba005190e58b252f9b5375cdf5655d9/1e1469e90101fc13326468baf942861d35b898010bfea7ec8104618ce6628ff9/assets/section-product-recommendations.js" defer></script>
<link href="https://cdn-theme.myshopline.com/cdn/shop/staging/dba005190e58b252f9b5375cdf5655d9/436d85ae1988b0e9b29422d0b99598825f39904323e19480489124c2b458f099/assets/component-price.css" rel="stylesheet" type="text/css" media="all">
<link href="https://cdn-theme.myshopline.com/cdn/shop/staging/dba005190e58b252f9b5375cdf5655d9/8549aa245f65304059205682cb36acf56f5849ba3a9a647664c20d4d55b064f6/assets/component-card.css" rel="stylesheet" type="text/css" media="all">
<style>
#shopline-section-product-recommendations.section-padding, #shopline-section-product-recommendations .section-padding {
padding-top: 80px;
padding-bottom: 80px;
}
@media only screen and (max-width: 959px) {
#shopline-section-product-recommendations.section-padding, #shopline-section-product-recommendations .section-padding {
padding-top: 40px;
padding-bottom: 40px;
}
}
</style>
<div class="page-width section-padding color-scheme-none">
<product-recommendations
data-url="/recommendations/products?section_id=product-recommendations&product_id=16062607064082767035242730&limit=4"
>
<h2 class="title4 title-wrapper text-center">
You may also like
</h2>
<div class="grid grid-cols-4-desktop grid-cols-2">
<li>
<div
class="product-card-wrapper card card-wrapper product-card-style-normal
"
style="--card-image-padding: 0px;
--color-card-background: 244, 247, 251;
--color-card-text: 41, 37, 44;"
>
<a href="/products/%E5%8C%85%E5%AD%90">
<div class="card__inner global-product-card-border-shadow">
<div class="ratio"
style="--ratio-percent: 150%;
--image-fill-type: contain;
--badge-border-radius: 0px;"
>
<div class="card__media media--hover-effect">
<img src="https://d2n979dmt31clo.cloudfront.net/image/store/1655365532096/-(2).jpeg?w=275&h=183" alt="包子" width="275" height="183" sizes="(max-width: 959px) calc(100vw * 1/2),(min-width: 960px) calc(100vw * 1/4)" fetchpriority="high" decoding="async" data-scale="hover-scale" loading="eager" class="collection-hero__image">
</div>
</div>
<div class="card__badge left_bottom "></div>
</div>
<div class="card__content ">
<h3 class="product__title body3 full-display ">
包子
</h3>
<div class="price ">
<div class="price__container">
<div class="price__regular">
<span class="body2 fw-bold price-item price-item--regular">HK$0.00</span>
</div>
</div>
</div>
</div>
</a>
</div>
</li>
</div>
</product-recommendations>
</div>
</div>
这篇文章对你有帮助吗?