LoginSignup
12
7

More than 1 year has passed since last update.

【Shopify】liquidのオブジェクトについてまとめてみた (order, page, page_discription)

Last updated at Posted at 2021-02-21

はじめに

この記事は、Liquid オブジェクトについて日本語訳したものです。

order, page, page_discriptionオブジェクトをまとめていきます。

order オブジェクト

orderオブジェクトには、customer.ordersテンプレートからアクセスすることができます。

価格や合計などの金額の属性は、顧客の現地通貨で表示されます。結果を金額として表示するには、money filterを使用します。

orderオブジェクトの属性についてそれぞれ見ていきます。

order.attributes

order.attributesは、注文のカスタムカート属性がある場合にその属性を返します。
カートにカスタム属性を好きなだけ追加することができます。詳しくはこちら

order.attributes属性をループいている時は、{{ attribute | first }}を使って属性名を取得し、{{ attribute | last }}を使ってその値を取得することができます。

Input
{% if order.attributes %}
  <p>Order notes:</p>
  <ul>
    {% for attribute in order.attributes %}
      <li><strong>{{ attribute | first }}</strong>: {{ attribute | last }}</li>
    {% endfor %}
  </ul>
{% endif %}
Output
<p>Order notes:</p>
<ul>
  <li><strong>Message to merchant</strong>: I love your products! Thanks!</li>
</ul>

order.billing_address

order.billing_addressは、注文の請求書先住所を返します。

order.cancelled

order.cancelledは、注文がキャンセルされた場合にtrueを、キャンセルされなかった場合にfalseを返します。

order.cancelled_at

order.cancelled_atは、注文がキャンセルされた日時のタイムスタンプを返します。タイムスタンプの書式設定にはdateフィルタを使用します。

order.cancel_reason

order.cancel_reasonは、注文がキャンセルされた場合に、以下のキャンセル理由のいずれかを返します。

  • items unavailable
  • fraudulent order
  • customer changed/cancelled order
  • other.

order.cancel_reason_label

order.cancel_reason_labelは、注文のorder.cancel_reasonの翻訳された出力を返します。

Input
English: {{ order.cancel_reason }}
Japanese: {{ order.cancel_reason_label }}
Output
English: Items unavailable
Japanese: 商品は入手できません

order.cart_level_discount_applications

order.cart_level_discount_applicationsは、注文に対する注文固有のdiscount applicationsの配列を返します。discount_applicationオブジェクトについて、詳しくはこちら

Input
{% for discount_application in order.cart_level_discount_applications %}
  Discount name: {{ discount_application.title }}
  Savings: -{{ discount_application.total_allocated_amount | money }}
{% endfor %}
Output
Discount name: SUMMER16
Savings: -¥2,000

order.created_at

order.created_atは、注文が作成された時刻のタイムスタンプを返します。dateフィルタを使用してタイムスタンプをフォーマットします。

order.customer

order.customerは、注文に関連する顧客を返します。

order.customer_url

order.customer_urlは、顧客が注文にアクセスするために使用できる一意のURLを返します。

Input
{{ order.name | link_to: order.customer_url }}
Output

<p>Order notes:</p>
<a href="http://unreact.myshopify.com/account/orders/d94ec4a1956f423dc4907167c9ef0413">#1235</a>

order.discount_applications

order.discount_applicationsは、注文に対するdiscount applicationsの配列を返します。

Input
{% for discount_application in order.discount_applications %}
  Discount name: {{ discount_application.title }}
  Savings: -{{ discount_application.total_allocated_amount | money }}
{% endfor %}
Output
<p>Order notes:</p>
Discount name: SUMMER16
Savings: -¥2,000

order.email

order.emailは、注文に関連付けられたメールアドレスが存在する場合に、そのメールアドレスを返します。

order.financial_status

order.financial_statusは、注文のfinancial_statusを返します。取り得る値は以下の通りです。

  • pending
  • authorized
  • paid
  • partially_paid
  • refunded
  • partially_refunded
  • voided

order.financial_status_label

order.financial_status_labelは、注文のfinancial_statusの翻訳された出力を返します。

Input
English: {{ order.financial_status }}
Japanese: {{ order.financial_status_label }}
Output
English: Paid
Japanese: 支払い済

order.fulfillment_status

order.fulfillment_statusは、注文のフルフィルメント状態を返します。

order.fulfillment_status_label

order.fulfillment_status_labelは、注文のfulfillment_statusの翻訳された出力を返します。

Input
English: {{ order.fulfillment_status }}
Japanese: {{ order.fulfillment_status_label }}
Output
English: Unfulfilled
Japanese: 未発送

order.line_items

order.line_itemsは、注文のラインアイテムの配列を返します。

order.line_items_subtotal_price

order.line_items_subtotal_priceは、注文のラインアイテムの価格の合計を、ラインアイテムの割引を適用した後の価格で返します。
小計金額には、カート割引、税金(価格に税金が含まれていない場合)、送料は含まれていません。

Input
<!-- subtotal = カートの合計金額 - ラインアイテムの割引額 -->
Subtotal: {{ order.line_items_subtotal_price | money }}
Output
<!-- ¥5,000の商品をカートに入れて¥500の割引があると -->
Subtotal: ¥4,500

