v1 提前订餐功能

您可以在履单中添加支持,以便用户安排自提和 提供送餐服务在 履单,创建用于指定用户营业时间的服务目录 Feed 以便提前下单,如产品目录 Feed 架构中所述 (AdvanceServiceDeliveryHoursSpecification)。

提前订单空档

Google 建议以 15 分钟为增量提前订购空档,最长可持续 7 天 根据餐馆或服务的履单时间(如 AdvanceServiceDeliveryHoursSpecification)。

要检索建议的提前订单空档,请使用以下值: 结账时 FoodCartExtension 对象的 fulfillmentPreference 字段:

  • PickupInfo.pickupTimeIso8601
  • DeliveryInfo.deliveryTimeIso8601

在结账时实施提前订单

下表列出了实现执行方式的 响应。

场景 Fulfillment 行为
可以满足所请求的空档的提前订单。 接受P0M(“尽快”)或 FUTURE_SLOT购物车。ProposedOrder 。如需查看接受空档的结账响应示例,请参阅 此代码段
无法履行所请求的空档的提前订单。 您的执行方式应执行以下操作: <ph type="x-smartling-placeholder">
    </ph>
  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

CREATEDCONFIRMED OrderState 对象。添加 。

如果您的履单稍后向餐馆发送订单,请向 Google 发送一个 使用异步订单更新操作进行更新。

在履单的提交订单响应的 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 类型可用于指定 送货或自提时间,以便用户提前安排订单。

注意 :您必须指定两个单独的时间范围 对于服务执行方式:一个订购窗口,用于指定用户何时可以 以及用于指定履行订单的时间的 fulfillment window。通过 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"
    }
  }
}
...

以下示例 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"
      }
    }
  ]
}
...