อัปเดตผลิตภัณฑ์เป็นประจำ

Sub-API ของผลิตภัณฑ์ช่วยให้คุณทำการอัปเดตบางส่วนกับผลิตภัณฑ์ที่มีอยู่ได้ ซึ่งเหมาะอย่างยิ่งสำหรับข้อมูลที่มีการเปลี่ยนแปลงบ่อยครั้ง เช่น ราคาและความพร้อมจำหน่ายสินค้า เนื่องจากไม่จำเป็นต้องส่งผลิตภัณฑ์ทั้งหมดอีกครั้งสำหรับการเปลี่ยนแปลงเล็กน้อย อย่างไรก็ตาม คุณควรแทรกผลิตภัณฑ์อีกครั้งเป็นประจำเพื่อให้แน่ใจว่าข้อมูลสินค้าทั้งหมดซิงค์กัน

คู่มือนี้จะอธิบายวิธีใช้เมธอด productinputs.patch เพื่ออัปเดตผลิตภัณฑ์

ข้อกำหนดเบื้องต้น

คุณต้องมีสิ่งต่อไปนี้ก่อนจึงจะอัปเดตผลิตภัณฑ์ได้

อัปเดตรายละเอียดสินค้าที่เฉพาะเจาะจง

หากต้องการเปลี่ยนรายละเอียดบางอย่างของผลิตภัณฑ์ เช่น ราคาหรือความพร้อมจำหน่ายสินค้า โดยไม่ต้อง ส่งข้อมูลทั้งหมดอีกครั้ง ให้ใช้ productInputs.patch เมธอด

คุณสามารถระบุช่องที่ต้องการเปลี่ยนแปลงในพารามิเตอร์ updateMask updateMask คือรายการที่คั่นด้วยคอมมาของช่องที่คุณต้องการอัปเดต เมธอด patch จะทำงานดังนี้

  • ช่องใน updateMask และเนื้อหา: ช่องเหล่านี้จะอัปเดตด้วย ค่าใหม่
  • ช่องใน updateMask แต่ไม่อยู่ในเนื้อหา: ช่องเหล่านี้จะถูกลบออกจาก อินพุตผลิตภัณฑ์
  • ช่องที่ไม่อยู่ใน updateMask: ช่องเหล่านี้จะไม่มีการเปลี่ยนแปลง
  • ละเว้นพารามิเตอร์updateMask: ระบบจะอัปเดตช่องทั้งหมดที่ระบุไว้ในเนื้อหาคำขอ และจะไม่ลบช่องที่ไม่ได้ระบุไว้ในเนื้อหาคำขอออกจากข้อมูลผลิตภัณฑ์

ตัวอย่างข้อมูลสินค้าก่อนการอัปเดต

{
  "name": "accounts/{ACCOUNT_ID}/productInputs/en~US~SKU12345",
  "product": "accounts/{ACCOUNT_ID}/products/en~US~SKU12345",
  "offerId": "SKU12345",
  "contentLanguage": "en",
  "feedLabel": "US",
  "productAttributes": {
    "title": "Classic Cotton T-Shirt",
    "description": "A comfortable, durable, and stylish t-shirt made from 100% cotton.",
    "link": "https://www.example.com/p/SKU12345",
    "availability": "IN_STOCK",
    "price": {
      "amountMicros": "15990000",
      "currencyCode": "USD"
    },
    "condition": "NEW",
    "gtins": [
      "9780007350896"
    ],
    "imageLink": "https://www.example.com/image/SKU12345"
  }
}

ตัวอย่างนี้จะอัปเดต title และ availability ของผลิตภัณฑ์ รวมถึงลบ imageLink description และ price ไม่อยู่ใน updateMask จึงจะไม่มีการเปลี่ยนแปลง

