【Shopify.dev和訳】Apps/Subscriptions/Shipping and delivery
この記事について
この記事は、Apps/Subscriptions/Shipping and deliveryの記事を和訳したものです。
記事内で使用する画像は、公式ドキュメント内の画像を引用して使用させていただいております。
Shopify アプリのご紹介
Shopify アプリである、「商品ページ発売予告アプリ | リテリア Coming Soon」は、商品ページを買えない状態のまま、発売日時の予告をすることができるアプリです。Shopify で Coming Soon 機能を実現することができます。
Shopify アプリである、「らくらく日本語フォント設定|リテリア Font Picker」は、ノーコードで日本語フォントを使用できるアプリです。日本語フォントを導入することでブランドを演出することができます。
サブスクリプションの配送料と配送方法を作成および管理する
各サブスクリプション契約 には、契約内の製品がどのように、どのような価格で配信されるかを説明する配信方法があります。製品がサブスクリプション契約に追加またはサブスクリプション契約から削除されたときに、配信方法を更新できます。
このチュートリアルでは、サブスクリプションの配送を管理するために行うことができる呼び出しについて説明します。また、顧客が 1 回限りの購入またはサブスクリプションを購入するときにチェックアウト中に表示される配送料に関する情報も提供します。
要件
- GraphQLAdmin および RESTAdmin API の開始ガイドを完了し、API で認証されました。
- テストショップで製品 と製品バリアントを作成しました。
- 販売プランの作成と管理、および サブスクリプション契約の作成と管理のチュートリアルを完了しました。
- 次の API オブジェクトに精通している:配信プロファイル、販売計画 、およびサブスクリプション契約。
スコープ
サブスクリプションの GraphQL ミューテーションを使用するには、アプリで Shopify ストアの次のアクセススコープをリクエストする必要があります。
-
read_own_subscription_contracts
:アプリが所有するコントラクトのサブスクリプションコントラクトミューテーションを読み取れるようにします。 -
write_own_subscription_contracts
:アプリが所有するコントラクトのサブスクリプションコントラクトミューテーションを記述できるようにします。 -
read_shipping
:アプリが配送料を読み取れるようにします。 -
write_shipping
:アプリが配送料を書き込むことができるようにします。
チェックアウト時に表示される配送料
顧客は、両方がマーチャントによって提供されている場合、1 回限りの購入とサブスクリプションを購入できます。
1 回限りの購入とサブスクリプションが同じ配信プロファイルにあり、同じ場所から来ている場合、1 回限りの購入の送料はサブスクリプションの購入で計算されます。以降のサブスクリプションの配送料は、個別に計算されます。 1 回限りの購入とは別にサブスクリプションの送料を計算する場合は、サブスクリプション固有の配信プロファイルを構成できます。 DeliveryProfile APIを使用して、販売プラングループ(製品に関連付けられている)を配信プロファイルに関連付けることにより、サブスクリプション固有のプロファイルを作成できます。
複数のサブスクリプションがカートにある場合、それらが同じ販売プランの請求および配信ポリシーを共有している場合、配送料は統合されます。
複数の料金が利用可能な場合、顧客はカート内の 1 回限りの購入商品の配送料金を選択できます。また、サブスクリプションの合計送料と 1 回限りの購入の合計送料を表示することもできます。
制限事項
- デフォルトでは、製品は 1 回限りの購入として購入された場合でも、サブスクリプションの一部として購入された場合でも、同じ配送料になります。
- 集荷と現地配送の方法は、サブスクリプションではサポートされていません。カートにサブスクリプションが含まれている場合、配送方法は 1 回限りの購入もサポートしていません。
- サブスクリプションの一部として製品を購入した場合、最も安い配送料のみが利用可能です。お客様は、複数の配送料から選択することはできません。
- 販売プラングループに固有の配送料は、Shopify 管理者の配送料と配達料の設定 には表示されません。アプリでプラングループを販売するための配送料を構成する必要があります。
- サブスクリプション契約ドラフトの新しい配送料を照会する場合、返される配送料は以下によって異なります。
・サブスクリプション契約に販売プラン ID がない場合は、バリアント ID に関連付けられた配信プロファイルの配送料が表示されます。
・サブスクリプション契約に販売プランまたはバリアント ID がない場合は、ショップの局留めプロファイルからの配送料が表示されます。 - レートが配信プロファイルから継承されている場合、レート名は「Shipping」です。 API を使用してサブスクリプション固有のレートを定義する場合、指定された名前が使用されます。
すべてのサブスクリプションに送料無料を指定する
販売プラングループ内のすべての製品に配送料を請求したくない場合は、販売プランの配送料を0
に設定できます。
次の例では、deliveryProfileCreate
ミューテーションを使用して、販売プラングループのすべての国の送料無料を含めています。salesPlanGroupsToAssociate
フィールドは、配信プロファイルに関連付けられる販売プラングループ ID を表します。
リクエスト
POST /admin/api/2021-01/graphql.json
mutation {
deliveryProfileCreate(
profile: {
sellingPlanGroupsToAssociate: ["gid://shopify/SellingPlanGroup/2"]
name: "Subscriptions Free Shipping"
locationGroupsToCreate: {
locations: "gid://shopify/Location/1"
zonesToCreate: {
name: "All Countries"
countries: { restOfWorld: true }
methodDefinitionsToCreate: {
rateDefinition: { price: { amount: 0, currencyCode: CAD } }
name: "Free Shipping"
}
}
}
}
) {
profile {
id
profileLocationGroups {
locationGroupZones(first: 1) {
edges {
node {
zone {
id
name
countries {
code {
restOfWorld
}
}
}
methodDefinitions(first: 1) {
edges {
node {
id
name
rateProvider {
__typename
... on DeliveryRateDefinition {
price {
amount
currencyCode
}
}
}
}
}
}
}
}
}
}
}
}
}
出荷サブスクリプションを特定の国に制限する
Shopify 管理者で構成した配送ゾーンに関係なく、配送サブスクリプションを特定の国に制限できます。次の例では、販売プラングループに北米の配送ゾーンへの送料無料が含まれています。
Request
POST /admin/api/2021-01/graphql.json
mutation {
deliveryProfileCreate(
profile: {
sellingPlanGroupsToAssociate: ["gid://shopify/SellingPlanGroup/1"]
name: "Subscriptions To NA"
locationGroupsToCreate: {
locations: "gid://shopify/Location/1"
zonesToCreate: {
name: "North America Shipping"
countries: [
{ code: CA, includeAllProvinces: true }
{ code: US, includeAllProvinces: true }
{ code: MX, includeAllProvinces: true }
]
methodDefinitionsToCreate: {
name: "Free Shipping"
rateDefinition: { price: { amount: 0, currencyCode: CAD } }
}
}
}
}
) {
profile {
id
profileLocationGroups {
locationGroupZones(first: 1) {
edges {
node {
zone {
id
name
countries {
name
}
}
methodDefinitions(first: 1) {
edges {
node {
id
name
rateProvider {
__typename
... on DeliveryRateDefinition {
price {
amount
currencyCode
}
}
}
}
}
}
}
}
}
}
}
}
}
JSON response:
{
"data": {
"deliveryProfileCreate": {
"profile": {
"id": "gid://shopify/DeliveryProfile/3",
"profileLocationGroups": [
{
"locationGroupZones": {
"edges": [
{
"node": {
"zone": {
"id": "gid://shopify/DeliveryZone/3",
"name": "North America Shipping",
"countries": [
{
"name": "Canada"
},
{
"name": "United States"
},
{
"name": "Mexico"
}
]
},
"methodDefinitions": {
"edges": [
{
"node": {
"id": "gid://shopify/DeliveryMethodDefinition/3",
"name": "Free Shipping",
"rateProvider": {
"__typename": "DeliveryRateDefinition",
"price": {
"amount": "0.0",
"currencyCode": "CAD"
}
}
}
}
]
}
}
}
]
}
}
]
}
}
}
}
すべてのサブスクリプションについて、国ごとに均一な配送料を定義します
すべてのサブスクリプションについて、配送ゾーンごとに均一の配送料金を定義できます。次の例では、販売プラングループにカナダへの送料無料が含まれており、その他の地域では 15.00 ドルの均一配送料金が指定されています。
Request
POST /admin/api/2021-01/graphql.json
mutation {
deliveryProfileCreate(
profile: {
sellingPlanGroupsToAssociate: ["gid://shopify/SellingPlanGroup/1"]
name: "Subscriptions To Canada and International"
locationGroupsToCreate: {
locations: "gid://shopify/Location/1"
zonesToCreate: [
{
name: "Canada Shipping"
countries: [{ code: CA, includeAllProvinces: true }]
methodDefinitionsToCreate: {
name: "Free Shipping"
rateDefinition: { price: { amount: 0, currencyCode: CAD } }
}
}
{
name: "Rest of World"
countries: { restOfWorld: true }
methodDefinitionsToCreate: {
name: "International Shipping"
rateDefinition: { price: { amount: 15, currencyCode: CAD } }
}
}
]
}
}
) {
profile {
id
profileLocationGroups {
locationGroupZones(first: 2) {
edges {
node {
zone {
id
name
countries {
name
}
}
methodDefinitions(first: 1) {
edges {
node {
id
name
rateProvider {
__typename
... on DeliveryRateDefinition {
price {
amount
currencyCode
}
}
}
}
}
}
}
}
}
}
}
}
}
JSON response:
{
"data": {
"deliveryProfileCreate": {
"profile": {
"id": "gid://shopify/DeliveryProfile/4",
"profileLocationGroups": [
{
"locationGroupZones": {
"edges": [
{
"node": {
"zone": {
"id": "gid://shopify/DeliveryZone/4",
"name": "Canada Shipping",
"countries": [
{
"name": "Canada"
}
]
},
"methodDefinitions": {
"edges": [
{
"node": {
"id": "gid://shopify/DeliveryMethodDefinition/4",
"name": "Free Shipping",
"rateProvider": {
"__typename": "DeliveryRateDefinition",
"price": {
"amount": "0.0",
"currencyCode": "CAD"
}
}
}
}
]
}
}
},
{
"node": {
"zone": {
"id": "gid://shopify/DeliveryZone/5",
"name": "Rest of World",
"countries": [
{
"name": "Rest of World"
}
]
},
"methodDefinitions": {
"edges": [
{
"node": {
"id": "gid://shopify/DeliveryMethodDefinition/5",
"name": "International Shipping",
"rateProvider": {
"__typename": "DeliveryRateDefinition",
"price": {
"amount": "15.0",
"currencyCode": "CAD"
}
}
}
}
]
}
}
}
]
}
}
]
}
}
}
}
新しい配送ゾーンで配信プロファイルを更新します
deliveryProfileUpdate
ミューテーションを使用して、新しい配送ゾーンを追加できます。次の例では、「米国」の配送ゾーンが配送プロファイルに追加されています。
Request
POST /admin/api/2021-01/graphql.json
mutation {
deliveryProfileUpdate(
id: "gid://shopify/DeliveryProfile/4"
profile: {
locationGroupsToCreate: {
locations: "gid://shopify/Location/1"
zonesToCreate: [
{
name: "United States"
countries: { code: US, includeAllProvinces: true }
methodDefinitionsToCreate: {
rateDefinition: { price: { amount: 0, currencyCode: CAD } }
name: "Free Shipping"
}
}
]
}
}
) {
profile {
id
profileLocationGroups {
locationGroupZones(first: 5) {
edges {
node {
zone {
id
name
countries {
id
name
provinces {
id
name
code
}
}
}
}
}
}
}
}
}
}
JSON response
{
"data": {
"deliveryProfileUpdate": {
"profile": {
"id": "gid://shopify/DeliveryProfile/4",
"profileLocationGroups": [
{
"locationGroupZones": {
"edges": [
{
"node": {
"zone": {
"id": "gid://shopify/DeliveryZone/6",
"name": "United States",
"countries": [
{
"id": "gid://shopify/DeliveryCountry/3",
"name": "United States",
"provinces": [
{
"id": "gid://shopify/DeliveryProvince/14",
"name": "Alabama",
"code": "AL"
},
{ ... },
{
"id": "gid://shopify/DeliveryProvince/71",
"name": "Wyoming",
"code": "WY"
}
]
}
]
}
}
}
]
}
}
]
}
}
},
"extensions": {
"cost": {
"requestedQueryCost": 33,
"actualQueryCost": 17
}
}
}
サブスクリプション契約ドラフトの新しい配送料をリクエストする
いつでも、サブスクリプション契約ドラフトの新しい配送料を照会できます。 ShippingOptions
フィールドは、ショップの現在の配送料を使用して、サブスクリプションドラフトの配送料オプションを再計算して返します。
配送オプションの取得はバックエンドで実行するのに時間がかかるため、アプリを継続的にポーリングする必要があります。クエリは、成功、失敗、またはnullのいずれかのステータスを返します。後続のリクエストは、ジョブワーカーが成功または失敗するまで、null を返し続けます。
Request
POST /admin/api/2021-01/graphql.json
{
subscriptionDraft(id: "gid://shopify/SubscriptionDraft/1") {
shippingOptions(
deliveryAddress: {
address1: "150 Elgin St"
city: "Ottawa"
country: "Canada"
countryCode: CA
province: "Ontario"
zip: "K2P1L4"
firstName: "James"
lastName: "Bond"
}
) {
__typename
... on SubscriptionShippingOptionResultSuccess {
shippingOptions {
title
price {
amount
currencyCode
}
}
}
... on SubscriptionShippingOptionResultFailure {
message
}
}
}
}
JSON response
{
"data": {
"subscriptionDraft": {
"shippingOptions": {
"__typename": "SubscriptionShippingOptionResultSuccess",
"shippingOptions": [
{
"title": "International rates",
"price": {
"amount": "10.0",
"currencyCode": "CAD"
}
}
]
}
}
},
"extensions": {
"cost": {
"requestedQueryCost": 3,
"actualQueryCost": 3,
"throttleStatus": {
"maximumAvailable": 5000.0,
"currentlyAvailable": 4997,
"restoreRate": 250.0
}
}
}
}
新しい送料でサブスクリプション契約を更新します
顧客がサブスクリプションを更新するとき、出荷への変更はサブスクリプション契約で更新する必要があります。
subscriptionDraftUpdate
ミューテーションのdeliveryPrice
フィールドとdeliveryMethod
フィールドを更新してから、サブスクリプションドラフトをコミット して変更をアクティブ化できます。
Request
POST /admin/api/2021-01/graphql.json
mutation {
subscriptionDraftUpdate(
draftId: "gid://shopify/SubscriptionDraft/1"
input: {
deliveryPrice: 21.90
deliveryMethod: {
shipping: {
address: {
address1: "150 Elgin St"
city: "Ottawa"
country: "Canada"
province: "Ontario"
zip: "K2P1L4"
firstName: "James"
lastName: "Bond"
}
shippingOption: {
title: "Standard"
presentmentTitle: "Standard"
code: "Standard"
description: null
}
}
}
}
) {
draft {
deliveryPrice {
amount
currencyCode
}
deliveryMethod {
__typename
... on SubscriptionDeliveryMethodShipping {
address {
address1
city
provinceCode
countryCode
}
shippingOption {
title
presentmentTitle
code
description
}
}
}
}
userErrors {
field
message
}
}
}
JSON response
{
"data": {
"subscriptionDraftUpdate": {
"draft": {
"deliveryPrice": {
"amount": "21.9",
"currencyCode": "CAD"
},
"deliveryMethod": {
"__typename": "SubscriptionDeliveryMethodShipping",
"address": {
"address1": "150 Elgin St",
"city": "Ottawa",
"provinceCode": "ON",
"countryCode": "CA"
},
"shippingOption": {
"title": "Standard",
"presentmentTitle": "Standard",
"code": "Standard",
"description": null
}
}
},
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 13,
"actualQueryCost": 13
}
}
}
Webhooks
サブスクリプションの配送に関する情報を受け取るためにアプリで特に利用できる Webhook はありません。ただし、アプリがショップの配信プロファイルの変更に対応する必要がある場合は、次の Webhook を使用できます。
Webhook トピック | 説明 | ペイロード |
---|---|---|
profiles/create |
配信プロファイルが最初に作成されたときに発行されます。 | { id, } |
profiles/update |
配信プロファイルが更新されたときに発行されます。 | { id, } |
profiles/delete |
配信プロファイルが削除されたときに発行されます。 | { id, } |
次のステップ
- サブスクリプションの割引を作成および管理する::パーセンテージ、定額、送料無料の割引など、サブスクリプションにさまざまなタイプの割引を適用する方法を学びます。
- サブスクリプション契約の作成と管理:ステップバイステップのワークフローに従ってサブスクリプション契約を作成および管理し、サブスクリプションの請求と Webhook がどのように機能するかを理解します。
Shopify アプリのご紹介
Shopify アプリである、「商品ページ発売予告アプリ | リテリア Coming Soon」は、商品ページを買えない状態のまま、発売日時の予告をすることができるアプリです。Shopify で Coming Soon 機能を実現することができます。
Shopify アプリである、「らくらく日本語フォント設定|リテリア Font Picker」は、ノーコードで日本語フォントを使用できるアプリです。日本語フォントを導入することでブランドを演出することができます。
Discussion