您可以在执行方式中添加支持,以便用户提前安排自提和送餐。在执行方式中实现此支持之前,请先创建一个服务目录 Feed,以指定用户提前下单的时间,如商品目录 Feed 架构 (AdvanceServiceDeliveryHoursSpecification
) 中所述。
提前订购时段
Google 建议根据餐厅或服务的履单时间(如 AdvanceServiceDeliveryHoursSpecification
中所定义),以 15 分钟为增量提前最多 7 天提前订餐。
如需检索建议的提前下单空档,请在结账时使用 FoodCartExtension
对象的 fulfillmentPreference
字段中的值:
PickupInfo.pickupTimeIso8601
DeliveryInfo.deliveryTimeIso8601
在结账时采用提前下单
下表列出了用户尝试下单时,在结账时实现执行方式响应的可能方式。
场景 | 执行方式 |
---|---|
可以为所请求的空档履行提前订单。 | 通过使用相同的槽位创建 ProposedOrder ,接受 P0M (“尽快”)或 FUTURE_SLOT 购物车。如需查看接受空档的结账响应的示例,请参阅此代码段。 |
无法针对所请求的空档完成提前订单。 | 您的执行方式应执行以下操作:
如需查看有关建议替代空档的结账响应的示例,请参阅此代码段。 |
履单的其他空档
在结账时,如果 Google 建议的提前下单槽不合适,您的履单服务可以使用 CheckoutResponseMessage
对象建议替代品。
如需指定其他提前订购时段,请使用 FoodErrorExtension
响应结账请求,并设置以下值:
- 在
foodOrderErrors
参数中,指定错误类型(例如UNAVAILABLE_SLOT
、NO_CAPACITY
或CLOSED
)。 - 在
correctedProposedOrder
参数中,通过availableFulfillmentOptions
提供备用P0M
或FUTURE_SLOT
值。
替代空档应是下单后 7 天内的空档,包括可履行用户请求的购物车的所有空档。
例如,假设特价午餐仅在周一至周五上午 11 点到下午 1 点提供。然后,用户尝试将特惠午餐添加到购物车,但所选时段不可用。在这种情况下,您的履单服务应在购物车中保留特价午餐,并且在接下来的 7 天内仅返回上午 11 点到下午 1 点的空档
您应该在响应中省略 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
应在 RejectionInfo
对象中包含原因(例如 UNAVAILABLE_SLOT
或 UNKNOWN
)。
当提供商接受订单后,在 OrderState
对象中将订单状态从 CREATED
更新为 CONFIRMED
。在发送给用户的确认电子邮件中包含所选时间段。
如果您的履单稍后会将订单发送给餐馆,请使用异步订单更新操作向 Google 发送更新。
在执行方式的提交订单响应或后续异步订单更新的 OrderUpdate
对象中,添加一个 estimatedFulfillmentTimeIso8601
,其值设置如下:
- 当订单状态为
CREATED
或CONFIRMED
时,请将值设置为用户为其提前订购的送货或自提时间。 - 如果餐厅或服务能够提供更准确的预计送货时间,请将该值设置为预计送货或自提时间。
示例:包含送货空位的 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" } ] }
以下示例 Service 接受全天候订单,并在工作日上午 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" } } } ...
以下示例 Service 每天从早上 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 点。我们不接受全天候订单。
... { // 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" } } ] } ...