匯入的 Order Printer 範本疑難排解

當您從舊版 Order Printer app 移轉您的範本至新的 Shopify Order Printer app 時,系統會更新您的 Liquid 變數,以確保與新 app 相容。少數情況下,您可能需要對匯入的範本進行疑難排解。

如果您匯入的範本未正確列印,可能需要在新的 Shopify Order Printer app 中手動編輯範本程式碼。請檢視以下範本可能無法正確匯入的最常見原因:

  • 範本包含自訂 CSS
  • 範本包含中繼欄位
  • Liquid 變數可能未正確更新

本頁提供將自訂範本匯入新的 Shopify Order Printer app 時,如何疑難排解潛在問題的詳細說明。

更新常見 CSS 設計自訂項目

如果您要移轉的範本包含自訂 CSS,可能需要手動更新範本中的 CSS 程式碼,才能正確顯示各種設計元素,例如圖片、自訂字型、標誌或條碼。

更新中繼欄位變數

若要存取中繼欄位,您必須指定該中繼欄位的命名空間,且不需要在變數後加上 .value。深入瞭解中繼欄位定義

例如,請改用 product.metafields.custom.manufacturerid 變數,而不是 product.metafields.custom.manufacturerid.value 變數。

若要確認每個中繼欄位的命名空間值,請參考您 Shopify 管理介面中的 自訂資料 頁面。中繼欄位定義會依其所參照的物件分組,例如商品、子類或訂單。

更新常見 Liquid 變數

多數情況下,您使用的 Liquid 變數會在移轉過程中自動更新。不過,如果範本未正確移轉,且您使用本節列出的變數,則可能需要手動以新變數取代舊變數。Shopify Order Printer app 與舊版 Order Printer app 使用的變數有所不同。

例如,若您使用 date 變數,則需改用 created_at 變數。

訂單變數

訂單變數在 Shopify Order Printer app 中的使用方式不同。若要存取訂單變數,您需要加上 order. 前綴。例如,要存取 billing_address 變數,需使用 order.billing_address

以下常見的訂單變數,無需加上 order. 前綴即可存取:

  • line_items
  • tax_lines
  • fulfillments
  • transactions
  • refunds
  • shipping_methods
  • customer

例如,若要存取商品項目變數,您可以使用 line_itemsorder.line_items

您也可以在範本中自行建立別名變數。例如,您可以使用 {% assign fulfillments_count = order.fulfillments | size %} 的 Liquid 語法,接著在程式碼中以 {{ fulfillments_count }} 來引用。

訂單變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
line_items
  • 已退款的商品項目 不會包含在 line_items 變數中。請參閱以下詳情:
    • 您可以使用 refunds.<each>.refund_line_items 變數來存取已退款的商品項目。請檢閱下列範例:
      {% assign refunded_line_items = refunds | map: "refund_line_items" | map: "line_item" %}
    • 如有需要,您可以將已退款的商品項目加入 line_items 集合中。請檢閱下列範例:
      {% assign refunded_line_items = order.refunds | map: "refund_line_items" | map: "line_item" %} {% assign line_items_with_refunded = order.line_items | concat: refunded_line_items | uniq %}
    • 請務必加入 | uniq 過濾器,以避免重複計入已退款的商品項目。
  • 小費商品項目 不會包含在 line_items 變數中。請參閱以下詳情:
    • 您可以使用 tip_line_items 變數來存取小費商品項目。
    • 如有需要,您可以將 tip_line_items 加入 line_items 集合中。請檢閱下列範例:
      {% assign line_items_with_tips = order.line_items | concat: order.tip_line_items %}
  • 若要模擬舊版 Order Printer 的 line_items 集合,您可以使用下列範例程式碼:
    {% assign refunded_line_items = refunds | map: "refund_line_items" | map: "line_item" %} {% assign all_line_items = order.line_items | concat: refunded_line_items | concat: order.tip_line_items | uniq %} {% for line_item in all_line_items %} ... {% endfor %}