PATCH https://merchantapi.googleapis.com/products/v1/accounts/{ACCOUNT_ID}/productInputs/en~US~SKU12345?updateMask=productAttributes.title,productAttributes.availability,productAttributes.imageLink&dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}
{
 "productAttributes": {
   "title": "Classic Cotton T-Shirt - New Edition",
   "availability": "OUT_OF_STOCK",
    "description": "A comfortable T-shirt from premium cotton, newer edition.",
    "price": {
      "amountMicros": "9990000",
      "currencyCode": "USD"
    }
 }
}

การเรียกใช้ที่สำเร็จจะแสดงทรัพยากร ProductInput ที่อัปเดต title และ availability จะได้รับการอัปเดต และ imageLink จะถูกนำออกเนื่องจากอยู่ใน updateMask แต่ไม่อยู่ในเนื้อหาคำขอ description และ price จะไม่มีการเปลี่ยนแปลงเนื่องจากไม่ได้ระบุไว้ใน updateMask

{
  "name": "accounts/{ACCOUNT_ID}/productInputs/en~US~SKU12345",
  "product": "accounts/{ACCOUNT_ID}/products/en~US~SKU12345",
  "offerId": "SKU12345",
  "contentLanguage": "en",
  "feedLabel": "US",
  "productAttributes": {
    "title": "Classic Cotton T-Shirt - New Edition",
    "description": "A comfortable, durable, and stylish t-shirt made from 100% cotton.",
    "link": "https://www.example.com/p/SKU12345",
    "availability": "OUT_OF_STOCK",
    "price": {
      "amountMicros": "15990000",
      "currencyCode": "USD"
    },
    "condition": "NEW",
    "gtins": [
      "9780007350896"
    ],
  }
}

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีอัปเดตผลิตภัณฑ์

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.datasources.v1.DataSourceName;
import com.google.shopping.merchant.products.v1.Availability;
import com.google.shopping.merchant.products.v1.Condition;
import com.google.shopping.merchant.products.v1.ProductAttributes;
import com.google.shopping.merchant.products.v1.ProductInput;
import com.google.shopping.merchant.products.v1.ProductInputName;
import com.google.shopping.merchant.products.v1.ProductInputsServiceClient;
import com.google.shopping.merchant.products.v1.ProductInputsServiceSettings;
import com.google.shopping.merchant.products.v1.UpdateProductInputRequest;
import com.google.shopping.type.CustomAttribute;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to update a product input */
public class UpdateProductInputSample {

