Regions

借助 regions 服务,您可以创建和管理地理区域,并将其用作 regionalinventoryshippingsettings 服务的定位条件。您可以将区域定义为邮政编码的集合,也可以在某些国家/地区使用预定义的地理位置定位目标。本指南提供了有关如何定义每种类型的地区以及如何创建地区性价格替换的示例。如需详细了解 regions 服务(包括所有可用的方法和参数),请参阅参考文档。

地区资格条件

创建区域时,地区服务会确定您是否可以将该地区与其他 Content API 服务搭配使用。成功调用 regions.create 后返回的响应对象包含两个布尔值字段:regionalInventoryEligibleshippingEligible,分别用于指示您是否可以将相应区域与 regionalinventoryshippingsettings 服务搭配使用。

regionalInventoryEligible

若要符合与 regionalinventory 服务搭配使用的条件,某个地区必须满足以下条件:

  • 您在创建地区时指定的 regionId 必须仅包含数字,且必须包含至少 6 位数字。
  • 相应地区必须满足地理区域和在线人口的最低规模要求。

shippingEligible

若要符合与 shippingsettings 服务搭配使用的条件,某个地区必须满足以下条件:

  • 必须使用邮政编码定义地区。
  • 该地区必须是受 shippingsettings 服务支持的国家/地区的一部分。

示例

以下是一个完整的代码示例,可用于在 Java 中创建新地区:

// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package shopping.content.v2_1.samples.regions;

import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.services.content.model.Region;
import com.google.api.services.content.model.RegionPostalCodeArea;
import com.google.api.services.content.model.RegionPostalCodeAreaPostalCodeRange;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import shopping.content.v2_1.samples.ContentSample;

/**
 * Creates a region. The region created here can be used with the regional inventory service.
 * Regional availability and pricing lets you provide product availability and variable pricing
 * based on your business presence and the location of your customer base. Regional availability and
 * pricing is available for products advertised through Shopping ads on Google Search, and listed in
 * free listings on the Shopping tab.
 */
public class RegionCreateSample extends ContentSample {
  public RegionCreateSample(String[] args) throws IOException {
    super(args);
  }

  @Override
  public void execute() throws IOException {
    checkNonMCA();

    // Creates a List of Postal Code Area Postal Code Ranges.
    // This allows you to flexibly define regions as combinations of postal code
    // ranges. Each postal code range in the list has its own start and end zip code.
    List<RegionPostalCodeAreaPostalCodeRange> postalCodeRanges =
        new ArrayList<RegionPostalCodeAreaPostalCodeRange>();

    // Creates a new postal code range from two postal code values.
    // This range is equivalent to all postal codes in the USA state of New York (00501 - 14925)
    RegionPostalCodeAreaPostalCodeRange postalCodeRange =
        new RegionPostalCodeAreaPostalCodeRange().setBegin("00501").setEnd("14925");

    // Adds the NY State postal code range into the list of postal code ranges that a postal
    // code area accepts.
    postalCodeRanges.add(postalCodeRange);

    // Creates Postal Code Area for the Region that will be inserted, using the NY State postal code
    // ranges, and the US CLDR territory/country code that the postal code ranges applies to.
    RegionPostalCodeArea postalCodeArea =
        new RegionPostalCodeArea().setPostalCodes(postalCodeRanges).setRegionCode("US");

    // Creates a region with example values for displayName and postalCodeArea
    Region region = new Region().setDisplayName("NYState").setPostalCodeArea(postalCodeArea);

    // Tries to create the region, and catches any exceptions
    try {
      System.out.println("Creating region");
      Region result =
          content
              .regions()
              .create(this.config.getMerchantId().longValue(), region)
              .setRegionId("12345678") // User-defined, numeric, minimum of 6 digits
              .execute();
      System.out.println("Listing succesfully created region");
      System.out.println(result);
    } catch (GoogleJsonResponseException e) {
      checkGoogleJsonResponseException(e);
    }
  }

  public static void main(String[] args) throws IOException {
    new RegionCreateSample(args).execute();
  }
}

使用邮政编码创建地区

您可以使用 regions.create 方法创建定义为邮政编码集合的区域。以下示例通过指定邮政编码范围,为美国亚利桑那州创建了一个新区域。

如需创建区域,请发出 POST 请求,并使用以下网址和请求正文:

https://shoppingcontent.googleapis.com/content/v2.1/merchantId/regions?regionId=456789
{
  postalCodeArea: {
    regionCode: "US",
    postalCodes: [
      {
        begin: "850*",
        end: "860*"
      }
    ]
   }
}

每个 Merchant Center 账号的 regionsshippingsettings 数据量硬性限制为 2 MB。配送和区域设置会从 MCA 内部复制到其所有子账号,因此对于较大的 MCA,您可能会很快达到存储空间上限。在这种情况下,一种解决方法是在商家 ID 级别管理 regionsshippingsettings。无法将区域配额增加到 2MB 上限以上。

使用地理位置定位条件创建地区

对于巴西和俄罗斯的地区,您还可以使用 regions.create 方法来创建定义为地理定位目标集合的地区,这些地理定位目标是预定义的地理区域。地理位置定位类型包括国家/地区、州/省/自治区/直辖市、城市、社区和机场。不过,regions 服务目前仅支持巴西的“州”类型和俄罗斯的“地区”类型。如需下载包含所有地理定位 ID(包括可与 regions 服务搭配使用的地理定位)的 CSV 文件,请参阅地理定位。以下示例通过提供三个巴西州的地理定位 ID 来创建新区域。

如需创建区域,请使用以下网址和请求正文发出 POST 请求:

https://shoppingcontent.googleapis.com/content/v2.1/merchantId/regions?regionId=123456
{
  geoTargetAreas: {
    geotargetCriteriaId: [20106, 20102, 20101] //Sao Paulo, Rio de Janeiro, Parana
  }
}

使用地区创建地区价格替换值

创建区域时,regions 服务会返回一个响应对象,其中包含 regionId 和两个资格条件状态字段。如果 regionalInventoryEligible 值为 true,您可以使用 regionaliventory 服务创建替换项,为相应地区设置不同的价格。以下示例使用上例中创建的基于邮政编码的地区(邮政编码为“456789”)创建地区价格替换值。regionId

如需创建替换项,请使用以下网址和请求正文发出 POST 请求:

https://shoppingcontent.googleapis.com/content/v2.1/merchantId/products/{productId}/regionalinventory
{
  “regionId”: "456789"
  “price”: {
    value: 10
    currency: “USD”
  },
  “availability”: “in stock”
}