v1 預訂功能功能

您可以在出貨要求中新增支援服務,方便使用者安排取貨時間。 外送餐點。在以下國家/地區導入這項支援服務前: 執行要求,請建立服務商品目錄動態饋給,為客戶指定營業時間 提前下單 (正如商品目錄動態饋給結構定義中所述) (AdvanceServiceDeliveryHoursSpecification)。

預先訂購版位

Google 建議提前訂購時段,以 15 分鐘為單位,最多 7 天 到達餐廳或服務的出貨時間 (定義請見 AdvanceServiceDeliveryHoursSpecification)。

如要擷取預先提議的訂單,請使用以下 FoodCartExtension 物件的 fulfillmentPreference 欄位:

  • PickupInfo.pickupTimeIso8601
  • DeliveryInfo.deliveryTimeIso8601

在結帳時導入預先訂單功能

下表列出了可能可以實作執行要求的方式。 回覆。

情境 履行行為
要求的時段可以完成提前訂單。 接受P0M (「越快越好」) 或 方法是建立 ProposedOrder,並使用FUTURE_SLOT 同一個版位。如需接受特定時段的結帳回應範例,請參閱 這個程式碼片段
無法為要求的時段完成提前訂單。 執行要求應執行下列操作:
  1. 拒絕要求的 P0MFUTURE_SLOT 然後說明此訂單無法履行的原因。 FoodErrorExtension 物件。
    • 如果因容量不足而無法履行訂單,請指定 錯誤類型 NO_CAPACITYFoodOrderError
    • 如果訂單因餐廳無法出貨 已關閉,請指定錯誤類型的 FoodOrderError CLOSED
    • 如果訂單因其他原因而無法出貨 指定錯誤類型的 FoodOrderError UNAVAILABLE_SLOT
  2. 請盡可能提供替代的 P0McorrectedProposedOrder 中的 FUTURE_SLOT 個值。 這些值應為接下來 7 個有效的執行要求版位 天 (自目前時間起算)。加入 P0M 版位 。

如需提供替代版位的結帳回應範例,請參閱: 這個程式碼片段

訂單履行的替代運算單元

結帳時,如果 Google 提出的預訂訂單不適用, 執行要求可以使用 CheckoutResponseMessage 建議替代方案 物件。

如要指定替代的預先訂單版位,請在回覆結帳要求時, FoodErrorExtension,並設定下列值:

  1. foodOrderErrors 參數中指定錯誤類型 (例如 UNAVAILABLE_SLOTNO_CAPACITYCLOSED)。
  2. correctedProposedOrder 參數中,提供替代的 P0M 或 透過 availableFulfillmentOptions 取得 FUTURE_SLOT 個值。

替代時段應為下單後的未來 7 天 而且包含使用者要求購物車的所有版位 才能順利運作

比如說,午餐特惠只在週一到週五提供 早上 11 點到下午 1 點使用者嘗試將午餐特惠加入購物車 所選時段無法使用在這種情況下,您的執行要求 在購物車中保留午餐特惠資訊,只傳回上午 11 點到下午 1 點的時段 未來 7 天

您應該省略 correctedProposedOrder.Cart.fulfillmentPreference 物件 。

如果沒有可預約的時段,或是餐廳/服務並未開放預約 支援提前訂單,則無需提供 correctedProposedOrder

請參閱下方範例,瞭解執行要求與 Google 之間的 JSON 訊息 結帳要求和回應流程期間, 開放預購的餐廳或服務。

範例:含送貨時段的 CheckoutRequest

下列程式碼片段為提前訂單的結帳要求範例 放送時段

{
  "inputs": [
    {
      "intent": "actions.foodordering.intent.CHECKOUT",
      "arguments": [
        {
          "extension": {
            "@type": "type.googleapis.com/google.actions.v2.orders.Cart",
            "merchant": {
              "id": "https://www.exampleprovider.com/merchant/id1",
              "name": "Cucina Venti"
            },
            "lineItems": [
              {
                "name": "Sizzling Prawns Dinner",
                "type": "REGULAR",
                "id": "sample_item_offer_id_1",
                "offerId": "https://www.exampleprovider.com/menu/item/offer/id1",
                "quantity": 1,
                "price": {
                  "type": "ESTIMATE",
                  "amount": {
                    "currencyCode": "USD",
                    "units": "16",
                    "nanos": 750000000
                  }
                },
              }
            ],
            "extension": {
              "@type": "type.googleapis.com/google.actions.v2.orders.FoodCartExtension",
              "fulfillmentPreference": {
                "fulfillmentInfo": {
                  "delivery": {
                    // Deliver at 6:30PM.
                    "deliveryTimeIso8601": "2017-12-14T18:30:00-07:00"
                  }
                }
              },
              "location": {
                ...
              }
            }
          }
        }
      ]
    }
  ]
}