  public static void updateProductInput(Config config, String productId, String dataSourceId)
      throws Exception {

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

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

    // Creates product name to identify product.
    String name =
        ProductInputName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setProductinput(productId)
            .build()
            .toString();

    // Just productAttributes and customAttributes can be updated
    FieldMask fieldMask =
        FieldMask.newBuilder()
            .addPaths("product_attributes.title")
            .addPaths("product_attributes.description")
            .addPaths("product_attributes.link")
            .addPaths("product_attributes.image_link")
            .addPaths("product_attributes.availability")
            .addPaths("product_attributes.condition")
            .addPaths("product_attributes.gtins")
            .addPaths("custom_attributes.mycustomattribute")
            .build();

    // Calls the API and catches and prints any network failures/errors.
    try (ProductInputsServiceClient productInputsServiceClient =
        ProductInputsServiceClient.create(productInputsServiceSettings)) {

      ProductAttributes attributes =
          ProductAttributes.newBuilder()
              .setTitle("A Tale of Two Cities")
              .setDescription("A classic novel about the French Revolution")
              .setLink("https://exampleWebsite.com/tale-of-two-cities.html")
              .setImageLink("https://exampleWebsite.com/tale-of-two-cities.jpg")
              .setAvailability(Availability.IN_STOCK)
              .setCondition(Condition.NEW)
              .addGtins("9780007350896")
              .build();

      // The datasource can be either a primary or supplemental datasource.
      String dataSource =
          DataSourceName.newBuilder()
              .setAccount(config.getAccountId().toString())
              .setDatasource(dataSourceId)
              .build()
              .toString();

      UpdateProductInputRequest request =
          UpdateProductInputRequest.newBuilder()
              .setUpdateMask(fieldMask)
              // You can only update product attributes and custom_attributes
              .setDataSource(dataSource)
              .setProductInput(
                  ProductInput.newBuilder()
                      .setName(name)
                      .setProductAttributes(attributes)
                      .addCustomAttributes(
                          CustomAttribute.newBuilder()
                              .setName("mycustomattribute")
                              .setValue("Example value")
                              .build())
                      .build())
              .build();

      System.out.println("Sending update ProductInput request");
      ProductInput response = productInputsServiceClient.updateProductInput(request);
      System.out.println("Updated ProductInput Name below");
      // The last part of the product name will be the product ID assigned to a product by Google.
      // Product ID has the format `contentLanguage~feedLabel~offerId`
      System.out.println(response.getName());
      System.out.println("Updated Product below");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // An ID assigned to a product by Google. In the format
    // contentLanguage~feedLabel~offerId
    String productId = "en~label~sku123"; // Replace with your product ID.

    // Identifies the data source that will own the product input.
    String dataSourceId = "{INSERT_DATASOURCE_ID}"; // Replace with your datasource ID.

    updateProductInput(config, productId, dataSourceId);
  }
}

PHP

use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Shopping\Merchant\Products\V1\Availability;
use Google\Shopping\Merchant\Products\V1\Condition;
use Google\Shopping\Merchant\Products\V1\ProductAttributes;
use Google\Shopping\Merchant\Products\V1\Client\ProductInputsServiceClient;
use Google\Shopping\Merchant\Products\V1\ProductInput;
use Google\Shopping\Merchant\Products\V1\UpdateProductInputRequest;
use Google\Shopping\Type\CustomAttribute;

/**
 * This class demonstrates how to update a product input.
 */
class UpdateProductInputSample
{
    // An ID assigned to a product by Google. In the format
    // contentLanguage~feedLabel~offerId
    // Please ensure this product ID exists for the update to succeed.
    private const PRODUCT_ID = "online~en~label~sku123";

    // Identifies the data source that will own the product input.
    // Please ensure this data source ID exists.
    private const DATASOURCE_ID = "<INSERT_DATASOURCE_ID>";

    /**
     * Helper function to construct the full product input resource name.
     *
     * @param string $accountId The merchant account ID.
     * @param string $productInputId The product input ID (e.g., "online~en~label~sku123").
     * @return string The full product input resource name.
     */
    private static function getProductInputName(string $accountId, string $productInputId): string
    {
        return sprintf("accounts/%s/productInputs/%s", $accountId, $productInputId);
    }

    /**
     * Helper function to construct the full data source resource name.
     *
     * @param string $accountId The merchant account ID.
     * @param string $dataSourceId The data source ID.
     * @return string The full data source resource name.
     */
    private static function getDataSourceName(string $accountId, string $dataSourceId): string
    {
        return sprintf("accounts/%s/dataSources/%s", $accountId, $dataSourceId);
    }

