Magento 2 REST API-按段塞获取产品,或在REST搜索中获取媒体

Magento 2 REST API-按段塞获取产品,或在REST搜索中获取媒体,rest,magento,magento2,Rest,Magento,Magento2,我有一个余烬应用程序,我用它作为前端。我需要从RESTAPI获取产品,但我需要使用slug,而不是使用SKU。因此,我访问了以下工作正常的端点:http://*.com/index.php/rest/V1/products?searchCriteria[filter_-groups][0][filters][0][field]=url_-key和searchCriteria[filter_-groups][0][filters][0][value]=daniels icecream slug 但

我有一个余烬应用程序,我用它作为前端。我需要从RESTAPI获取产品,但我需要使用slug,而不是使用SKU。因此,我访问了以下工作正常的端点:
http://*.com/index.php/rest/V1/products?searchCriteria[filter_-groups][0][filters][0][field]=url_-key和searchCriteria[filter_-groups][0][filters][0][value]=daniels icecream slug


但是,结果显然是一个产品列表,而不是产品端点,因此省略了一些数据。即,
media\u gallery\u条目
字段。那么,我是否可以在
/products?searchCriteria
端点中返回此数据,或者是否有一种方法可以为产品端点获取
/products/:slug
而不是
/products/:sku

V1/products/?searchCriteria[filterGroups][0][filters][0][field]=url_key&searchCriteria[filterGroups][0][filters][0][value]=%shirt%&searchCriteria[filterGroups][0][filters][0][condition_type]=like
参数:

注意:确保根据您的要求在值中添加前缀和后缀
%


我在我的api调用中使用了相同的方法,它可以工作

我使用的是Magento v2.2,当我进行搜索时,每个项目都有一个
图像
属性(在
自定义属性
列表中),当向产品添加图像时,mangento会自动将该属性添加到产品中:

{
  "items": [{
    "sku": "MH07-XS-Black",
    "name": "Hero Hoodie-XS-Black",
    "custom_attributes": [{
        "attribute_code": "description",
        "value": "<p>Gray and black color blocking sets you apart as the Hero Hoodie keeps you warm on the bus, campus or cold mean streets. Slanted outsize front pockets keep your style real . . . convenient.</p>\n<p>&bull; Full-zip gray and black hoodie.<br />&bull; Ribbed hem.<br />&bull; Standard fit.<br />&bull; Drawcord hood cinch.<br />&bull; Water-resistant coating.</p>"
      },
      {
        "attribute_code": "image",
        "value": "/m/h/mh07-black_main.jpg"
      },
      {
        "attribute_code": "small_image",
        "value": "/m/h/mh07-black_main.jpg"
      },
      {
        "attribute_code": "thumbnail",
        "value": "/m/h/mh07-black_main.jpg"
      },
      {
        "attribute_code": "color",
        "value": "49"
      },
      {
        "attribute_code": "minimal_price",
        "value": "54.0000"
      },
      {
        "attribute_code": "category_ids",
        "value": [
          "15"
        ]
      },
      {
        "attribute_code": "options_container",
        "value": "container2"
      },
      {
        "attribute_code": "required_options",
        "value": "0"
      },
      {
        "attribute_code": "has_options",
        "value": "0"
      },
      {
        "attribute_code": "url_key",
        "value": "hero-hoodie-xs-black"
      },
      {
        "attribute_code": "msrp_display_actual_price_type",
        "value": "0"
      },
      {
        "attribute_code": "tax_class_id",
        "value": "2"
      },
      {
        "attribute_code": "size",
        "value": "167"
      }
    ]
  }]
}
{
“项目”:[{
“sku”:“MH07 XS黑色”,
“姓名”:“英雄连帽衫XS黑色”,
“自定义_属性”:[{
“属性代码”:“说明”,
“价值”:"灰色和黑色拼接设计让你与众不同,因为英雄连帽衫在公交车、校园或寒冷的街道上让你保持温暖。倾斜的超大前口袋让你的风格保持真实……便捷。

\n&bull;全拉链灰色和黑色连帽衫。
&bull;罗纹下摆。
&bull;标准合身。
&bull;抽绳连帽衫扣紧。
&bull;防水涂层。

” }, { “属性代码”:“图像”, “值”:“/m/h/mh07-black_main.jpg” }, { “属性代码”:“小图像”, “值”:“/m/h/mh07-black_main.jpg” }, { “属性代码”:“缩略图”, “值”:“/m/h/mh07-black_main.jpg” }, { “属性代码”:“颜色”, “值”:“49” }, { “属性代码”:“最低价格”, “价值”:“54.0000” }, { “属性代码”:“类别ID”, “价值”:[ "15" ] }, { “属性\代码”:“选项\容器”, “值”:“容器2” }, { “属性\u代码”:“必需的\u选项”, “值”:“0” }, { “属性\代码”:“具有\选项”, “值”:“0” }, { “属性\代码”:“url \密钥”, “价值”:“英雄连帽衫xs黑色” }, { “属性代码”:“msrp显示\实际\价格\类型”, “值”:“0” }, { “属性代码”:“税类id”, “值”:“2” }, { “属性代码”:“大小”, “值”:“167” } ] }] }
因此,这将返回所有产品字段,如获取单个产品?它将返回与url键匹配的产品集合,该url键不回答我的问题-我需要获取产品上的
媒体库项
数据对象,我需要按产品段获取产品。
/products/
忽略
media_gallery_条目
字段,但是
/products/:sku
检索它。我需要获取相同的数据集并从slug中提取产品。
{
  "items": [{
    "sku": "MH07-XS-Black",
    "name": "Hero Hoodie-XS-Black",
    "custom_attributes": [{
        "attribute_code": "description",
        "value": "<p>Gray and black color blocking sets you apart as the Hero Hoodie keeps you warm on the bus, campus or cold mean streets. Slanted outsize front pockets keep your style real . . . convenient.</p>\n<p>&bull; Full-zip gray and black hoodie.<br />&bull; Ribbed hem.<br />&bull; Standard fit.<br />&bull; Drawcord hood cinch.<br />&bull; Water-resistant coating.</p>"
      },
      {
        "attribute_code": "image",
        "value": "/m/h/mh07-black_main.jpg"
      },
      {
        "attribute_code": "small_image",
        "value": "/m/h/mh07-black_main.jpg"
      },
      {
        "attribute_code": "thumbnail",
        "value": "/m/h/mh07-black_main.jpg"
      },
      {
        "attribute_code": "color",
        "value": "49"
      },
      {
        "attribute_code": "minimal_price",
        "value": "54.0000"
      },
      {
        "attribute_code": "category_ids",
        "value": [
          "15"
        ]
      },
      {
        "attribute_code": "options_container",
        "value": "container2"
      },
      {
        "attribute_code": "required_options",
        "value": "0"
      },
      {
        "attribute_code": "has_options",
        "value": "0"
      },
      {
        "attribute_code": "url_key",
        "value": "hero-hoodie-xs-black"
      },
      {
        "attribute_code": "msrp_display_actual_price_type",
        "value": "0"
      },
      {
        "attribute_code": "tax_class_id",
        "value": "2"
      },
      {
        "attribute_code": "size",
        "value": "167"
      }
    ]
  }]
}