範例: CheckoutResponse 接受指定時段

下列程式碼片段為結帳回應範例,其中已出貨至出貨部分 接受建議的提前訂單時段。

{
  "expectUserResponse": false,
  "finalResponse": {
    "richResponse": {
      "items": [
        {
          "structuredResponse": {
            "checkoutResponse": {
              "proposedOrder": {
                "id": "sample_proposed_order_id_1",
                "cart": {
                  "merchant": {
                    "id": "https://www.exampleprovider.com/merchant/id1",
                    "name": "Falafel Bite"
                  },
                  "lineItems": [
                    {
                      "name": "Sizzling Prawns Dinner",
                      "type": "REGULAR",
                      "id": "sample_item_offer_id_1",
                      "offerId": "https://www.exampleprovider.com/menu/item/offer/id1",
                      "quantity": 1,
                      "price": {
                        "type": "ESTIMATE",
                        "amount": {
                          "currencyCode": "USD",
                          "units": "16",
                          "nanos": 750000000
                        }
                      },
                    }
                  ],
                  "extension": {
                    "@type": "type.googleapis.com/google.actions.v2.orders.FoodCartExtension",
                    "fulfillmentPreference": {
                      "fulfillmentInfo": {
                        "delivery": {
                          // Same as the time in the request.
                          "deliveryTimeIso8601": "2017-12-14T18:30:00-07:00"
                        }
                      }
                    },
                    "location": {
                      ...
                     }
                   }
                },
                "totalPrice": {
                  "type": "ESTIMATE",
                  "amount": {
                    // Represents $16.75
                    "currencyCode": "USD",
                    "units": "16",
                    "nanos": 750000000
                  }
                },
                "extension": {
                  "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderExtension",
                  // Send whole proposed order back.
                  "availableFulfillmentOptions": [
                    "fulfillmentInfo": {
                      "delivery": {
                        // Same as the time in the request.
                        "deliveryTimeIso8601": "2017-12-14T18:30:00-07:00"
                      }
                    }
                  ]
                }
              },
              "paymentOptions": {
                ...
              }
            }
          }
        }
      ]
    }
  }
}

範例:含替代時段的 CheckoutResponse

下列程式碼片段為結帳回應範例,其中已出貨至出貨部分 提出替代的提前訂單版位。請注意, 以下位置應省略 correctedProposedOrder.Cart.fulfillmentPreference 物件: 您的回應。

{
  "expectUserResponse": false,
  "finalResponse": {
    "richResponse": {
      "items": [
        {
          "structuredResponse": {
            "error": {
              "@type": "type.googleapis.com/google.actions.v2.orders.FoodErrorExtension",
              "foodOrderErrors": [
                {
                  "error": "UNAVAILABLE_SLOT", // Cart level error
                  "description": "The restaurant is closed."
                }
              ],
              "correctedProposedOrder": {
                // Send whole original cart back,
                // without the fulfillmentPreference.
                "cart": {
                  ...
                },
                "otherItems": {
                  ...
                },
                "totalPrice": {
                  ...
                },
                "extension": {
                  "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderExtension",
                  "availableFulfillmentOptions": [
                    "fulfillmentInfo": {
                      "delivery": {
                        "deliveryTimeIso8601": "2017-12-14T19:00:00-07:00"
                      }
                    },
                    "fulfillmentInfo": {
                      "delivery": {
                        "deliveryTimeIso8601": "2017-12-14T19:30:00-07:00"
                      }
                    },
                    "fulfillmentInfo": {
                      "delivery": {
                        "deliveryTimeIso8601": "2017-12-14T20:00:00-07:00"
                      }
                    }
                  ]
                }
              },
              "paymentOptions": {
                ...
              }
            }
          }
        }
      ]
    }
  }
}

在提交訂單時導入預先訂單

提交訂單時,如果預購訂單發生問題,您的 SubmitOrderResponseMessage 應包含原因 (例如 UNAVAILABLE_SLOTUNKNOWN)。RejectionInfo

