ניהול הגדרות של ערוצים מרובים

‫Omnichannel Settings API הוא נקודת הכניסה להגדרת התוכניות של מודעות מלאי של חנויות מקומיות (LIA) וכרטיסים חינמיים למוצרים מקומיים (FLL).

אפשר להשתמש בו כדי

  • לנהל (ליצור ולעדכן) את ההגדרות של כל הערוצים
  • אחזור (get ו-list) של הגדרות בכל הערוצים
  • בקשה לאימות מלאי למוכרים שעומדים בדרישות

כאן יש סקירה כללית בנושא מודעות מלאי של חנויות מקומיות וכרטיסים חינמיים למוצרים מקומיים.

דרישות מוקדמות

אתם צריכים:

יצירת הגדרה לכל הערוצים

אפשר להשתמש ב-method‏ omnichannelSettings.create כדי ליצור הגדרה של כל הערוצים. השיטה create מקבלת משאב omnichannelSetting כקלט ומחזירה את הגדרת כל הערוצים שנוצרה, אם הפעולה בוצעה בהצלחה.

כשיוצרים את המדיניות, צריך למלא גם את השדה regionCode וגם את השדה LsfType:

  • ההגדרה OmnichannelSetting היא לכל מדינה בנפרד. ‫RegionCode מגדיר את המדינה המטורגטת. אחרי שיוצרים את המרחב, אי אפשר לשנות את ההגדרה הזו. הערך של RegionCode צריך להיות תואם לכלל מתן השמות שמוגדר בפרויקט Common Locale Data Repository (CLDR)‎.
  • הערך של LsfType מבוסס על דף המוצר שלך. מידע נוסף מופיע במאמר LsfType.

מידע נוסף זמין במאמר שינוי חוויית המשתמש בדף המוצר שאליו מובילות מודעות מלאי של חנויות מקומיות.

לא חייבים למלא את כל השדות בשלב היצירה, אפשר להגדיר אותם מאוחר יותר. כדי לעדכן omnichannelSetting קיים, עיינו במאמר עדכון הגדרה של כל הערוצים.

הנה דוגמה לבקשה אם בחרתם באפשרות MHLSF_BASIC ונרשמתם ל-inStock:

POST https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings

