LoginSignup
16
14

More than 1 year has passed since last update.

【Shopify】liquidのオブジェクトについてまとめてみた (current_tags, customer, customer_address)

Last updated at Posted at 2021-02-11

はじめに

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

current_tagscustomercustomer_addressのオブジェクトをまとめていきます。

こちらを参考にしました。

current_tagsオブジェクト

currentオブジェクトの概要についてドキュメントからの引用です。

current_tagsは、コレクションやブログをフィルタリングするために使われている全タグを含む配列です。

Shopifyでは、タグは商品とブログ記事に与えることができ、それぞれのページでフィルタリングが出来ます。

使用するページは、collection.liquidblog.liquidの2ページです。

collection.liquid 内で使用された時

collection.liquidの中では、currenct_tagsには、コレクションをフィルタリングするる全商品タグが含まれています。

以下の例では、コレクション内の全商品の全タグを表示するリストを作成しています。

コレクションが商品タグによってフィルタリングされている場合(currenct_tagsにタグが含まれている場合)、フィルタを解除出来るリンクが表示されます。

コレクションが商品タグでフィルタリングされていない場合(currenct_tagsにタグが含まれていない場合)、顧客がフィルタリング出来るようにするためのリンクが表示されます。

<ul>
{% for tag in collection.all_tags %}
    {% if current_tags contains tag %}
        <li class="active">{{ tag | link_to_remove_tag: tag }}</li>
    {% else %}
        <li>{{ tag | link_to_add_tag: tag }}</li>
    {% endif %}
{% endfor %}
</ul>

blog.liquid 内で使用した時

blog.liquidの中では、current_tagsにブログのフィルタリングに使われている全記事タグが含まれています。

以下の例では、どの記事タグがブログのフィルタリングに使用されているかを示すパンくずが追加されています。

ブログをフィルタリングしている時、パンくずリストはタグ名を表示し、フィルタリングを解除するためのリンクを表示します。

{% if current_tags %}
    <h1>{{ blog.title | link_to: blog.url }} &raquo; {{ current_tags.first }}</h1>
{% else %}
    <h1>{{ blog.title }}</h1>
{% endif %}

customerオブジェクト

customerオブジェクトの概要についてドキュメントからの引用です。

customerオブジェクトには、顧客アカウントを持つ顧客に関する情報が含まれています。

customerオブジェクトはグローバルオブジェクトなので、全てのレイアウトファイル、テンプレートファイル、スニペットファイルでアクセスできます。

さらに、メールテンプレートやチェックアウトの注文ページ、Order Printerなどのアプリからもアクセス剃ることが出来ます。

しかし、customerオブジェクトは、顧客がログインしてる場合にのみ定義されます。

{% if customer %}
  Customer is logged in. You can access the customer
  attributes such as {{ customer.first_name }}.
{% endif %}

それでは、customerオブジェクトの属性を見ていきましょう

customer.accepts_marketing

顧客が購入をした場合にtrueを返し、購入しなかった場合にfalseを返します。

customer.addresses

顧客に関連付けられたアドレスの配列を返します。

利用可能な属性の一覧は、後のcustomer_addressオブジェクトを参照ください。

{% for address in customer.addresses %}
  {{ address.street }}
{% endfor %}

126 York St, Suite 200 (Shopify Office)
123 Fake St
53 Featherston Lane

customer.addresses_count

顧客に関連付けられたアドレスの数を返します。

customer.default_address

顧客が複数のアカウントを持っている時に、デフォルトに設定されているcustomer_address(アドレス)を返します。

customer.email

顧客のメールアドレスを返します。

customer.first_name

顧客のファーストネーム(名前)を返します。

customer.has_account

チェックアウト時に入力したメールアドレスが、顧客のアカウントに関連付けられている場合はtrueを返し、そうでない場合はfalseを返します。

顧客は、ストアにアカウントを持っていなくてもチェックアウトを完了させることが出来ます。

ストアのアカウントを持っていない場合は、メールテンプレートやチェックアウト時に、customer.has_accountfalseになります。

顧客がストアにアカウントを持っていて、チェックアウト時にそのアカウントに関連付けられたメールを入力した場合、customer.has_accounttrueとなります。

顧客がアカウントにログインしているかどうかに関わらず、メールはアカウントに関連付けられた内容を送信します。

customer.id

顧客のIDを返します。

customer.last_name

顧客のラストネーム(名字)を返します。

customer.last_order

テスト注文以外で、顧客が最後に注文した商品を返します。

Your last order was placed on: {{ customer.last_order.created_at | date: "%B %d, %Y %I:%M%p" }}

Your last order was placed on: April 25, 2014 01:49PM

customer.name

顧客のフルネームを返します。

customer.orders

顧客が発注したすべての注文の配列を返します。

{% for order in customer.orders %}
{{ order.id }}
{% endfor %}

#1088
#1089
#1090

customer.orders_count

顧客が発注した注文の総数を返します。

customer.phone

顧客の電話番号を返します。

customer.tags

顧客に関連付けられたタグをリストを返します。

{% for tag in customer.tags %}
{{ tag }}
{% endfor %}

wholesale regular-customer VIP

customer.tax_exempt

顧客が非課税であるかどうかを返します。

customer.total_spent

顧客が今まで購入した総金額を返します。

customer_addressオブジェクト

customer_addressオブジェクトの概要についてドキュメントからの引用です。

customer_addressは、顧客管理の住所欄の値を返します。

英語の顧客の住所欄

ScreenClip.png

日本語の顧客の住所欄
ScreenClip.png

それでは、customer_addressの属性について見ていきましょう。

customer_address.address1

住所欄のの住所(Address)の値を返します。

customer_address.address2

住所欄の建物名、部屋番号など(Apatment, suite, etc)の値を返します。

customer_address.city

住所欄の市区町村(City)の値を返します。

customer_address.company

住所欄の会社(Company)の値を返します。

customer_address.country

住所欄の国/地域(Coutry/Region)の値を返します。

{{ customer_address.country }}

Japan

customer_address.country_code

住所欄の国/地域(Coutry/Region)の値を、ISO 3166-2 標準フォーマットで返します。

国が日本だとJPになります。

{{ customer_address.country_code }}

CA

customer_address.first_name

住所欄の名(First name)の値を返します。

customer_address.id

顧客の住所に基づいた、IDを返します。

customer_address.last_name

住所欄の姓(Last name)の値を返します。

customer_address.phone

住所欄の電話番号(Phone)の値を返します。

customer_address.province

住所欄の州(province)の値を返します。

{{ customer_address.province }}

Ontario

customer_address.province_code

住所欄の州(province)に基づいた、省略値を返します。

{{ customer_address.province_code }}

ON

customer_address.street

住所欄の住所(Address)欄と建物名、部屋番号など(Address2)の合計値を返します。

{{ shipping_address.street }}

150 Elgin St, Shopify Office

customer_address.zip

住所欄の郵便番号(Postal/Zip)の値を返します。

Postalコードは、国がカナダの時、Zipコードは、アメリカなどで表示されます。

ScreenClip.png

ScreenClip.png

終わりに

今回の記事はここまでになります。

お疲れさまでした。

Shopify アプリのご紹介

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

16
14
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
16
14