    /**
     * Updates an existing product input in your Merchant Center account.
     *
     * @param array $config The configuration array containing the account ID.
     * @param string $productId The ID of the product input to update.
     * @param string $dataSourceId The ID of the data source.
     */
    public static function updateProductInput(
        array $config,
        string $productId,
        string $dataSourceId
    ): void {
        // Gets the OAuth credentials to make the request.
        $credentials = Authentication::useServiceAccountOrTokenFile();

        // Creates options config containing credentials for the client to use.
        $options = ['credentials' => $credentials];

        // Creates a ProductInputsServiceClient.
        $productInputsServiceClient = new ProductInputsServiceClient($options);

        // Construct the full resource name of the product input to be updated.
        $name = self::getProductInputName($config['accountId'], $productId);

        // Define the FieldMask to specify which fields to update.
        // Only 'attributes' and 'custom_attributes' can be specified in the
        // FieldMask for product input updates.
        $fieldMask = new FieldMask([
            'paths' => [
                "product_attributes.title",
                "product_attributes.description",
                "product_attributes.link",
                "product_attributes.image_link",
                "product_attributes.availability",
                "product_attributes.condition",
                "product_attributes.gtin",
                "custom_attributes.mycustomattribute" // Path for a specific custom attribute
            ]
        ]);

        // Calls the API and handles any network failures or errors.
        try {
            // Define the new attributes for the product.
            $attributes = new ProductAttributes([
                'title' => 'A Tale of Two Cities 3',
                'description' => 'A classic novel about the French Revolution',
                'link' => 'https://exampleWebsite.com/tale-of-two-cities.html',
                'image_link' => 'https://exampleWebsite.com/tale-of-two-cities.jpg',
                'availability' => Availability::IN_STOCK,
                'condition' => Condition::PBNEW,
                'gtins' => ['9780007350896'] // GTIN is a repeated field.
            ]);

            // Construct the full data source name.
            // This specifies the data source context for the update.
            $dataSource = self::getDataSourceName($config['accountId'], $dataSourceId);

            // Create the ProductInput object with the desired updates.
            // The 'name' field must match the product input being updated.
            $productInput = new ProductInput([
                'name' => $name,
                'product_attributes' => $attributes,
                'custom_attributes' => [ // Provide the list of custom attributes.
                    new CustomAttribute([
                        'name' => 'mycustomattribute',
                        'value' => 'Example value'
                    ])
                ]
            ]);

            // Create the UpdateProductInputRequest.
            $request = new UpdateProductInputRequest([
                'update_mask' => $fieldMask,
                'data_source' => $dataSource,
                'product_input' => $productInput
            ]);

            print "Sending update ProductInput request\n";
            // Make the API call to update the product input.
            $response = $productInputsServiceClient->updateProductInput($request);

            print "Updated ProductInput Name below\n";
            // The name of the updated product input.
            // The last part of the product name is the product ID (e.g., contentLanguage~feedLabel~offerId).
            print $response->getName() . "\n";
            print "Updated Product below\n";
            // Print the full updated product input object.
            print_r($response);

        } catch (ApiException $e) {
            printf("ApiException caught: %s\n", $e->getMessage());
        }
    }

    /**
     * Executes the UpdateProductInput sample.
     */
    public function callSample(): void
    {
        $config = Config::generateConfig();
        $productId = self::PRODUCT_ID;
        $dataSourceId = self::DATASOURCE_ID;

        self::updateProductInput($config, $productId, $dataSourceId);
    }
}

// Run the script.
$sample = new UpdateProductInputSample();
$sample->callSample();

Python

"""A module to update a product input."""

from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.protobuf import field_mask_pb2
from google.shopping.merchant_products_v1 import Availability
from google.shopping.merchant_products_v1 import Condition
from google.shopping.merchant_products_v1 import ProductAttributes
from google.shopping.merchant_products_v1 import ProductInput
from google.shopping.merchant_products_v1 import ProductInputsServiceClient
from google.shopping.merchant_products_v1 import UpdateProductInputRequest
from google.shopping.type import CustomAttribute


# Fetches the Merchant Center account ID from the authentication examples.
# This ID is needed to construct resource names for the API.
_ACCOUNT_ID = configuration.Configuration().read_merchant_info()


def update_product_input(account_id: str, product_id: str, data_source_id: str):
  """Updates an existing product input for a specific account.

  Args:
    account_id: The Merchant Center account ID.
    product_id: The ID of the product input to update. This ID is assigned by
      Google and has the format `contentLanguage~feedLabel~offerId`.
    data_source_id: The ID of the data source that owns the product input.
  """

