ภูมิภาค

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

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

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

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 ด้วย URL ต่อไปนี้และเนื้อความของคำขอ

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

มีการจำกัดข้อมูลอย่างเข้มงวดที่ 2 MB สำหรับ 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”
}