用于Shopify的调试液

用于Shopify的调试液,shopify,Shopify,我真的很困惑,不明白为什么我的{{time}}返回一个空值 我试图计算当前时间和Shopify中的预订时间之间的差异。对于预订,我将日期(第一行项目属性)和时间(第二行)分开。我想将一个变量添加到另一个变量中,然后将其与当前时间进行比较,但在计算之前,我已尝试显示我创建的不同变量。 {{now}&{{date}工作正常,但对于{time}它返回一个空值。另一方面,如果不给它赋值,我只显示行.item.property,它工作正常 你能帮我理解我做错了什么吗 {% assign today =

我真的很困惑,不明白为什么我的
{{time}}
返回一个空值

我试图计算当前时间和Shopify中的预订时间之间的差异。对于预订,我将日期(第一行项目属性)和时间(第二行)分开。我想将一个变量添加到另一个变量中,然后将其与当前时间进行比较,但在计算之前,我已尝试显示我创建的不同变量。
{{now}
&
{{date}
工作正常,但对于
{time}
它返回一个空值。另一方面,如果不给它赋值,我只显示
行.item.property
,它工作正常

你能帮我理解我做错了什么吗

  {% assign today = 'now' | date: '%s' %}
  {% for order in customer.orders %}
    {%- for line_item in order.line_items -%}
      {% for property in line_item.properties limit:1 %} 
        {% assign date = property.last | date: '%s' %}
      {% endfor %}
      {% for property in line_item.properties offset:1 %}
        {% assign time = property.last | date: '%s' %}
      {% endfor %}
    {%- endfor -%}
    {{ now }} - {{ date }} - {{ time }}
  {% endfor %}

通过使用
plus:0
可以将
字符串
转换为
整数
,这将启用用于比较的数学运算

  {% assign today = 'now' | date: '%s' | plus: 0 %}
使用
{%进行检查,除非第_行item.properties==empty%}
查看属性是否存在

{%assign date=property.last | date:“%s”%}
,变量
属性。last
必须在格式良好的日期之后才能工作

偏移量问题:1
,如果数组只有1个
行\u项。属性
这将根本不会运行。因此,
时间
为空;或者它存在但
属性。last
没有
日期格式

{% assign today = 'now' | date: '%s' | plus: 0 %}
{% for order in customer.orders %}
  {%- for line_item in order.line_items -%}

    {% unless line_item.properties == empty %}
        {% for property in line_item.properties %}
            {% if forloop.index == 1 %}
                {% assign date = property.last | date: '%s' | plus: 0 %}
                {% if date == 0 %}
                    {% comment %}Opp! Not A Date, Terminate loop{% endcomment %}
                    {% break %}
                {% endif %}
            {% else %}
                {% assign time = property.last | date: '%s' | plus: 0 %}
                {% unless time == 0 %}
                    {% assign date = date - time %}
                {% endunless %}
            {% endif %}
        {% endfor %}
    {% endunless %}
{% endfor %}

{{today - date}}

谢谢查尔斯,这真的帮了我的忙。 在这里发布我的最终版本,因为我需要比较准确的时间,而不仅仅是订单日期

      {% assign now_date = 'now' | date: '%s' | plus: 0 %}
  {% assign now_time = 'now' | date: '%s' | plus: 0 %}
    {% for order in customer.orders %}
        {%- for line_item in order.line_items -%}
            {% for property in line_item.properties limit:1 %}
                {% assign booking_date = property.last | date: '%s' | plus: 0 %}
            {% endfor %}
            {% for property in line_item.properties offset:1 limit:1 %}
                {% assign booking_time = property.last | date: '%s' | plus: 0 %}
            {% endfor %}
            {% assign date_to_compare = booking_date | plus: '86400' %}
                {% unless now_date > date_to_compare %}
                  {% if now_time <= booking_time or now_date <= booking_date %}SEANCE A VENIR{% endif %}            
                {% endunless %}
        {%- endfor -%}
    {% endfor %}
{%assign now_date='now'|日期:'%s'|加上:0%}
{%assign now_time='now'|日期:'%s'|加上:0%}
{对于customer.orders%中的订单,}
{%-用于订单中的第_行项目。第_行项目-%}
{第_行中属性的%item.properties限制:1%}
{%assign booking_date=property.last|date:“%s”加上:0%}
{%endfor%}
{第_行中的属性为%item.properties偏移量:1限制:1%}
{%assign booking_time=property.last |日期:'%s'|加上:0%}
{%endfor%}
{%assign date_to_compare=booking_date|plus:'86400%}
{%除非现在\u日期>日期\u到\u比较%}

{%if now_time所以我可以通过使用捕获而不是分配向前推进,但我只前进了一步。我现在可以提取当前时间和日期以及预订时间和日期。我还捕获了当前日期和预订日期之间的差异以及当前时间和预订时间。但是当我想检查差异是正还是负时,我得到一个错误,说“液体错误:字符串与0的比较失败”。
      {% assign now_date = 'now' | date: '%s' | plus: 0 %}
  {% assign now_time = 'now' | date: '%s' | plus: 0 %}
    {% for order in customer.orders %}
        {%- for line_item in order.line_items -%}
            {% for property in line_item.properties limit:1 %}
                {% assign booking_date = property.last | date: '%s' | plus: 0 %}
            {% endfor %}
            {% for property in line_item.properties offset:1 limit:1 %}
                {% assign booking_time = property.last | date: '%s' | plus: 0 %}
            {% endfor %}
            {% assign date_to_compare = booking_date | plus: '86400' %}
                {% unless now_date > date_to_compare %}
                  {% if now_time <= booking_time or now_date <= booking_date %}SEANCE A VENIR{% endif %}            
                {% endunless %}
        {%- endfor -%}
    {% endfor %}