{"id":813,"date":"2022-07-02T21:06:12","date_gmt":"2022-07-02T20:06:12","guid":{"rendered":"http:\/\/blog.chen-hongyi.com\/?p=813"},"modified":"2022-07-04T20:21:42","modified_gmt":"2022-07-04T19:21:42","slug":"shopify%e7%9a%84%e6%a8%a1%e6%9d%bf%e8%af%ad%e8%a8%80liquid","status":"publish","type":"post","link":"https:\/\/chen-hongyi.com\/?p=813","title":{"rendered":"shopify\u7684\u6a21\u677f\u8bed\u8a00liquid"},"content":{"rendered":"\n<p>shopify\u4f7f\u7528\u4e86 liquid \u4f5c\u4e3a\u81ea\u5df1\u6a21\u677f\u8bed\u8a00\u3002\u5728\u6211\u770b\u6765liquid\u662fsmarty\u7684\u540e\u7ee7\u8005\u3002<\/p>\n\n\n\n<p><br>Shopify\u7684\u6587\u6863 (<a href=\"https:\/\/shopify.dev\/api\/liquid\">\u94fe\u63a5<\/a>) \uff08github\uff09\u5e38\u7528\u7684\u5bf9\u8c61(<a href=\"https:\/\/shopify.dev\/api\/liquid\/objects\">object<\/a>) (<a href=\"https:\/\/www.shopify.com\/partners\/shopify-cheat-sheet?shpxid=caa8564d-7192-40FD-281A-F10F000FD271\">cheat sheet<\/a>)<\/p>\n\n\n\n<p>github \uff08<a href=\"https:\/\/github.com\/Shopify\/liquid\">\u94fe\u63a5<\/a>\uff09<\/p>\n\n\n\n<p><strong>\u4f5c\u54c11<\/strong> \u6309\u7167meta\u4fe1\u606f\u6392\u5e8f.<br><\/p>\n\n\n\n<p>\u57fa\u672c\u601d\u8def\u5c31\u662f\u5728\u5faa\u73af\u663e\u793a\u4e4b\u524d\uff0c\u5148\u5faa\u73af\u4e00\u904d\uff0c\u628a\u4fe1\u606f\u53d6\u51fa\u6765\u540e\uff0c\u5355\u72ec\u4fdd\u5b58\u5230\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4\u5185\u3002\u7136\u540e\u5bf9\u8fd9\u4e2a\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{% assign newArray = false %}\n\n{% for line_item in line_items %}\n\t{% assign newOrder = line_item.product.metafields.regalnummer.value  | default:'' %}\n\t{% assign matrix = newOrder | append:'.'  | append:forloop.index0 %}\n\t{% if newArray %}\n\t\t{% assign tmpIndex = matrix | split:',' %}\n\t\t{% assign newArray = newArray | concat:tmpIndex %}\n\t{% else %}\n\t\t{% assign newArray = matrix | split:',' %}\n\t{% endif %}\n{% endfor %}\n\n{% assign newArray = newArray | sort %}\n\n<\/code><\/pre>\n\n\n\n<p>\u663e\u793a\u7684\u65f6\u5019\u5c31\u6309\u7167\u8fd9\u4e2a\u65b0\u7684\u6570\u7ec4\u8fdb\u884c\u5faa\u73af<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    {% for newArrayItem in newArray %}\n     \t{% assign i = newArrayItem | split:'.' | last | times: 1 %}\n     \t{% assign rowObj =line_items&#91;i]  %} \n        &lt;tr&gt;\n            &lt;td&gt;{{ rowObj.quantity }} x&lt;\/td&gt;\n            &lt;td&gt;({{ rowObj.variant.inventory_quantity }})&lt;\/td&gt;\n            &lt;td&gt;{{ rowObj.product.metafields.regalnummer.value }}&lt;\/td&gt;\n            &lt;td&gt;{{ rowObj.variant.barcode }}&lt;\/td&gt;\n&lt;!--        &lt;td&gt;{{ rowObj.product.metafields.exp.value }}&lt;\/td&gt; --&gt;\n            &lt;td&gt;{{ rowObj.sku }}&lt;\/td&gt;\n            &lt;td&gt;{{ rowObj.vendor }}&lt;\/td&gt;\n            &lt;td&gt;{{ rowObj.title }}&lt;\/td&gt;\n            &lt;td style=\"text-align: right;\"&gt;\n                {{ rowObj.price | money }}&lt;\/td&gt;\n    \t\t&lt;td style=\"text-align: right;\"&gt;\n    \t\t    {{ rowObj.price | times:rowObj.quantity | money }}&lt;\/td&gt;\n    \t\t&lt;td style=\"text-align: right;\"&gt;\n                {% assign a = rowObj.grams %}\n                {% assign b = rowObj.quantity %}\n                {{ a | times: b }}&lt;\/td&gt;\n        &lt;\/tr&gt;\n    {% endfor %}<\/code><\/pre>\n\n\n\n<p>\u6700\u7ec8\u6548\u679c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/blog.chen-hongyi.com\/wp-content\/uploads\/2022\/07\/Screenshot_2022-07-02_21-54-38.png\"><img loading=\"lazy\" decoding=\"async\" width=\"675\" height=\"277\" src=\"http:\/\/blog.chen-hongyi.com\/wp-content\/uploads\/2022\/07\/Screenshot_2022-07-02_21-54-38.png\" alt=\"\" class=\"wp-image-815\" srcset=\"https:\/\/chen-hongyi.com\/wp-content\/uploads\/2022\/07\/Screenshot_2022-07-02_21-54-38.png 675w, https:\/\/chen-hongyi.com\/wp-content\/uploads\/2022\/07\/Screenshot_2022-07-02_21-54-38-300x123.png 300w, https:\/\/chen-hongyi.com\/wp-content\/uploads\/2022\/07\/Screenshot_2022-07-02_21-54-38-500x205.png 500w\" sizes=\"auto, (max-width: 675px) 100vw, 675px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>shopify\u4f7f\u7528\u4e86 liquid \u4f5c\u4e3a\u81ea\u5df1\u6a21\u677f\u8bed\u8a00\u3002\u5728\u6211\u770b\u6765liquid\u662fsm &hellip; <a href=\"https:\/\/chen-hongyi.com\/?p=813\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-813","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=\/wp\/v2\/posts\/813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=813"}],"version-history":[{"count":5,"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions"}],"predecessor-version":[{"id":820,"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions\/820"}],"wp:attachment":[{"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chen-hongyi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}