ภูมิภาค

บริการ regions ช่วยให้คุณสร้างและจัดการพื้นที่ทางภูมิศาสตร์ที่ คุณสามารถใช้เป็นเป้าหมายสำหรับทั้ง regionalinventory และ shippingsettings บริการต่างๆ คุณจะกำหนดภูมิภาคเป็นคอลเล็กชันของรหัสไปรษณีย์ หรือใน ในบางประเทศ โดยใช้ตัวเลือก geotargets คู่มือนี้ประกอบด้วย ตัวอย่างวิธีกำหนดภูมิภาคแต่ละประเภท และวิธีสร้างภูมิภาค การปรับราคา สำหรับข้อมูลเพิ่มเติมเกี่ยวกับบริการ regions รวมทั้งเมธอดและพารามิเตอร์ที่ใช้ได้ทั้งหมด โปรดดูเอกสารอ้างอิง

การมีสิทธิ์ในภูมิภาค

เมื่อคุณสร้างภูมิภาค บริการของภูมิภาคจะกำหนดว่าคุณสามารถใช้ ร่วมกับบริการ Content API อื่นๆ ออบเจ็กต์การตอบสนองแสดงผลสำหรับ การเรียกใช้ regions.create ที่สำเร็จจะมีช่องบูลีน 2 ช่อง regionalInventoryEligible และ shippingEligible ซึ่งระบุว่าคุณ ใช้ภูมิภาคกับบริการ regionalinventory และ shippingsettings ได้ ตามลำดับ

regionalInventoryEligible

ภูมิภาคต้องเป็นไปตามเงื่อนไขต่อไปนี้จึงจะมีสิทธิ์ใช้กับบริการ regionalinventory เกณฑ์ต่อไปนี้

  • regionId ที่คุณระบุเมื่อสร้างภูมิภาคต้องมีเฉพาะ และต้องมีอย่างน้อย 6 หลัก
  • ภูมิภาคต้องเป็นไปตามข้อกำหนดด้านขนาดขั้นต่ำสำหรับพื้นที่ทางภูมิศาสตร์และทางออนไลน์ ประชากร

shippingEligible

ภูมิภาคต้องเป็นไปตามเงื่อนไขต่อไปนี้จึงจะมีสิทธิ์ใช้กับบริการ shippingsettings เกณฑ์ต่อไปนี้

  • ภูมิภาคต้องกำหนดโดยใช้รหัสไปรษณีย์
  • ภูมิภาคต้องเป็นส่วนหนึ่งของประเทศที่ shippingsettings รองรับ service.

ตัวอย่าง

ต่อไปนี้คือตัวอย่างโค้ดแบบเต็มที่คุณสามารถใช้สร้างภูมิภาคใหม่ใน 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ด้วย URL ต่อไปนี้และคำขอ เนื้อความ:

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

มีการจำกัดข้อมูลอย่างเข้มงวดที่ 2MB สำหรับ regions และ shippingsettings ต่อบัญชี Merchant Center การตั้งค่าการจัดส่งและภูมิภาค มีการคัดลอกภายในจาก MCA ไปยังบัญชีย่อยทั้งหมดของบัญชีนั้น ดังนั้น MCA อาจทำให้พื้นที่เก็บข้อมูลเต็มอย่างรวดเร็ว ในกรณีนี้ วิธีแก้ไขคือ เพื่อจัดการ regions และ shippingsettings ที่ระดับรหัสผู้ขาย ไม่มี การเพิ่มโควต้าภูมิภาคของคุณเกินขีดจำกัด 2MB ไปแล้ว

สร้างภูมิภาคโดยใช้เป้าหมายตามภูมิศาสตร์

สำหรับภูมิภาคในบราซิลและรัสเซีย คุณใช้เมธอด regions.create ได้ด้วย เพื่อสร้างภูมิภาคซึ่งกำหนดเป็นชุดของเป้าหมายตามภูมิศาสตร์ ซึ่งกำหนดไว้ล่วงหน้า พื้นที่ทางภูมิศาสตร์ ตัวอย่างของประเภทเป้าหมายตามภูมิศาสตร์ ได้แก่ ประเทศ รัฐ เมือง ย่านใกล้เคียง และสนามบิน อย่างไรก็ตาม ขณะนี้บริการ regions เพียงอย่างเดียวเท่านั้น รองรับประเภท "รัฐ" สำหรับบราซิลและประเภท "ภูมิภาค" สำหรับรัสเซีย ถึง ดาวน์โหลดไฟล์ CSV ของรหัสเป้าหมายตามภูมิศาสตร์ทั้งหมด รวมถึงเป้าหมายตามภูมิศาสตร์ที่สามารถ ที่ใช้กับบริการ regions โปรดดู เป้าหมายตามภูมิศาสตร์ ตัวอย่างด้านล่างจะสร้าง ภูมิภาคใหม่โดยระบุรหัสเป้าหมายตามภูมิศาสตร์ของ 3 รัฐในบราซิล

หากต้องการสร้างภูมิภาค ให้ส่งคำขอ POST โดยใช้ URL และคำขอต่อไปนี้ เนื้อความ:

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

ใช้ภูมิภาคเพื่อสร้างการลบล้างราคาระดับภูมิภาค

เมื่อคุณสร้างภูมิภาค บริการ regions จะแสดงผลออบเจ็กต์การตอบกลับที่ มีช่องสถานะregionIdและช่องสถานะการมีสิทธิ์ 2 ช่อง หาก ค่า regionalInventoryEligible คือ true คุณสามารถใช้ regionaliventory เพื่อสร้างการลบล้างที่กำหนดราคาอื่นสำหรับภูมิภาคนั้น ตัวอย่างด้านล่างสร้างการลบล้างราคาระดับภูมิภาคโดยใช้รหัสไปรษณีย์ ภูมิภาคที่สร้างในตัวอย่างข้างต้น ซึ่งมี regionId เป็น "456789"

หากต้องการสร้างการลบล้าง ให้ส่งคำขอ POST โดยใช้ URL ต่อไปนี้และ เนื้อหาคำขอ:

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