{
  "regionCode": "{REGION_CODE}",
  "lsfType: "MHLSF_BASIC",
  "inStock": {
      "uri": {URI}"
  }
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫{ACCOUNT_ID}: המזהה הייחודי של חשבון Merchant Center
  • ‫{REGION_CODE}: קוד אזור כפי שמוגדר על ידי CLDR
  • ‫{URI}: כתובת URI תקינה שמשמשת לביקורת הנתונה. יכול להיות שכתובת URI שלא עומדת בדרישות תמנע את האישור.

אחרי שהבקשה תפעל בהצלחה, תופיע התגובה הבאה:

{
  "name": "accounts/{ACCOUNT_ID}/omnichannelSettings/{omnichannel_setting}",
  "regionCode": "{REGION_CODE}",
  "lsfType: "MHLSF_BASIC",
  "inStock": {
      "uri": "{URI}",
      "state": "RUNNING"
  }
}

הרשמה לתכונות שונות של מודעות מלאי של חנויות מקומיות או של דף חנות ב-Google באמצעות שדות omnichannelSetting מפעילה בדיקות ידניות, שבדרך כלל נמשכות בין כמה שעות לכמה ימים. מומלץ לבדוק שוב את הנתונים שהזנתם כדי למנוע עיכובים מיותרים בגלל נתונים לא תקינים.

כדי לראות את ההגדרה החדשה של כל הערוצים או לבדוק את סטטוס הבדיקות, משתמשים ב-accounts.omnichannelSettings.get או ב-accounts.omnichannelSettings.list ומציינים את המדינה.

סוג דף החנות המקומית (LSF)

בהתאם לדף המוצר שבו אתם מתכננים להשתמש, בוחרים LsfType:

סוג דף המוצר LsfType הערך של הטיפוס בן המנייה (enum)
דפי מוצר עם נתוני זמינות במלאי דף של חנות מקומית באתר של המוכר (בסיסי) MHLSF_BASIC
דפי מוצר עם נתוני מחיר וזמינות במלאי בחנות ספציפית דף של חנות מקומית באתר של המוכר (מלא) MHLSF_FULL
דפי מוצר ללא נתוני זמינות בחנות דף של חנות מקומית שמתארח ב-Google‏ (GHLSF) GHLSF

אם אתם בוחרים בסוגים של דף חנות מקומית באתר של המוכר, אתם צריכים למלא גם את שדה ה-URI של לפחות אחד מהמאפיינים הבאים: inStock או pickup.

InStock

אתם יכולים להשתמש ב-InStock כדי לספק מידע נוסף על דף המוצר.

אם אתם בוחרים בדפי נחיתה של חנויות בטיפול המוכר ומציינים את השדה URI ב-InStock, אתם מראים שאתם מתכוונים להציג מוצרים שזמינים במלאי. אנחנו נתחיל בדיקה על סמך ה-URI שסיפקת.

אם בוחרים בסוג GHLSF, צריך לספק שדה InStock ריק בבקשה. בניגוד לסוגים של דפי מוצר בטיפול המוכר, כדי להשלים את תהליך ההצטרפות, אתם צריכים להשלים את תהליך אימות המלאי.

דוגמת הקוד הזו יוצרת omnichannelSetting עם GHLSF:

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.AccountName;
import com.google.shopping.merchant.accounts.v1.CreateOmnichannelSettingRequest;
import com.google.shopping.merchant.accounts.v1.InStock;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting.LsfType;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to create an omnichannel setting for a given Merchant Center account
 * in a given country
 */
public class CreateOmnichannelSettingSample {

  public static void createOmnichannelSetting(Config config, String regionCode) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      String accountId = config.getAccountId().toString();
      String parent = AccountName.newBuilder().setAccount(accountId).build().toString();

      // Creates an omnichannel setting with GHLSF type in the given country.
      CreateOmnichannelSettingRequest request =
          CreateOmnichannelSettingRequest.newBuilder()
              .setParent(parent)
              .setOmnichannelSetting(
                  OmnichannelSetting.newBuilder()
                      .setRegionCode(regionCode)
                      .setLsfType(LsfType.GHLSF)
                      .setInStock(InStock.getDefaultInstance())
                      .build())
              .build();

      System.out.println("Sending create omnichannel setting request:");
      OmnichannelSetting response =
          omnichannelSettingsServiceClient.createOmnichannelSetting(request);

      System.out.println("Inserted Omnichannel Setting below:");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    // The country which you're targeting at.
    String regionCode = "{REGION_CODE}";

    createOmnichannelSetting(config, regionCode);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\OmnichannelSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\CreateOmnichannelSettingRequest;
use Google\Shopping\Merchant\Accounts\V1\InStock;
use Google\Shopping\Merchant\Accounts\V1\OmnichannelSetting;
use Google\Shopping\Merchant\Accounts\V1\OmnichannelSetting\LsfType;

/**
 * This class demonstrates how to create an omnichannel setting for a given
 * Merchant Center account in a given country.
 */
class CreateOmnichannelSetting
{
    /**
     * Helper to create the parent string.
     *
     * @param string $accountId The merchant account ID.
     * @return string The parent string in the format `accounts/{account}`.
     */
    private static function getParent(string $accountId): string
    {
        return sprintf('accounts/%s', $accountId);
    }

    /**
     * Creates an omnichannel setting for a given Merchant Center account.
     *
     * @param array $config The configuration file for authentication.
     * @param string $regionCode The country for the omnichannel setting.
     */
    public static function createOmnichannelSettingSample(
        array $config,
        string $regionCode
    ): void {
        // Obtains OAuth credentials from the configuration file.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates a client.
        $omnichannelSettingsServiceClient = new OmnichannelSettingsServiceClient([
            'credentials' => $credentials
        ]);

        // Constructs the parent resource name.
        $parent = self::getParent($config['accountId']);

        // Creates the omnichannel setting with GHLSF type in the given country.
        $omnichannelSetting = new OmnichannelSetting([
            'region_code' => $regionCode,
            'lsf_type' => LsfType::GHLSF,
            'in_stock' => new InStock()
        ]);

        // Creates the request.
        $request = new CreateOmnichannelSettingRequest([
            'parent' => $parent,
            'omnichannel_setting' => $omnichannelSetting
        ]);

        // Calls the API and prints the response.
        try {
            printf("Sending create omnichannel setting request:%s", PHP_EOL);
            $response = $omnichannelSettingsServiceClient->createOmnichannelSetting($request);
            printf("Inserted Omnichannel Setting below:%s", PHP_EOL);
            print $response->serializeToJsonString(true) . PHP_EOL;
        } catch (ApiException $e) {
            printf("An error has occured: %s", $e->getMessage());
        }
    }

    /**
     * Executes the sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();
        // The country which you're targeting.
        $regionCode = '{REGION_CODE}';
        self::createOmnichannelSettingSample($config, $regionCode);
    }
}

// Runs the script.
$sample = new CreateOmnichannelSetting();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import CreateOmnichannelSettingRequest
from google.shopping.merchant_accounts_v1 import InStock
from google.shopping.merchant_accounts_v1 import OmnichannelSetting
from google.shopping.merchant_accounts_v1 import OmnichannelSettingsServiceClient


def create_omnichannel_setting(account_id: str, region_code: str) -> None:
  """Creates an omnichannel setting for a given Merchant Center account.

  Args:
      account_id: The ID of the Merchant Center account.
      region_code: The country for which you're creating the setting.
  """
  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = OmnichannelSettingsServiceClient(credentials=credentials)

  # The parent account under which to create the setting.
  parent = f"accounts/{account_id}"

  # Creates an omnichannel setting with GHLSF type in the given country.
  omnichannel_setting = OmnichannelSetting()
  omnichannel_setting.region_code = region_code
  omnichannel_setting.lsf_type = OmnichannelSetting.LsfType.GHLSF
  omnichannel_setting.in_stock = InStock()

  # Creates the request.
  request = CreateOmnichannelSettingRequest(
      parent=parent, omnichannel_setting=omnichannel_setting
  )

  # Makes the request and catches and prints any error messages.
  try:
    print("Sending create omnichannel setting request:")
    response = client.create_omnichannel_setting(request=request)
    print("Inserted Omnichannel Setting below:")
    print(response)
  except RuntimeError as e:
    print("An error has occured: ")
    print(e)


if __name__ == "__main__":
  # The ID of the account to get the omnichannel settings for.
  _ACCOUNT = configuration.Configuration().read_merchant_info()

  # The country which you're targeting.
  _REGION_CODE = "{REGION_CODE}"

  create_omnichannel_setting(_ACCOUNT, _REGION_CODE)

איסוף

חוץ מהזמינות בחנות, אתם יכולים לשפר את חוויית הרכישה של המוצרים בחנות באמצעות התכונה "איסוף", שזמינה רק בדפי מוצר בטיפול המוכר.

כשמוצר מסומן כזמין לאיסוף, זה אומר שהלקוח יכול לקנות אותו אונליין ולאסוף אותו מהחנות. הגדרת השדה Pickup מציינת שאתם מתכוונים להציג מוצרים עם תאריך זמינות לאיסוף. אנחנו נתחיל בדיקה על סמך ה-URI שסיפקת.

הנה דוגמה לבקשה שיוצרת הגדרת omnichannel עם Pickup:

POST https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings

{
  "regionCode": "{REGION_CODE}",
  "lsfType: "MHLSF_BASIC",
  "pickup": {
     "uri: "{URI}"
  }
}

בתצוגה, למכירה בהזמנה בלבד

התכונה בתצוגה, למכירה בהזמנה בלבד מאפשרת לפרסם מוצרים שמוצגים בחנות פיזית, אבל לא זמינים לרכישה מיידית. כמו רהיטים גדולים.

  • לקוחות שמחפשים מוצרים דומים ב-Google יראו את המודעות האלה בתוצאות החיפוש עם ההערה "בחנות".
  • לקוחות שמעיינים במוצרים מהחנות בדף תוצאות החיפוש ב-Google יראו את המוצרים האלה עם ההערה "זמין להזמנה".

כדי לראות את הפריט, הם יכולים ללחוץ על מודעת המלאי של החנות המקומית או על הכרטיס החינמי למוצר המקומי. כדי לקנות את הפריט, הם צריכים לבקר בחנות הפיזית שלכם, לראות את הפריט ולהזמין אותו. הם יכולים לבקש שתשלחו אותו אליהם או אל החנות שלכם לאיסוף.

מידע כללי (גרמניה, אוסטריה ושווייץ)

אם אתם מציגים מודעות באוסטריה ובגרמניה ובחרתם באפשרות GHLSF, אתם צריכים לשלוח דף מידע כללי.

אם אתם מציגים מודעות בשווייץ, אתם צריכים לשלוח דף "מידע כללי" בלי קשר ל-LsfType.

עד שכתובת ה-URL של דף ה"אודות" לא תאומת, מוכרים ב-GHLSF לא יוכלו לבקש מ-Google אימות מלאי ידני.

לכל המוכרים בשלוש המדינות האלה, השירות לא מפעיל את התכונות של FLL/LIA עד שדף ה"מידע כללי" מקבל אישור.

אימות מלאי

אימות מלאי נדרש רק למוכרים בGHLSF. הוא לא נתמך בסוגי הערכים MHLSF.

אתם צריכים לאמת את איש הקשר לפני או אחרי שאתם מוסיפים את נתוני המוצרים ונתוני המלאי (באמצעות accounts.products.localInventories.insert או ממשק המשתמש של Merchant Center). ציינו איש קשר לאימות המלאי (שם וכתובת אימייל) באמצעות השיטה create או update. איש הקשר יקבל אימייל מ-Google, ויוכל לאמת את הסטטוס שלו בלחיצה על כפתור בהודעה.

אחרי שתעשו את זה, תוכלו לבקש אימות מלאי. מידע נוסף על אימות מלאי

אפשר לשנות את איש הקשר במהלך תהליך האימות או אחרי האימות באמצעות omnichannelSetting.update.

אחרי שתסיימו את התהליך, Google תאמת את הדיוק של המידע שסיפקתם.

קבלת הגדרה של כל הערוצים

כדי לאחזר את ההגדרות של omnichannelSetting במדינה מסוימת, או כדי לבדוק את הסטטוס הנוכחי של הביקורות, משתמשים ב-method‏ omnichannelSettings.get.

הנה דוגמה לבקשה:

GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings/{OMNICHANNEL_SETTING}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫{ACCOUNT_ID}: המזהה הייחודי של חשבון Merchant Center
  • ‫{OMNICHANNEL_SETTING}: קוד האזור של מדינת היעד

הסטטוס ACTIVE מציין שהביקורת אושרה.

אם הסטטוס הוא FAILED, צריך לטפל בבעיות ולהפעיל בדיקה חדשה באמצעות קריאה ל-omnichannelSetting.update.

בשדה LFP לקריאה בלבד מוצג סטטוס שותף שלכם בתוכנית לספקי ניהול פידים עבור חנויות מקומיות. כדי לקשר לשותפות, צריך להשתמש ב-lfpProviders.linkLfpProvider.

מידע נוסף על בדיקת הסטטוסים והמשמעות שלהם זמין במאמר הצגת הסטטוס של הגדרת אומניצ'אנל.

הגדרות של רישום בכל הערוצים

כדי לאחזר את כל המידע על omnichannelSetting בחשבון, משתמשים ב-method‏ omnichannelSettings.list.

דוגמת קוד:

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.AccountName;
import com.google.shopping.merchant.accounts.v1.ListOmnichannelSettingsRequest;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient.ListOmnichannelSettingsPagedResponse;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to get the list of omnichannel settings for a given Merchant Center
 * account
 */
public class ListOmnichannelSettingsSample {

  public static void omnichannelSettings(Config config) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    String accountId = config.getAccountId().toString();
    String parent = AccountName.newBuilder().setAccount(accountId).build().toString();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      ListOmnichannelSettingsRequest request =
          ListOmnichannelSettingsRequest.newBuilder().setParent(parent).build();

      System.out.println("Sending list omnichannel setting request:");
      ListOmnichannelSettingsPagedResponse response =
          omnichannelSettingsServiceClient.listOmnichannelSettings(request);

      int count = 0;

      // Iterates over all the entries in the response.
      for (OmnichannelSetting omnichannelSetting : response.iterateAll()) {
        System.out.println(omnichannelSetting);
        count++;
      }
      System.out.println(String.format("The following count of elements were returned: %d", count));
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    omnichannelSettings(config);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\OmnichannelSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\ListOmnichannelSettingsRequest;

/**
 * This class demonstrates how to get the list of omnichannel settings for a
 * given Merchant Center account.
 */
class ListOmnichannelSettings
{
    /**
     * Helper to create the parent string.
     *
     * @param string $accountId The merchant account ID.
     * @return string The parent string in the format `accounts/{account}`.
     */
    private static function getParent(string $accountId): string
    {
        return sprintf('accounts/%s', $accountId);
    }

    /**
     * Lists the omnichannel settings for a given Merchant Center account.
     *
     * @param array $config The configuration file for authentication.
     */
    public static function listOmnichannelSettingsSample(array $config): void
    {
        // Obtains OAuth credentials from the configuration file.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates a client.
        $omnichannelSettingsServiceClient = new OmnichannelSettingsServiceClient([
            'credentials' => $credentials
        ]);

        // Constructs the parent resource name.
        $parent = self::getParent($config['accountId']);

        // Creates the request.
        $request = new ListOmnichannelSettingsRequest(['parent' => $parent]);

        // Calls the API and prints the response.
        try {
            printf("Sending list omnichannel setting request:%s", PHP_EOL);
            $response = $omnichannelSettingsServiceClient->listOmnichannelSettings($request);

            $count = 0;
            // Iterates over all the omnichannel settings and prints them.
            foreach ($response->iterateAllElements() as $omnichannelSetting) {
                print $omnichannelSetting->serializeToJsonString(true) . PHP_EOL;
                $count++;
            }
            printf("The following count of elements were returned: %d%s", $count, PHP_EOL);
        } catch (ApiException $e) {
            printf("An error has occured: %s", $e->getMessage());
        }
    }

    /**
     * Executes the sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();
        self::listOmnichannelSettingsSample($config);
    }
}

// Runs the script.
$sample = new ListOmnichannelSettings();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import ListOmnichannelSettingsRequest
from google.shopping.merchant_accounts_v1 import OmnichannelSettingsServiceClient


def list_omnichannel_settings(account_id: str) -> None:
  """Lists the omnichannel settings for a given Merchant Center account.

  Args:
      account_id: The ID of the Merchant Center account.
  """
  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = OmnichannelSettingsServiceClient(credentials=credentials)

  # The parent account for which to list the settings.
  parent = f"accounts/{account_id}"

  # Creates the request.
  request = ListOmnichannelSettingsRequest(parent=parent)

  # Makes the request and catches and prints any error messages.
  try:
    print("Sending list omnichannel setting request:")
    response = client.list_omnichannel_settings(request=request)

    count = 0
    # Iterates over all the entries in the response.
    for omnichannel_setting in response:
      print(omnichannel_setting)
      count += 1
    print(f"The following count of elements were returned: {count}")
  except RuntimeError as e:
    print("An error has occured: ")
    print(e)


if __name__ == "__main__":
  # The ID of the account to get the omnichannel settings for.
  _ACCOUNT = configuration.Configuration().read_merchant_info()

  list_omnichannel_settings(_ACCOUNT)

עדכון הגדרה של כל הערוצים

כדי לעדכן את ההגדרה של כל הערוצים, משתמשים ב-method‏ omnichannelSettings.update.

כדי לעדכן, צריך להוסיף את התכונה שרוצים למסכת העדכון, ולמלא את השדות המתאימים בשדה omnichannelSetting בבקשת העדכון. אתם יכולים לעדכן את

  • lsfType
  • inStock
  • pickup
  • odo
  • about
  • inventoryVerification

אם מאפיין לא נכלל במסכת העדכון, הוא לא יעודכן.

אם מאפיין נכלל במסכת העדכון אבל לא מוגדר בבקשה, הוא יימחק.

דוגמת הקוד הבאה מראה איך לעדכן את השדה של אימות המלאי.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.accounts.v1.InventoryVerification;
import com.google.shopping.merchant.accounts.v1.OmnichannelSetting;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingName;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import com.google.shopping.merchant.accounts.v1.UpdateOmnichannelSettingRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to update an omnichannel setting for a given Merchant Center account
 * in a given country
 */
public class UpdateOmnichannelSettingSample {

  public static void updateOmnichannelSettings(
      Config config, String regionCode, String contact, String email) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      String accountId = config.getAccountId().toString();
      String name =
          OmnichannelSettingName.newBuilder()
              .setAccount(accountId)
              .setOmnichannelSetting(regionCode)
              .build()
              .toString();

      OmnichannelSetting omnichannelSetting =
          OmnichannelSetting.newBuilder()
              .setName(name)
              .setInventoryVerification(
                  InventoryVerification.newBuilder()
                      .setContact(contact)
                      .setContactEmail(email)
                      .build())
              .build();
      FieldMask fieldMask = FieldMask.newBuilder().addPaths("inventory_verification").build();
      UpdateOmnichannelSettingRequest request =
          UpdateOmnichannelSettingRequest.newBuilder()
              .setOmnichannelSetting(omnichannelSetting)
              .setUpdateMask(fieldMask)
              .build();

      System.out.println("Sending update omnichannel setting request:");
      OmnichannelSetting response =
          omnichannelSettingsServiceClient.updateOmnichannelSetting(request);

      System.out.println("Updated Omnichannel Setting below:");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    // The country which you're targeting at.
    String regionCode = "{REGION_CODE}";
    // The name of the inventory verification contact you want to update.
    String contact = "{NAME}";
    // The address of the inventory verification email you want to update.
    String email = "{EMAIL}";

    updateOmnichannelSettings(config, regionCode, contact, email);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Shopping\Merchant\Accounts\V1\Client\OmnichannelSettingsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\InventoryVerification;
use Google\Shopping\Merchant\Accounts\V1\OmnichannelSetting;
use Google\Shopping\Merchant\Accounts\V1\UpdateOmnichannelSettingRequest;

/**
 * This class demonstrates how to update an omnichannel setting for a given
 * Merchant Center account in a given country.
 */
class UpdateOmnichannelSetting
{
    /**
     * Helper to create the name string.
     *
     * @param string $accountId The merchant account ID.
     * @param string $regionCode The region code of the setting.
     * @return string The name string in the format
     *     `accounts/{account}/omnichannelSettings/{omnichannelSetting}`.
     */
    private static function getName(string $accountId, string $regionCode): string
    {
        return sprintf('accounts/%s/omnichannelSettings/%s', $accountId, $regionCode);
    }

    /**
     * Updates an omnichannel setting for a given Merchant Center account.
     *
     * @param array $config The configuration file for authentication.
     * @param string $regionCode The country of the omnichannel setting.
     * @param string $contact The name of the inventory verification contact.
     * @param string $email The email of the inventory verification contact.
     */
    public static function updateOmnichannelSettingSample(
        array $config,
        string $regionCode,
        string $contact,
        string $email
    ): void {
        // Obtains OAuth credentials from the configuration file.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates a client.
        $omnichannelSettingsServiceClient = new OmnichannelSettingsServiceClient([
            'credentials' => $credentials
        ]);

        // Constructs the resource name.
        $name = self::getName($config['accountId'], $regionCode);

        // Creates the omnichannel setting with the updated fields.
        $omnichannelSetting = new OmnichannelSetting([
            'name' => $name,
            'inventory_verification' => new InventoryVerification([
                'contact' => $contact,
                'contact_email' => $email
            ])
        ]);

        // Creates the field mask to specify which fields to update.
        $fieldMask = new FieldMask([
            'paths' => ['inventory_verification']
        ]);

        // Creates the request.
        $request = new UpdateOmnichannelSettingRequest([
            'omnichannel_setting' => $omnichannelSetting,
            'update_mask' => $fieldMask
        ]);

        // Calls the API and prints the response.
        try {
            printf("Sending update omnichannel setting request:%s", PHP_EOL);
            $response = $omnichannelSettingsServiceClient->updateOmnichannelSetting($request);
            printf("Updated Omnichannel Setting below:%s", PHP_EOL);
            print $response->serializeToJsonString(true) . PHP_EOL;
        } catch (ApiException $e) {
            printf("An error has occured: %s", $e->getMessage());
        }
    }

    /**
     * Executes the sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();
        // The country which you're targeting.
        $regionCode = '{REGION_CODE}';
        // The name of the inventory verification contact you want to update.
        $contact = '{NAME}';
        // The address of the inventory verification email you want to update.
        $email = '{EMAIL}';
        self::updateOmnichannelSettingSample($config, $regionCode, $contact, $email);
    }
}

// Runs the script.
$sample = new UpdateOmnichannelSetting();
$sample->callSample();

Python

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.protobuf import field_mask_pb2
from google.shopping.merchant_accounts_v1 import InventoryVerification
from google.shopping.merchant_accounts_v1 import OmnichannelSetting
from google.shopping.merchant_accounts_v1 import OmnichannelSettingsServiceClient
from google.shopping.merchant_accounts_v1 import (
    UpdateOmnichannelSettingRequest,
)


def update_omnichannel_setting(
    account_id: str, region_code: str, contact: str, email: str
) -> None:
  """Updates an omnichannel setting for a given Merchant Center account.

  Args:
      account_id: The ID of the Merchant Center account.
      region_code: The country for which you're updating the setting.
      contact: The name of the inventory verification contact.
      email: The email of the inventory verification contact.
  """
  # Gets OAuth Credentials.
  credentials = generate_user_credentials.main()

  # Creates a client.
  client = OmnichannelSettingsServiceClient(credentials=credentials)

  # The name of the omnichannel setting to update.
  name = f"accounts/{account_id}/omnichannelSettings/{region_code}"

  # Creates an omnichannel setting with the updated values.
  omnichannel_setting = OmnichannelSetting()
  omnichannel_setting.name = name
  omnichannel_setting.inventory_verification = InventoryVerification(
      contact=contact, contact_email=email
  )

  # Creates a field mask to specify which fields to update.
  field_mask = field_mask_pb2.FieldMask(paths=["inventory_verification"])

  # Creates the request.
  request = UpdateOmnichannelSettingRequest(
      omnichannel_setting=omnichannel_setting, update_mask=field_mask
  )

  # Makes the request and catches and prints any error messages.
  try:
    print("Sending update omnichannel setting request:")
    response = client.update_omnichannel_setting(request=request)
    print("Updated Omnichannel Setting below:")
    print(response)
  except RuntimeError as e:
    print("An error has occured: ")
    print(e)


if __name__ == "__main__":
  # The ID of the account to get the omnichannel settings for.
  _ACCOUNT = configuration.Configuration().read_merchant_info()

  # The country which you're targeting.
  _REGION_CODE = "{REGION_CODE}"
  # The name of the inventory verification contact you want to update.
  _CONTACT = "{NAME}"
  # The address of the inventory verification email you want to update.
  _EMAIL = "{EMAIL}"

  update_omnichannel_setting(_ACCOUNT, _REGION_CODE, _CONTACT, _EMAIL)

בקשה לאימות מלאי

omnichannelSettings.requestInventoryVerification רלוונטי רק למוכרים ב-GHLSF.

לפני שקוראים ל-RPC הזה, צריך לבצע את הפעולות הבאות:

  • מעלים את נתוני המוצרים והמלאי.
  • מאמתים את איש הקשר לאימות המלאי.
  • מוכרים באוסטריה, גרמניה או שווייץ צריכים להשלים בדיקה של דף About.

כדי לבדוק אם אתם עומדים בדרישות, התקשרו למספר omnichannelSettings.get ועיינו בכתובת omnichannelSetting.inventoryVerification.state. אם מופיע הסמל INACTIVE, אתם יכולים להתקשר אל omnichannelSettings.requestInventoryVerification.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingName;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceClient;
import com.google.shopping.merchant.accounts.v1.OmnichannelSettingsServiceSettings;
import com.google.shopping.merchant.accounts.v1.RequestInventoryVerificationRequest;
import com.google.shopping.merchant.accounts.v1.RequestInventoryVerificationResponse;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/**
 * This class demonstrates how to request inventory verification for a given Merchant Center account
 * in a given country
 */
public class RequestInventoryVerificationSample {

  public static void requestInventoryVerification(Config config, String regionCode)
      throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    OmnichannelSettingsServiceSettings omnichannelSettingsServiceSettings =
        OmnichannelSettingsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (OmnichannelSettingsServiceClient omnichannelSettingsServiceClient =
        OmnichannelSettingsServiceClient.create(omnichannelSettingsServiceSettings)) {
      String accountId = config.getAccountId().toString();
      String name =
          OmnichannelSettingName.newBuilder()
              .setAccount(accountId)
              .setOmnichannelSetting(regionCode)
              .build()
              .toString();
      RequestInventoryVerificationRequest request =
          RequestInventoryVerificationRequest.newBuilder().setName(name).build();

      System.out.println("Sending request inventory verification request:");
      RequestInventoryVerificationResponse response =
          omnichannelSettingsServiceClient.requestInventoryVerification(request);

      System.out.println("Omnichannel Setting after inventory verification request below:");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    // The country which you're targeting at.
    String regionCode = "{REGION_CODE}";

    requestInventoryVerification(config, regionCode);
  }
}

לראות את הסטטוס של הגדרת אומניצ'אנל.

כדי לבדוק את סטטוס הבדיקה של תהליך ההפעלה של מודעות LIA, בודקים את ReviewState כדי לראות את המאפיינים התואמים של omnichannelSetting שהוחזרו על ידי השיטות omnichannelSettings.get או omnichannelSettings.list.

השדה ReviewState רלוונטי לכל הבדיקות של תהליך ההצטרפות, חוץ מתהליך אימות המלאי, ויכול לכלול את הערכים הבאים:

  • ‫ACTIVE: אושר.
  • ‫FAILED: נדחה.
  • ‫RUNNING: הוא עדיין בבדיקה.
  • ‫ACTION_REQUIRED: קיים רק ב-InStock.state למוכרים ב-GHLSF. זה אומר שאתם צריכים לבקש אימות מלאי כדי להציג מודעות LIA.

‫InventoryVerification.State יכול לקבל את הערכים הבאים:

  • ‫SUCCEEDED: אושר.
  • INACTIVE: אתם מוכנים לבקש אימות מלאי.
  • RUNNING: בבדיקה
  • ‫SUSPENDED: נכשלתם באימות המלאי יותר מדי פעמים (בדרך כלל 5), ואתם צריכים להמתין לפני שתוכלו לבקש אימות נוסף.
  • ACTION_REQUIRED: צריך לבצע פעולות נוספות לפני ששולחים בקשה לאימות מלאי.

פתרון בעיות שקשורות אל Omnichannel Settings API

בקטע הזה מוסבר איך לפתור בעיות נפוצות.

יצירת הגדרה לכל הערוצים

  • חשוב להגדיר גם את LsfType וגם את RegionCode.
  • אם בוחרים באפשרות GHLSF, צריך לספק InStock ריק בבקשה.
  • אם אתם בוחרים סוגים של דפי מוצר עם נתוני זמינות ומחיר באתר של המוכר, אתם צריכים לספק לפחות URI אחד במאפיין InStock או Pickup.

עדכון הגדרה של כל הערוצים

כדי להשתמש בשיטת העדכון של המשאב הזה, צריך להוסיף את הכללים הבאים:

  • אי אפשר לשנות את קוד האזור.
  • אי אפשר לבצע עדכונים כשהתכונה LIA או FLL פועלת או אחרי שהיא אושרה.
  • כשעוברים מסוגי דפי נחיתה של חנות ב-Merchant Center ל-GHLSF, אם InStock ו-Pickup הוגדרו בעבר, צריך לכלול אותם במסכת העדכון יחד עם העדכון של LsfType.

לדוגמה, אם הגשתם בקשה ל-MHLSF_BASIC ול-Pickup והיא נדחתה, אתם יכולים לעבור ל-GHLSF על ידי שליחת בקשה כזו:

PATCH https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/omnichannelSettings/{REGION_CODE}?update_mask=lsf_type,in_stock,pickup

{
  "lsfType": "GHLSF",
  "inStock": {},
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫{ACCOUNT_ID}: המזהה הייחודי של חשבון Merchant Center
  • ‫{REGION_CODE}: קוד אזור כפי שמוגדר ב-CLDR

בקשה לאימות מלאי

אם עדכנתם את פיד המוצרים או את פיד המלאי ואישרתם את איש הקשר, אבל הערך של InventoryVerification.state הוא לא INACTIVE:

  • מוכרים באוסטריה, גרמניה ושווייץ: ודאו שביצעתם בדיקה של דף המידע הכללי.
  • יהיה עיכוב של כ-48 שעות.
  • אם בדיקת המלאי נכשלת שוב ושוב (יותר מחמש פעמים), השירות אוכף תקופת צינון של שלושים יום לפני שאפשר להגיש בקשה נוספת. כדי לבקש את ההחזר מוקדם יותר, אפשר לפנות לתמיכה של Google.

מידע נוסף

פרטים נוספים זמינים במרכז העזרה בנושא מודעות מלאי של חנויות מקומיות וכרטיסים חינמיים למוצרים מקומיים.