credit_card請使用 transactions.<each>.payment_details 變數,依訂單中的每筆交易取得付款詳情。
current_shipping_priceshipping_price
date請改用 created_at 變數。使用 date 過濾器來格式化時間戳記,例如:{{ order.created_at | date: "%B %e, %Y" }}
gatewaysunique_gatewaystransactions.<each>.gateway
order_currencycurrency
processed_at使用 created_at 變數。此變數的值等同於來自 GraphQL API 的 order.processed_at,代表訂單實際處理的時間,而非訂單匯入 Shopify 的時間。它與舊版 Order Printer app 的 order.processed_at 相同。您可以使用 date 篩選器來格式化時間戳記,例如:{{ order.created_at | date: "%B %e, %Y" }}
payment_transactions

在 Liquid 語法中,透過 where 針對 order.transactionskind 狀態進行篩選,或使用迴圈並在內部加入 if。請參考以下範例。

{% assign sale_transactions = order.transactions | where: "kind", "sale" %} {% assign capture_transactions = order.transactions | where: "kind", "capture" %} {% for transaction in transactions %} {% if transaction.kind == "sale" or transaction.kind == "capture" %} Transaction ID: {{ transaction.id }} Kind: {{ transaction.kind }} Amount: {{ transaction.amount | money }} {% endif %} {% endfor %}

{% assign sale_transactions = order.transactions | where: "kind", "sale" %} {% assign capture_transactions = order.transactions | where: "kind", "capture" %} {% assign payment_transactions = sale_transactions | concat: capture_transactions %}

refund_transactions在 Liquid 語法中,使用 where 透過 order.transactions 篩選 kind 狀態,或是透過迴圈以及內部的 if 進行篩選,如下列範例所示:
{% assign refund_transactions = order.transactions | where: "kind", "refund" %}
shipping_lineshipping_methods | first
shipping_linesshipping_methods
show_line_item_taxestax_lines.size > 0。您可以在範本開頭將其定義為變數並多次參照此變數,如下列範例所示:
{% if tax_lines.size > 0 %} {% assign show_line_item_taxes = true %} {% else %} {% assign show_line_item_taxes = false %} {% endif %}
total_taxtax_price
total_paidnet_payment

LineItem 變數

LineItem 變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
fulfillable_quantityquantity - successfully_fulfilled_quantity
fulfilledquantity == successfully_fulfilled_quantity
nametitle
product_titleproduct.title
unit_discountquantity ? line_level_total_discount / quantity : 0
variant_titlevariant.title
weightgrams

出貨作業變數

出貨作業變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
datecreated_at

商店變數

商店變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
owneraccount_owner.name
addressshop.address.address1
address2shop.address.address2
cityshop.address.city
countryshop.address.country
country_codeshop.address.country_code
provinceshop.address.province
province_codeshop.address.province_code
zipshop.address.zip

地址變數

地址變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
latitude如果 address 變數參照自 location 屬性,則 location 物件本身即會提供緯度和經度。
longitude如果 address 變數參照自 location 屬性,則 location 物件本身即會提供緯度和經度。

退款變數

退款變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
date請改用 created_at 變數。使用 date 過濾器來格式化時間戳記,例如:{{ order.created_at | date: "%B %e, %Y" }}

ShippingLine 變數

ShippingLine 變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
current_priceprice
priceoriginal_price

交易變數

以下交易變數已移除,且無法在 Shopify Order Printer app 中替代:

  • authorization
  • message
  • test

子類變數

子類變數
舊版 Order Printer app 中的變數新版 Shopify Order Printer app 中的變數
gramsweight

中繼欄位變數

若要存取中繼欄位,您需要指定該中繼欄位的命名空間,且不需要在變數後加上 .value。 瞭解詳情:metafield definitions

例如,請不要使用 product.metafields.manufacturerid.value 變數,改用 product.metafields.custom.manufacturerid 變數。

若要找出每個中繼欄位的命名空間值,請參考 Shopify 管理介面中的 Custom data 頁面。中繼欄位定義會依其參照的物件分組,例如商品、子類或訂單。

過濾器對應

過濾器對應
舊版 Order Printer app 的過濾器名稱新版 Shopify Order Printer app 的過濾器名稱
files_urlfile_url
payment_methodpayment_methods請在訂單交易上使用 transaction.gateway_display_name 欄位。付款方式不再劃分為特定類型,例如 {credit card, debit card, bank transfer}。舊版 Order Printer app 僅將目前可用的少數付款閘道對應到這些類別。付款閘道提供者會在其系統中管理顧客所使用的付款方式類型。