  # Obtains OAuth credentials for authentication.
  credentials = generate_user_credentials.main()

  # Creates a ProductInputsServiceClient instance.
  client = ProductInputsServiceClient(credentials=credentials)

  # Constructs the full resource name for the product input.
  # Format: accounts/{account}/productInputs/{productinput}
  name = f"accounts/{account_id}/productInputs/{product_id}"

  # Defines the FieldMask to specify which fields of the product input
  # are being updated. Only 'attributes' and 'custom_attributes' can be updated.
  field_mask = field_mask_pb2.FieldMask(
      paths=[
          "product_attributes.title",
          "product_attributes.description",
          "product_attributes.link",
          "product_attributes.image_link",
          "product_attributes.availability",
          "product_attributes.condition",
          "product_attributes.gtins",
          "custom_attributes.mycustomattribute",
      ]
  )

  # Prepares the new attribute values for the product.
  attributes = ProductAttributes(
      title="A Tale of Two Cities updated",
      description="A classic novel about the French Revolution",
      link="https://exampleWebsite.com/tale-of-two-cities.html",
      image_link="https://exampleWebsite.com/tale-of-two-cities.jpg",
      availability=Availability.IN_STOCK,
      condition=Condition.NEW,
      gtins=["9780007350896"],  # GTIN is a repeated field.
  )

  # Constructs the full resource name for the data source.
  # The data source can be primary or supplemental.
  # Format: accounts/{account}/dataSources/{datasource}
  data_source = f"accounts/{account_id}/dataSources/{data_source_id}"

  # Prepares the ProductInput object with the updated information.
  product_input_data = ProductInput(
      name=name,
      product_attributes=attributes,
      custom_attributes=[
          CustomAttribute(
              name="mycustomattribute", value="Example value"
          )
      ],
  )

  # Creates the UpdateProductInputRequest.
  request = UpdateProductInputRequest(
      update_mask=field_mask,
      data_source=data_source,
      product_input=product_input_data,
  )

  # Sends the update request to the API.
  try:
    print("Sending update ProductInput request")
    response = client.update_product_input(request=request)
    print("Updated ProductInput Name below")
    # The response includes the name of the updated product input.
    # The last part of the product name is the product ID assigned by Google.
    print(response.name)
    print("Updated Product below")
    print(response)
  except RuntimeError as e:
    # Catches and prints any errors that occur during the API call.
    print(e)


if __name__ == "__main__":
  # The ID of the product to be updated.
  # This ID is assigned by Google and typically follows the format:
  # contentLanguage~feedLabel~offerId
  # Replace with an actual product ID from your Merchant Center account.
  product_id_to_update = "online~en~label~sku123"

  # The ID of the data source that will own the updated product input.
  # Replace with an actual data source ID from your Merchant Center account.
  data_source_id_for_update = "<INSERT_DATA_SOURCE_ID>"

  update_product_input(
      _ACCOUNT_ID, product_id_to_update, data_source_id_for_update
  )

cURL

curl --location --request PATCH 'https://merchantapi.googleapis.com/products/v1/accounts/{ACCOUNT_ID}/productInputs/en~US~SKU12345?updateMask=productAttributes.title,productAttributes.description&dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}' \
--header 'Authorization: Bearer <API_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
   "productAttributes": {
       "title": "A Tale of Two Cities",
       "description": "A classic novel about the French Revolution"
   }
}'

อัปเดตโดยใช้แอตทริบิวต์ที่กำหนดเอง

คุณสามารถอัปเดตทั้งแอตทริบิวต์มาตรฐานและแอตทริบิวต์ที่กำหนดเองได้ในการเรียกใช้ครั้งเดียว หากต้องการอัปเดตแอตทริบิวต์ที่กำหนดเอง ให้ใส่คำนำหน้า customAttributes ที่ชื่อแอตทริบิวต์ใน updateMask