order.location

order.locationは、注文の物理的な場所を返します(POSのみ)。Shopify管理者のロケーション設定でロケーションを設定することができます。

order.name

order.nameは、Shopifyのストア管理画面の「設定 > 一般設定 > 基準とフォーマット」で設定したフォーマットで注文の名前を返します。

Input
{{ order.name }}
Output
#1025

order.note

order.noteは、顧客の注文に関連するメモを返します。
メール通知やオーダープリンターのテンプレートに注文メモを表示するには、{{ note }}を使用します。customers/account.liquidのようなテンプレートファイルに注文メモを表示するには、{{ order.note }}を使用します。

Input
Special instructions: {{ order.note }}
Output
Special instructions: 午後5時以降の配達をお願いします。

order.order_number

order.order_numberは、注文名の整数表現を返します。

Input
{{ order.order_number }}
Output
1025

これは、注文番号からプリフィックスとサフィックスを取り除いたものです。

order.order_status_url

order.order_status_urlは、注文の注文状況ページの一意の URL を返します。

order.phone

order.phoneは、注文に関連する電話番号を返します。

order.shipping_address

order.shipping_addressは、ご注文のお届け先を返します。

order.shipping_methods

order.shipping_methodsは、注文の shipping_method 変数の配列を返します。

order.shipping_price

order.shipping_priceは、注文した商品の送料を返します。

order.subtotal_line_items

order.subtotal_line_itemsは、注文の小計価格の計算に使用する行項目の配列を返します。チップのライン項目は除外します。

order.subtotal_price

order.subtotal_priceは、ラインアイテム割引とカート割引の両方を適用した後の注文の全アイテムの小計価格を返します。
小計には税金(価格に税金が含まれていない場合)、送料、チップは含まれていません。

order.tags

order.tagsは、注文のすべてのタグの配列を返します。タグはアルファベット順に返されます。

Input
{% for tag in order.tags %}
    {{ tag }}
{% endfor %}
Output
leather
sale
special

order.tax_lines

order.tax_linesは、注文に対するtax_line変数の配列を返します。
tax_lineについての詳しい説明はこちら

Input
{% for tax_line in order.tax_lines %}
  Tax ({{ tax_line.title }} {{ tax_line.rate | times: 100 }}%): {{ tax_line.price | money }}
{% endfor %}
Output
Tax (GST 10.0%): ¥2,000

order.tax_price

order.tax_priceは、注文の税額を返します。

order.total_discounts

order.total_discountsは、注文に適用されたすべての割引の合計値を返します。

order.total_net_amount

order.total_net_amountは、注文の純額を返します。

order.total_net_amountは、返金が適用された後に計算されます。この値はorder.total_priceからorder.total_refunded_amountを引いたものと同じです。

order.total_price

order.total_priceは、注文の合計価格を返します。

order.total_priceの金額は、返金が適用される前に計算されます。
返金の値を取得するには、order.total_refunded_amountプロパティを使用します。

order.total_refunded_amount

order.total_refunded_amountは、ご注文の返金額の合計を返します。

order.transactions

order.transactionsは、注文からのトランザクションの配列を返します。

pageオブジェクト

次にpageオブジェクトの属性をみていきます。

page.author

page.authorは、ページの著者を返します。

page.content

page.contentは、ページのコンテンツを返します。

page.handle

page.handleは、ページのハンドルを返します。

page.id

page.idは、ページのidを返します。

ページのidとは、ストア管理画面のページのエディタを開いている時に URL に表示される一意の数字になります。

ページのid

page.published_at

page.published_atは、ページが作成された時刻のタイムスタンプを返します。日付フィルタを使用してタイムスタンプをフォーマットします。

page.template_suffix

page.template_suffixは、page.プレフィックスと.liquid拡張子を除いて、ページに割り当てられたカスタムページテンプレートの名前を返します。
カスタムテンプレートがページに割り当てられていない場合はnilを返します。

Input
<!-- on page.contact.liquid -->
{{ page.template_suffix }}
Output
contact

page.title

page.titleは、ページのタイトルを返します。

page.title

page.urlは、ページの URL を返します。

Input
{{ page.url }}
Output
/pages/about-us

page_description オブジェクト

page_descriptionは、管理画面のそれぞれのセクションで設定されているページの説明を返します。

page_descriptionは、検索エンジンのリスティングやソーシャルメディアのフィードで共有された投稿の中でページの簡単な説明を提供するために使用することができます。

Input
<meta name="description" content="{{ page_description}}" />
Output
<meta name="description" content="ここにページやブログのエディタで設定したメタディスクリプションが挿入されます。" />

商品、ページ、コレクション、ブログ、ブログ記事のリソースの場合、page_descriptionは検索結果のプレビューから取得されます。
ホームページの場合、page_descriptionは管理画面のオンラインストアの設定から取得します。タイトルとメタディスクリプションの編集についてはこちらをご覧ください。

終わりに

今回の記事はここまでになります。
お疲れ様でした。

Shopify アプリのご紹介

Shopify アプリである、「商品ページ発売予告アプリ | リテリア Coming Soon」は、商品ページを買えない状態のまま、発売日時の予告をすることができるアプリです。Shopify で Coming Soon 機能を実現することができます。

12
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
7