將訂單狀態從 CREATED 更新為 CONFIRMED OrderState 物件。加入 在確認電子郵件中選取時段。

如果出貨資訊稍後會送給餐廳,請將 請使用非同步訂單更新動作進行更新。

請在執行要求提交訂單回應的 OrderUpdate 物件中 後續的非同步訂單更新,加入 estimatedFulfillmentTimeIso8601 的值,設定如下:

  • 如果訂單狀態是 CREATEDCONFIRMED,請將值設為 使用者為提前訂單安排的到貨或取貨時間。
  • 餐廳的預估送達時間更準確 或服務,請將值設為預估送達或取貨時間。

範例:SubmitOrderRequest 包含放送時段

下列程式碼片段為提交訂單要求的例子,指出 使用者選取的預購訂單。

{
  "inputs": [
    {
      "intent": "actions.intent.TRANSACTION_DECISION",
      "arguments": [
        {
          "transactionDecisionValue": {
            "order": {
              "finalOrder": {
                "cart": {
                  "notes": "Guest prefers their food to be hot when it is delivered.",
                  "merchant": {
                    "id": "https://www.exampleprovider.com/merchant/id1",
                    "name": "Cucina Venti"
                  },
                  "lineItems": [
                    {
                      "name": "Sizzling Prawns Dinner",
                      "type": "REGULAR",
                      "id": "sample_item_offer_id_1",
                      "offerId": "https://www.exampleprovider.com/menu/item/offer/id1",
                      "quantity": 1,
                      "price": {
                        "type": "ESTIMATE",
                        "amount": {
                          "currencyCode": "USD",
                          "units": "16",
                          "nanos": 750000000
                        }
                      }
                    }
                  ],
                  "extension": {
                    "@type": "type.googleapis.com/google.actions.v2.orders.FoodCartExtension",
                    "fulfillmentPreference": {
                      "fulfillmentInfo": {
                        "delivery": {
                          "deliveryTimeIso8601": "2017-12-14T18:30:00-07:00"
                        }
                      }
                    }
                    "contact": {
                      ...
                    }
                  }
                },
                "totalPrice": {
                  "type": "ESTIMATE",
                  "amount": {
                    "currencyCode": "USD",
                    "units": "16",
                    "nanos": 750000000
                  }
                },
                "id": "sample_final_order_id",
                "extension": {
                  // Send whole proposed order back.
                  "availableFulfillmentOptions": [
                    "fulfillmentInfo": {
                      "delivery": {
                        "deliveryTimeIso8601": "2017-12-14T18:30:00-07:00"
                      }
                   ]
                }
              },
              "googleOrderId": "sample_google_order_id",
              "orderDate": "2017-07-17T12:00:00Z",
              "paymentInfo": {
                ...
              }
            }
          }
        }
      ]
    }
  ]
}

範例:SubmitOrderResponse 接受訂單

以下程式碼片段是提交訂單回應的範例,其中 執行要求,確認已接受使用者的提前訂單。

{
  "expectUserResponse": false,
  "finalResponse": {
    "richResponse": {
      "items": [
        {
          "structuredResponse": {
            "orderUpdate": {
              "actionOrderId": "sample_action_order_id",
              "orderState": {
                "state": "CREATED",
                "label": "Order placed"
              },
              "receipt": {
                "userVisibleOrderId": "userVisibleId1234"
              },
              "updateTime": "2017-07-17T12:00:00Z",
              "orderManagementActions": [
                ...
              ],
              "infoExtension": {
                 "@type": "type.googleapis.com/google.actions.v2.orders.FoodOrderUpdateExtension",
                 // Same as the user selected time.
                 "estimatedFulfillmentTimeIso8601": "2017-12-14T18:30:00-07:00"
              }
            }
          }
        }
      ]
    }
  }
}

範例:SubmitOrderResponse 因無法預訂時段而拒絕訂單

以下程式碼片段是提交訂單回應的範例,其中 因沒有時段無法使用,執行要求拒絕使用者的提前訂單。

{
  "expectUserResponse": false,
  "finalResponse": {
    "richResponse": {
      "items": [
        {
          "structuredResponse": {
            "orderUpdate": {
              "actionOrderId": "sample_action_order_id",
              "orderState": {
                "state": "REJECTED",
                "label": "Unavailable slot"
              },
              "rejectionInfo": {
                // Note that this UNAVAILABLE_SLOT is different from the enum
                // with the same name proposed for FoodOrderError.
                "state": "UNAVAILABLE_SLOT",
                "label": "Unavailable slot"
              },
              "updateTime": "2017-07-17T12:00:00Z",
              "orderManagementActions": [
                ...
              ]
            }
          }
        }
      ]
    }
  }
}

進階訂單範例

AdvanceServiceDeliveryHoursSpecification 類型可以用來指定 外送或取貨時段,讓使用者能提前安排訂單。

注意: 您必須指定兩個不同的時間範圍 服務執行要求:訂購視窗,用來指定使用者何時可以 訂單和出貨期,用於指定訂單的履行時間。 OpeningHoursSpecification 物件會定義使用者 就能下單子項出貨時間 (ServiceDeliveryHoursSpecification) 或 AdvanceServiceDeliveryHoursSpecification) 定義 符合條件。