ตัวอย่างนี้จะดำเนินการหลายอย่างในคำขอเดียว

  • อัปเดตแอตทริบิวต์ title มาตรฐานโดยตรง
  • อัปเดตแอตทริบิวต์ที่กำหนดเองที่มีอยู่ (myCustomAttrToBeUpdated)
  • แทรกแอตทริบิวต์ที่กำหนดเองใหม่ (myCustomAttrToBeInserted)
  • ลบแอตทริบิวต์ที่กำหนดเองที่มีอยู่ (myCustomAttrToBeDeleted)
PATCH https://merchantapi.googleapis.com/products/v1/accounts/{ACCOUNT_ID}/productInputs/en~US~SKU12345?updateMask=productAttributes.title,customAttributes.myCustomAttrToBeInserted,customAttributes.myCustomAttrToBeUpdated,customAttributes.myCustomAttrToBeDeleted&dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}
{
  "productAttributes": {
    "title": "ProductTitle Updated"
  },
  "customAttributes": [
    {
      "name": "description",
      "value": "A newly updated description."
    },
    {
      "name": "myCustomAttrToBeUpdated",
      "value": "myCustomAttrToBeUpdated updated value"
    },
    {
      "name": "myCustomAttrToBeInserted",
      "value": "new from update"
    }
  ]
}

คำขอที่สำเร็จจะแสดง ProductInput ที่อัปเดตซึ่งแสดงการเปลี่ยนแปลงทั้งหมดที่ระบุ

ทำความเข้าใจการอัปเดตแอตทริบิวต์ที่กำหนดเอง

คุณสามารถใช้ช่อง customAttributes เพื่ออัปเดตแอตทริบิวต์ที่คุณกำหนดเอง แอตทริบิวต์เหล่านี้จะไม่สอดคล้องกับข้อกำหนดมาตรฐานและจะจัดเก็บเป็นแอตทริบิวต์ที่กำหนดเองในผลิตภัณฑ์ขั้นสุดท้าย

วิธีประมวลผลการอัปเดตผลิตภัณฑ์

เมื่อคุณส่งคำขอ patch ระบบจะใช้การอัปเดตกับข้อมูล ProductInput ที่เฉพาะเจาะจง ก่อน ที่จะใช้กฎใดๆ ซึ่งจะทำให้การแทรกและการอัปเดตผลิตภัณฑ์มีลักษณะการทำงานที่สอดคล้องกัน

ระบบจะประมวลผลการอัปเดตดังนี้

  1. อัปเดตอินพุต: คำขอ patch ของคุณจะแก้ไข ProductInput ที่เฉพาะเจาะจงซึ่งเชื่อมโยงกับแหล่งข้อมูลที่คุณระบุ

  2. การประมวลผลและการผสาน: หลังจากอัปเดตข้อมูลแล้ว การประมวลผลจะเริ่มต้นขึ้น

    • กฎฟีดและแหล่งข้อมูลเสริม: กฎที่กำหนดค่าไว้ในแหล่งข้อมูลหลักของผลิตภัณฑ์จะรวม ProductInput จากแหล่งข้อมูลหลักและแหล่งข้อมูลเสริม กฎเหล่านี้สามารถเปลี่ยนแอตทริบิวต์หรือสร้างแอตทริบิวต์ใหม่ได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับการตั้งค่ากฎได้ที่ ตั้งค่ากฎแอตทริบิวต์
    • แหล่งข้อมูลอื่นๆ: ระบบจะผสานข้อมูลจากแหล่งข้อมูลอื่นๆ (เช่น การปรับปรุงอัตโนมัติ) เข้ากับข้อมูลจากแหล่งข้อมูลหลักด้วย
    • การตรวจสอบ: ระบบจะตรวจสอบข้อมูลที่ผสานกับข้อกำหนดในการจัดทำข้อมูลผลิตภัณฑ์และนโยบาย Shopping ของ Google
  3. ผลิตภัณฑ์ขั้นสุดท้าย: ผลลัพธ์ของไปป์ไลน์นี้คือทรัพยากร Product ที่ประมวลผลแล้วขั้นสุดท้าย ซึ่งสามารถแสดงผลได้โดยใช้ products.get หรือ products.list นอกจากนี้ยังเป็นเวอร์ชันของผลิตภัณฑ์ที่จะแสดงใน Merchant Center และมีสิทธิ์ปรากฏในปลายทางต่างๆ

