首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Shopify中提取产品数据

在Shopify中提取产品数据
EN

Stack Overflow用户
提问于 2018-04-18 15:47:45
回答 1查看 1.2K关注 0票数 1

我正在为我的网站制作我自己的产品滑块。我有自己的动态部分,在‘定制主题’中,您可以选择5个产品。

我可以通过{{ section.setings.Product-1}来完成产品处理,但是如何获得产品id、产品名称、产品价格、产品形象url等等?

像{{ product.title }}这样的东西不起作用,因为它不知道从哪里提取信息。

我目前的代码是:

代码语言:javascript
复制
<div class="wrapper">
  <div class="section-header text-center">
    <h2 class="h1 section-header__title"> {{ section.settings.text-box }} 
    </h2>
  </div>

  <div class="rte">

    <div class="gallery js-flickity" data-flickity-options='{ "freeScroll": true, "wrapAround": true }'>
       <div class="gallery-cell"> </div>
       <div class="gallery-cell"> Text </div>
       <div class="gallery-cell"> Text </div>
       <div class="gallery-cell"> Text </div> 
   </div>
 </div>
</div>

{% schema %}
{
"name": "Featured Slider",
"settings": [

{
    "id" : "text-box",
    "type" : "text",
    "label" : "Title of Section",
    "default" : "Featured Products"
},

{
    "type" : "product",
    "id" : "product-1",
    "label" : "Featured Product"
},

{
    "type" : "product",
    "id" : "product-2",
    "label" : "Featured Product"
},

{
    "type" : "product",
    "id" : "product-3",
    "label" : "Featured Product"
},

{
    "type" : "product",
    "id" : "product-4",
    "label" : "Featured Product"
},

{
    "type" : "product",
    "id" : "product-5",
    "label" : "Featured Product"
}],

"presets": [
    {
    "name" : "Featured Product Slider",
    "category" : "Allsops Sections"
    }
        ]
 }
{% endschema %}

因此,这个想法是在每个画廊-细胞div将是不同的产品。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-18 16:23:47

看起来你在使用一个很棒的部分,但是你并没有以一种有用的方式使用它。

各节为您的代码逻辑块(即动态内容)提供了一个非常好的补充。

代码语言:javascript
复制
{% schema %}
{
    "name": "Featured Slider",
    "settings": [
        {
            "id" : "text-box",
            "type" : "text",
            "label" : "Title of Section",
            "default" : "Featured Products"
        }
    ],
    "blocks": [
        {
            "type": "slide",
            "name": "Slide",
            "settings": [
            {
                "id": "product",
                "type": "product",
                "label": "Featured Products"
            }
            ]
        }
    ],
    "presets": [
        {
            "name" : "Featured Product Slider",
            "category" : "Allsops Sections"
        }
    ]
}
{% endschema %}

{% for block in section.blocks %}
    {% assign product = all_products[block.settings.product] %}
    <div class="slider">
        <a href="{{ product.url }}">
            <img src="{{ product.featured_image | img_url: 'master' }}">
            {{ product.title }}
        </a>
    </div>
    ...
{% endfor %}

通过这种方式,您可以添加尽可能多的幻灯片,并按您喜欢的方式重新排序。

至于您的问题,您可以使用all_products对象获取特定对象。在我提供的模式中,您可以看到我在这里使用它,{% assign product = all_products[block.settings.product] %}

请注意,all_products 只允许20个请求,除此之外,它还会抛出一个液体错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49903932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档