【问题标题】:How can I create a list with previous ordered products in Shopify?如何在 Shopify 中创建包含以前订购的产品的列表?
【发布时间】:2023-03-10 16:55:02
【问题描述】:

有什么方法可以在 Shopify 中创建先前订购的商品列表以及图片? 基本上我所追求的是首页上用户之前购买的 3 件商品的列表。

【问题讨论】:

  • 我真的不知道该尝试什么
  • 您要解决的解决方案是什么?您打算将这些信息用于何处等。您的问题确实没有提供关于您要解决的问题的详细信息。
  • 这需要特定于用户吗?这些用户之前是否已经登录(通过用户帐户),还是您只是想做一些诸如炫耀热门物品之类的事情?
  • 这就是问题所在,它应该是特定于用户的。如果您没有登录,您将看不到任何内容。
  • 查看 javascript API 以查看您是否可以访问用户帐户令牌或 ID。如果你能做到这一点,有一个 JSONP 端点或提供用户购买的产品(或放入他们以前放弃的购物车)并显示它们的东西。您可以编写自己的 API,根据 Shopify API 的各个部分提供详细信息、产品链接和图片链接。

标签: php html css shopify


【解决方案1】:

用户需要登录才能进行以下操作。如果用户已登录,那么您可以使用以下代码来显示他们的订单。这将仅显示 3 个订单。

{% if customer.orders.size != 0 %}
<table>
  <thead>
    <tr>
      <th class="order_number">Order</th>
      <th class="date">Date</th>
      <th class="payment_status">Payment Status</th>
      <th class="fulfillment_status">Fulfillment Status</th>
      <th class="total">Total</th>
    </tr>
  </thead>
  <tbody>
  {% for order in customer.orders limit:3 %}
    <tr class="{% cycle 'odd', 'even' %} {% if order.cancelled %}cancelled_order{% endif %}">
      <td>{{ order.name | link_to: order.customer_url }}</td>
      <td><span class="note">{{ order.created_at | date: "%b %d, %Y" }}</span></td>
      <td><span class="status_{{ order.financial_status }}">{{ order.financial_status }}</span></td>
      <td><span class="status_{{ order.fulfillment_status }}">{{ order.fulfillment_status }}</span></td>
      <td><span class="total money">{{ order.total_price | money }}</span></td>
    </tr>
  {% endfor %}
  </tbody>
</table>
{% else %}
    <p>You haven't placed any orders yet.</p>
{% endif %}

【讨论】:

    【解决方案2】:

    当客户登录时,将有一个customerliquid 变量可用,其中包含有关该用户的大量数据。如果您查看docs,有一个名为order 的成员变量将为您提供所有用户订单的数组。还有一个名为recent_order 的变量将为您提供用户最近的订单。

    如果您熟悉 Shopify 使用的 Liquid 模板语言,这应该足以让您入门。一般来说,Shopify wiki 很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 2011-08-03
      相关资源
      最近更新 更多