以下範例定義接受提前訂單的服務營業時間。 服務間隔為 15 分鐘

{
  "hoursAvailable": [
    {
      "@type": "OpeningHoursSpecification",
      "opens": "T00:00:00", // Ordering available 24 hours
      "closes": "T23:59:59",
      "deliveryHours": [
        {
          "@type": "ServiceDeliveryHoursSpecification",
          "opens": "T09:00:00", // ASAP orders b/w 9am and 8:59:59pm
          "closes": "T21:00:00",
          "deliveryLeadTime": {
            "value": "60",
            "unitCode": "MIN"
          }
        },
        {
          "@type": "AdvanceServiceDeliveryHoursSpecification",
          "opens": "T10:00:00",  // Delivery between 10AM and 7:59:59PM
          "closes": "T20:00:00",
          "serviceTimeInterval": "PT15M", // in slots spaced 15 minutes apart (ISO8601)
          "advanceBookingRequirement": {
            "minValue": 60,   // The slot should be at least 60 mins away
            "maxValue": 8640, // but not more than 6 days away
            "unitCode": "MIN"
          }
        }
      ]
    }
  ]
}

以下範例說明如何指定 聖誕節當天的當天訂單,但因已排定的進階訂單而關閉 當天。此範例支援下列情境:

  • 使用者可以在 12 月 25 日訂購當天到貨服務。
  • 使用者可以在 12 月 25 日提前下單,之後商品才會配送到貨 在 12 月 27 日
  • 使用者無法在 12 月 22 日提前下單,之後商品才會開始配送 12 月 25 日
{
  "specialOpeningHoursSpecification": {
    "@type": "AdvanceServiceDeliveryHoursSpecification",
    "validFrom": "2018-12-25T00:00:00-07:00",
    "validThrough": "2018-12-26T00:00:00-07:00",
    "opens": "T00:00:00", // No advance ordering
    "closes": "T00:00:00"
  }
}

以下範例說明如何指定 於聖誕節當天排定的當天訂單或預購訂單,但營業中 已排定推遲日期的進階訂單。這個範例支援以下項目 情境:

  • 使用者無法在 12 月 25 日訂購當天到貨服務。
  • 使用者可以在 12 月 25 日提前下單,之後商品才會配送到貨 在 12 月 27 日
  • 使用者無法在 12 月 22 日提前下單,之後商品才會開始配送 12 月 25 日
{
  "specialOpeningHoursSpecification": [
    {
      "@type": "ServiceDeliveryHoursSpecification",
      "validFrom": "2018-12-25T00:00:00-07:00",
      "validThrough": "2018-12-26T00:00:00-07:00",
      "opens": "T00:00:00", // No ASAP ordering on Christmas
      "closes": "T00:00:00"
    },
    {
      "@type": "AdvanceServiceDeliveryHoursSpecification",
      "validFrom": "2018-12-25T00:00:00-07:00",
      "validThrough": "2018-12-26T00:00:00-07:00",
      "opens": "T00:00:00", // Orders cannot be scheduled for Christmas
      "closes": "T00:00:00"
    }
  ]
}

下列範例「服務」接受全天候的訂單, 平日早上 10 點至下午 2:59:59:

...
{
  "@type": "OpeningHoursSpecification",
  "opens": "T00:00:00",
  "closes": "T23:59:59",
  "deliveryHours": {
    "@type": "AdvanceServiceDeliveryHoursSpecification",
    "opens": "T10:00:00", // Delivery starts at 10:00AM
    "closes": "T15:00:00", // Delivery ends at 3:00PM. Delivery from 10AM-2:59:59PM.
    "dayOfWeek": [
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday"
    ],
    "serviceTimeInterval": "PT15M", // in slots spaced 15 minutes apart
    "advanceBookingRequirement": {
      "minValue": 60,   // The slot should be at least 60 mins away
      "maxValue": 8640, // but not more than 6 days away
      "unitCode": "MIN"
    }
  }
}
...

以下範例「服務」接受每日上午 8 點到下午 4 點 59:59 的訂單,以及 消費者可以選擇在一小時內收到貨品,或者選擇 運算單元:

...
{
  "@type": "OpeningHoursSpecification",
  "opens": "T08:00:00",  // Ordering opens at 8:00AM
  "closes": "T17:00:00",  // Ordering closes at 5:00PM, last order at 4:59:59PM
  "deliveryHours": [
    {
      "@type": "ServiceDeliveryHoursSpecification",
      "opens": "T08:00:00",
      "closes": "T17:00:00",
      "deliveryLeadTime": {
        "@type": "QuantitativeValue",
        "value": "60", // If no exact deliveryLeadTime, put a maximum time
        "unitCode": "MIN"
      }
    },
    {
      "@type": "AdvanceServiceDeliveryHoursSpecification",
      "opens": "T08:00:00",
      "closes": "T17:00:00",
      "serviceTimeInterval": "PT15M", // in slots spaced 15 minutes apart
      "advanceBookingRequirement": {
        "minValue": 90,   // The slot should be at least 90 mins away
        "maxValue": 8640, // but not more than 6 days away
        "unitCode": "MIN"
      }
    }
  ]
}
...

以下範例顯示了商店營業時間為上午 8 點至下午 4 點 59 分 59 分 但週末的早上 8 點至晚上 6:59。恕不受理 24 小時全年無休的訂單。

...
{
  // On weekdays, ordering open from 8AM-4:59:59PM.
  "@type": "OpeningHoursSpecification",
  "opens": "T08:00:00",
  "closes": "T17:00:00",
  "dayOfWeek": [
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday"
  ],
  "deliveryHours": [
    {
      // Fulfillment between 8AM-4:59:59PM on weekdays.
      "@type": "AdvanceServiceDeliveryHoursSpecification",
      "opens": "T08:00:00",
      "closes": "T17:00:00",
      "dayOfWeek": [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday"
      ],
      "serviceTimeInterval": "PT15M",
      "advanceBookingRequirement": {
        "minValue": 60,
        "maxValue": 8640,
        "unitCode": "MIN"
      }
    },
    {
      // Fulfillment between 8AM-6:59:59PM on weekends (even for orders placed on a
      // weekday).
      "@type": "AdvanceServiceDeliveryHoursSpecification",
      "opens": "T08:00:00",
      "closes": "T19:00:00",
      "dayOfWeek": [
        "Saturday",
        "Sunday"
      ],
      "serviceTimeInterval": "PT15M",
      "advanceBookingRequirement": {
        "minValue": 60,
        "maxValue": 8640,
        "unitCode": "MIN"
      }
    }
  ]
},
{
  // On weekends, one can place orders upto 6:59:59PM.
  "@type": "OpeningHoursSpecification",
  "opens": "T08:00:00",
  "closes": "T19:00:00",
  "dayOfWeek": [
    "Saturday",
    "Sunday"
  ],
  "deliveryHours": [
    {
      // But fulfillment on weekdays is only till 4:59:59PM.
      "@type": "AdvanceServiceDeliveryHoursSpecification",
      "opens": "T08:00:00",
      "closes": "T17:00:00",
      "dayOfWeek": [
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday"
      ],
      "serviceTimeInterval": "PT15M",
      "advanceBookingRequirement": {
        "minValue": 60,
        "maxValue": 8640,
        "unitCode": "MIN"
      }
    },
    {
      // Fulfillment on weekends is till 6:59:59PM.
      "@type": "AdvanceServiceDeliveryHoursSpecification",
      "opens": "T08:00:00",
      "closes": "T19:00:00",
      "dayOfWeek": [
        "Saturday",
        "Sunday"
      ],
      "serviceTimeInterval": "PT15M",
      "advanceBookingRequirement": {
        "minValue": 60,
        "maxValue": 8640,
        "unitCode": "MIN"
      }
    }
  ]
}
...