【发布时间】:2019-03-29 17:57:46
【问题描述】:
我正在尝试向客户的订单历史记录页面添加一个重新订购按钮,以自动重新订购他们已经购买的商品。这会将他们送回购物车,其中包含已预装并准备结帐的物品。每个产品项目都附加了自定义属性。一切似乎都正常,除了当我将商品重新添加到购物车时,我无法显示自定义订单项属性。
我正在使用order-to-cart.liquid sn-p。
在第 18 行,似乎正在调用自定义属性:
properties: {{ line_item.properties | json }}
我已尝试修改代码以添加它们:
request.send(JSON.stringify({
'quantity':order.items[0].quantity,
'id':order.items[0].variant_id,
'properties':order.items[0].properties
}));
但这不起作用。
根据下面的评论,我尝试遍历项目属性:
request.send(JSON.stringify({
'quantity':order.items[0].quantity,
'id':order.items[0].variant_id,
'properties': {
{% for line_item in order.line_items %}
{% for property in line_item.properties %}
'{{ property.first }}': '{{ property.last }}'{% unless forloop.last %},{% endunless %}
{% endfor %}
{% endfor %}
}
}));
但我得到语法错误:
SyntaxError: missing } after property list
note: { opened at line 403, column 26
好像引用了request.send的属性列表
输出的示例json是:
/* Setup the order object. Extend this as needed. */
var order = {
items:[
{
variant_id: 16320547225634,
product_id: 1782978904098,
properties: [["Arrangement Type",""],["Enclosed Card",""],["Occasion \u0026amp; Comments","Condolescens"],["Delivery Date","Mar 29, 2019"]],
available: true
},
{
variant_id: null,
product_id: 1776316743714,
properties: [["Arrangement Type",""],["Enclosed Card",""],["Occasion \u0026amp; Comments",""],["Delivery Date","Mar 24, 2019"]],
available: null
},
{
variant_id: 16319970017314,
product_id: 1782916808738,
properties: [["Arrangement Type","Seasonal"],["Enclosed Card","Love and best wishes"],["Occasion \u0026amp; Comments","Just Because"],["Delivery Date","Mar 25, 2019"]],
available: true
},
{
variant_id: 16311468687394,
product_id: 1780877819938,
properties: [["Arrangement Type","Large vase with orchids"],["Enclosed Card","Steal the warm chair right after you get up when owners are asleep, cry for no apparent reason sleeps on my head."],["Occasion \u0026amp; Comments","Birthday so make extra special!"],["Delivery Date","Apr 10, 2019"]],
available: true
}
]
};
request.send(JSON.stringify({
'quantity':order.items[0].quantity,
'id':order.items[0].variant_id,
'properties': {
'Arrangement Type': '',
'Enclosed Card': '',
'Occasion & Comments': 'Condolescens',
'Delivery Date': 'Mar 29, 2019'
'Arrangement Type': '',
'Enclosed Card': '',
'Occasion & Comments': '',
'Delivery Date': 'Mar 24, 2019'
'Arrangement Type': 'Seasonal',
'Enclosed Card': 'Love and best wishes',
'Occasion & Comments': 'Just Because',
'Delivery Date': 'Mar 25, 2019'
'Arrangement Type': 'Large vase with orchids',
'Enclosed Card': 'Steal the warm chair right after you get up when owners are asleep, cry for no apparent reason sleeps on my head.',
'Occasion & Comments': 'Birthday so make extra special!',
'Delivery Date': 'Apr 10, 2019'
}
}));
我的cart.liquid 文件像这样调用自定义属性:
{% if property_size > 0 %}
{% for p in item.properties %}
{% assign first_character_in_key = p.first | truncate: 1, '' %}
{% unless p.last == blank or first_character_in_key == '_' %}
<div class="label-info">{{ p.first }}:
<strong class="input-info">{{ p.last }}</strong>
</div>
{% endunless %}
{% endfor %}
{% endif %}
但我不确定是否需要修改它以适应任何已创建的属性。
添加回购物车时需要显示自定义订单项属性,否则重新订购功能不会真正节省时间,因为它会迫使客户返回每个产品页面以将信息重新添加到自定义字段。
我对液体不太熟悉,所以不太确定需要做什么来修改 sn-p 或购物车模板。您能提供的任何帮助将不胜感激!
非常感谢, 标记
【问题讨论】:
标签: javascript shopify liquid