ภูมิภาค

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*"
      }
    ]
   }
}

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

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

สำหรับภูมิภาคในบราซิลและรัสเซีย คุณยังใช้วิธี 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”
}