กระบวนการนี้มีหลายขั้นตอน จึงอาจมีความล่าช้าเกิดขึ้น ซึ่งโดยปกติจะใช้เวลา 2-3 นาทีระหว่างที่คุณส่งคำขออัปเดตกับเวลาที่การเปลี่ยนแปลงปรากฏในทรัพยากร Product ขั้นสุดท้ายที่คุณดึงข้อมูลได้ด้วย products.get

ตัวอย่าง: การอัปเดตผลิตภัณฑ์ด้วยข้อมูลหลักรายการเดียว

นี่เป็นกรณีการใช้งานที่พบบ่อยที่สุด ผลิตภัณฑ์อยู่ในแหล่งข้อมูลหลักแหล่งเดียว และคุณต้องการอัปเดตแอตทริบิวต์บางอย่างของผลิตภัณฑ์

  1. สถานะเริ่มต้น: ผลิตภัณฑ์ en~US~SKU12345 อยู่ในแหล่งข้อมูลหลัก โดยมี title: "Classic T-Shirt" และ price: 15.99 USD
  2. คำขออัปเดต: คุณส่งคำขอ patch เพื่ออัปเดต price เป็น 14.99 USD และตั้งค่า availability เป็น out of stock
  3. การประมวลผล:
    • ระบบจะอัปเดต ProductInput สำหรับ SKU12345
  4. ผลิตภัณฑ์ขั้นสุดท้าย: ตอนนี้ Product ขั้นสุดท้ายมี title: "Classic T-Shirt", price: 14.99 USD และ availability: "out of stock"

ตัวอย่าง: การอัปเดตผลิตภัณฑ์ด้วยข้อมูลและกฎเสริม

ตัวอย่างนี้แสดงให้เห็นว่ากฎฟีดอาจส่งผลต่อการอัปเดตอย่างไร โดยทำให้มีการใช้การเปลี่ยนแปลงบางอย่างในขณะที่การเปลี่ยนแปลงอื่นๆ ถูกเขียนทับ

  1. สถานะเริ่มต้น:
    • ข้อมูลหลัก: en~US~SKU12345 มี title: "Great T-Shirt" และ description: "A great short-sleeve t-shirt."
    • ข้อมูลเสริม: ผลิตภัณฑ์เดียวกันมีรายการในแหล่งข้อมูลเสริม โดยมี title: "Awesome T-Shirt" และ description: "An awesome short-sleeve t-shirt."
    • กฎฟีด: มีการตั้งกฎให้ใช้ title จากแหล่งข้อมูลเสริม ไม่มีกฎสำหรับ description
    • ผลลัพธ์: ที่ประมวลผลแล้วขั้นสุดท้ายมี Product title: "Awesome T-Shirt" และ description: "A great short-sleeve t-shirt."
  2. คำขออัปเดต: คุณส่งคำขอ patch เพื่ออัปเดตแหล่งข้อมูลหลัก โดยตั้งค่า title เป็น "Fantastic T-Shirt" และ description เป็น "A fantastic short-sleeve t-shirt."
  3. การประมวลผล:
    • ระบบจะอัปเดต ProductInput ในแหล่งข้อมูลหลักให้มี title: "Fantastic T-Shirt" และ description: "A fantastic short-sleeve t-shirt."
    • ไปป์ไลน์การประมวลผลจะทำงาน
    • สำหรับ title กฎฟีดจะกำหนดให้ค่าจากแหล่งข้อมูลเสริม (Awesome T-Shirt) มีลำดับความสำคัญสูงกว่า ซึ่งจะเขียนทับการอัปเดตของคุณ
    • สำหรับ description เนื่องจากไม่มีกฎการเขียนทับ ระบบจึงใช้ค่าที่อัปเดตจากอินพุตหลัก (A fantastic short-sleeve t-shirt.)
  4. ผลิตภัณฑ์ขั้นสุดท้าย: `title` ของ Product ขั้นสุดท้ายยังคงเป็น Awesome T-Shirt (การอัปเดตของคุณถูกเขียนทับ) แต่ `description` จะเป็น A fantastic short-sleeve t-shirt. (การอัปเดตของคุณมีผล) แล้ว

