商品推荐

你可以通过关联商品查询 Ajax API,获得传入的商品内容相关的商品详细信息

请求信息

GET https://{handle}.myshopline.com/api/product/recommendations/products.json


请求参数:

参数名参数类型是否数组是否必填示例描述
product_idString16063124956315768682381690产品ID
limitString10【1,20】的整数,不传或非法的设置为20
intentStringrelated

用于生成产品推荐的推荐意图。

  • related:和入参商品自身属性相类似的商品,例如运动鞋和皮鞋
  • complementary:和入参商品在商品属性上,可以搭配使用的商品,例如皮鞋和鞋油

响应信息

响应body:

一级参数名二级参数名三级参数名参数类型是否数组示例描述
messageString
descriptionString
productsObject
idString产品ID
titleString产品标题
handleString产品的handle
urlString产品的相对路径,格式为: /products/handle
descriptionString产品的描述
brandString品牌名称
tagsList<String>产品的标签数组
imagesList<String>产品主图数组
featured_imageString产品的特色图,等同于images[0]
mediasObject
resourceString以 URL 形式表示的资源位置
coverString以 URL 形式表示的封面图位置
typeString媒体资源类型
altString具有图像特征或内容的单词或短语
sold_outBoolean是否售罄
priceLong产品售价,等同于price_min
price_minLong产品的最小售价
price_maxLong产品的最大售价
price_variesBoolean表明产品变体的最小售价和最大售价是否一致
compare_at_priceLong变体的原价,等同于 compareAtPriceMin
compare_at_price_minLong变体的最小原价
compare_at_price_maxLong变体的最大原价
compare_at_price_variesBoolean表明产品变体的最小原价和最大原价是否一致
created_atDate产品创建时间
published_atDate产品发布时间
optionsObject选项数组
nameString选项名称
valuesList<String>选项值数组
values_imagesMap<String,String>选项值和选项值图片的映射字典
variantsObject变体数组
idString变体ID
barcodeString条形码
titleString变体标题
option1String变体的第1个选项值
option2String变体的第2个选项值
option3String变体的第3个选项值
option4String变体的第4个选项值
option5String变体的第5个选项值
skuString变体的SKU码
featured_imageString变体图片
nameString变体名称,格式为:产品标题 · 变体标题
public_titleString公共标题,等同于 variant.title
optionsList<String>变体选项数组
weightBigDecimal重量
weight_unitString重量单位
priceLong变体售价,单位为:最小货币精度
compare_at_priceLong变体原价,单位为:最小货币精度
inventory_policyString是否允许超卖,continue:允许,deny:不允许
inventory_trackerBoolean是否追踪库存,默认为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_idString使用特定商品的商品推荐渲染指定的 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>
这篇文章对你有帮助吗?