เลือกระหว่างการอัปเดตกับแหล่งข้อมูลเสริม

คุณสามารถแก้ไขข้อมูลสินค้าได้โดยใช้ productinputs.patch หรือแทรกข้อมูลลงในแหล่งข้อมูลเสริม ตัวเลือกที่ดีที่สุดขึ้นอยู่กับกลยุทธ์การจัดการข้อมูลของคุณ

เราขอแนะนำว่าอย่าใช้ทั้ง productinputs.patch และแหล่งข้อมูลเสริมเพื่อจัดการข้อมูลผลิตภัณฑ์เดียวกันสำหรับผลิตภัณฑ์เดียวกัน เพื่อหลีกเลี่ยงผลลัพธ์ที่คาดเดาไม่ได้

การเปรียบเทียบแบบละเอียดมีดังนี้

ฟีเจอร์ productinputs.patch (การอัปเดต) แหล่งข้อมูลเสริม
เหมาะสำหรับ การเปลี่ยนแปลงบางส่วนที่รวดเร็วและเกิดขึ้นบ่อยครั้งกับข้อมูลที่มีอยู่ (เช่น ราคา ความพร้อมจำหน่ายสินค้า) การจัดเลเยอร์ข้อมูลที่แยกกันอย่างมีเหตุผล การจัดการแอตทริบิวต์ต่างๆ โดยระบบต่างๆ หรือการเขียนทับที่ซับซ้อนตามกฎ
กลไก แก้ไข ProductInput ที่มีอยู่โดยตรง สร้าง ProductInput ใหม่ที่แยกต่างหากในแหล่งข้อมูลเสริม
ความละเอียดของข้อมูล ทำงานกับช่องที่เฉพาะเจาะจงของ ProductInput รายการเดียว ทำงานกับ ProductInput ทั้งหมดภายในแหล่งข้อมูลเสริม
ความคงอยู่ การเปลี่ยนแปลงจะคงอยู่จนกว่า ProductInput เดียวกันจะถูกเขียนทับด้วย insert แบบเต็มหรือ patch อื่น กฎฟีดจะเป็นตัวควบคุมความคงอยู่ และสามารถเขียนทับข้อมูลหลักได้อย่างไม่มีกำหนดหากกฎให้ความสำคัญกับข้อมูลหลัก
การโต้ตอบของกฎ สามารถใช้ได้โดยไม่ต้องมีกฎฟีด เนื่องจากจะอัปเดตแหล่งข้อมูลและ ProductInput ที่มีอยู่ ต้องตั้งค่ากฎในแหล่งข้อมูลหลักอย่างชัดเจนเพื่อลิงก์แหล่งข้อมูลเสริม
การตั้งค่าแหล่งข้อมูล ทำงานกับแหล่งข้อมูลที่มีอยู่ โดยไม่จำเป็นต้องมีแหล่งข้อมูลใหม่ ต้องสร้างและจัดการแหล่งข้อมูลเสริมที่แยกต่างหาก รวมถึงลิงก์แหล่งข้อมูลเหล่านั้นโดยใช้กฎฟีด