API Sản phẩm cho phép bạn cập nhật một phần cho các sản phẩm hiện có. Đây là lựa chọn lý tưởng cho dữ liệu thường xuyên thay đổi, chẳng hạn như giá và tình trạng còn hàng, vì bạn không cần phải gửi lại toàn bộ sản phẩm cho một thay đổi nhỏ. Tuy nhiên, bạn nên thường xuyên chèn lại sản phẩm để đảm bảo tất cả dữ liệu sản phẩm đều được đồng bộ hoá.
Hướng dẫn này trình bày cách sử dụng phương thức productinputs.patch
để cập nhật sản phẩm.
Điều kiện tiên quyết
Để có thể cập nhật một sản phẩm, bạn cần có những thông tin sau:
- Một sản phẩm hiện có cần cập nhật. Để tìm hiểu cách tạo sản phẩm, hãy xem hướng dẫn Thêm và quản lý sản phẩm.
name
của nguồn dữ liệu mà dữ liệu đầu vào của sản phẩm thuộc về (ví dụ:accounts/12345/dataSources/67890
). Để tìm hiểu cách tìm thông tin này, hãy xem hướng dẫn Quản lý nguồn dữ liệu API để tải sản phẩm lên.
Cập nhật thông tin cụ thể về sản phẩm
Để thay đổi một vài thông tin chi tiết của một sản phẩm, chẳng hạn như giá hoặc tình trạng còn hàng, mà không cần gửi lại tất cả thông tin của sản phẩm đó, hãy sử dụng phương thức productInputs.patch
.
Bạn có thể chỉ định những trường mà bạn đang thay đổi trong tham số updateMask
. updateMask
là danh sách được phân tách bằng dấu phẩy gồm các trường bạn muốn cập nhật. Phương thức patch
hoạt động như sau:
- Các trường trong
updateMask
và nội dung: Các trường này được cập nhật bằng các giá trị mới. - Các trường trong
updateMask
nhưng không có trong nội dung: Các trường này sẽ bị xoá khỏi dữ liệu đầu vào của sản phẩm. - Các trường không có trong
updateMask
: Các trường này vẫn giữ nguyên. - Tham số
updateMask
bị bỏ qua: Tất cả các trường được cung cấp trong nội dung yêu cầu đều được cập nhật. Các trường không được cung cấp trong nội dung yêu cầu sẽ không bị xoá khỏi dữ liệu đầu vào của sản phẩm.
Dưới đây là ví dụ về dữ liệu sản phẩm trước khi cập nhật:
{
"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"
}
}
Ví dụ này cập nhật title
và availability
của một sản phẩm, đồng thời xoá imageLink
của sản phẩm đó. description
và price
không có trong updateMask
và sẽ không thay đổi.
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"
}
}
}
Lệnh gọi thành công sẽ trả về tài nguyên ProductInput
đã cập nhật. title
và availability
được cập nhật, còn imageLink
bị xoá vì nằm trong updateMask
nhưng không nằm trong nội dung yêu cầu. description
và price
vẫn không thay đổi vì chúng không có trong danh sách 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"
],
}
}
Các mẫu mã sau đây cho biết cách cập nhật một sản phẩm.
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"
}
}'
Cập nhật bằng thuộc tính tuỳ chỉnh
Bạn có thể cập nhật cả thuộc tính chuẩn và thuộc tính tuỳ chỉnh trong một lệnh gọi duy nhất. Để cập nhật một thuộc tính tuỳ chỉnh, hãy thêm tiền tố customAttributes
vào tên của thuộc tính đó trong updateMask
.
Ví dụ này thực hiện một số thao tác trong một yêu cầu:
- Cập nhật trực tiếp thuộc tính
title
chuẩn. - Cập nhật một thuộc tính tuỳ chỉnh hiện có (
myCustomAttrToBeUpdated
). - Chèn một thuộc tính tuỳ chỉnh mới (
myCustomAttrToBeInserted
). - Xoá một thuộc tính tuỳ chỉnh hiện có (
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"
}
]
}
Yêu cầu thành công sẽ trả về ProductInput
đã cập nhật, phản ánh tất cả các thay đổi được chỉ định.
Tìm hiểu thông tin cập nhật về thuộc tính tuỳ chỉnh
Bạn có thể dùng trường customAttributes
để cập nhật các thuộc tính mà bạn đã tự xác định. Các thuộc tính này không liên kết với quy cách tiêu chuẩn và sẽ được lưu trữ dưới dạng thuộc tính tuỳ chỉnh trên sản phẩm cuối cùng.
Cách xử lý nội dung cập nhật sản phẩm
Khi bạn gửi yêu cầu patch
, bản cập nhật sẽ được áp dụng cho dữ liệu ProductInput
cụ thể trước khi bất kỳ quy tắc nào được áp dụng. Điều này dẫn đến hành vi nhất quán giữa việc chèn và cập nhật sản phẩm.
Sau đây là cách chúng tôi xử lý nội dung cập nhật của bạn:
Cập nhật dữ liệu đầu vào: Yêu cầu
patch
của bạn sẽ sửa đổiProductInput
cụ thể được liên kết với nguồn dữ liệu mà bạn cung cấp.Xử lý và hợp nhất: Sau khi dữ liệu đầu vào được cập nhật, quá trình xử lý sẽ bắt đầu:
- Quy tắc nguồn cấp dữ liệu và nguồn dữ liệu bổ sung: Các quy tắc được định cấu hình trên nguồn chính của sản phẩm sẽ kết hợp
ProductInput
từ nguồn chính và nguồn bổ sung. Các quy tắc này có thể thay đổi thuộc tính hoặc tạo ra các thuộc tính mới. Để tìm hiểu thêm về cách thiết lập các quy tắc, hãy xem bài viết https://support.google.com/merchants/answer/14994083. - Các nguồn dữ liệu khác: Dữ liệu từ các nguồn khác (ví dụ: các điểm cải tiến tự động) cũng được hợp nhất với dữ liệu đầu vào của nguồn dữ liệu chính.
- Xác thực: Dữ liệu đã hợp nhất được xác thực theo Quy cách dữ liệu sản phẩm và chính sách mua sắm của Google.
- Quy tắc nguồn cấp dữ liệu và nguồn dữ liệu bổ sung: Các quy tắc được định cấu hình trên nguồn chính của sản phẩm sẽ kết hợp
Sản phẩm cuối cùng: Kết quả của quy trình này là tài nguyên
Product
đã xử lý cuối cùng có thể được trả về bằng cách sử dụngproducts.get
hoặcproducts.list
. Đây cũng là phiên bản sản phẩm xuất hiện trong Merchant Center và đủ điều kiện xuất hiện ở nhiều vị trí.
Do quy trình nhiều bước này, nên có một khoảng trễ (thường là vài phút) giữa thời điểm bạn gửi yêu cầu cập nhật và thời điểm các thay đổi được phản ánh trong tài nguyên Product
cuối cùng mà bạn có thể truy xuất bằng products.get
.
Ví dụ: Cập nhật một sản phẩm bằng một nguồn đầu vào chính
Đây là trường hợp sử dụng phổ biến nhất. Một sản phẩm có trong một nguồn dữ liệu chính duy nhất và bạn muốn cập nhật một số thuộc tính của sản phẩm đó.
- Trạng thái ban đầu: Một sản phẩm
en~US~SKU12345
tồn tại trong nguồn dữ liệu chính của bạn vớititle: "Classic T-Shirt"
vàprice: 15.99 USD
. - Yêu cầu cập nhật: Bạn gửi yêu cầu
patch
để cập nhậtprice
thành14.99 USD
và đặtavailability
thànhout of stock
. - Đang xử lý:
- Đã cập nhật
ProductInput
choSKU12345
.
- Đã cập nhật
- Sản phẩm cuối cùng:
Product
cuối cùng hiện cótitle: "Classic T-Shirt"
,price: 14.99 USD
vàavailability: "out of stock"
.
Ví dụ: Cập nhật một sản phẩm bằng dữ liệu và quy tắc bổ sung
Ví dụ này cho thấy cách quy tắc nguồn cấp dữ liệu có thể ảnh hưởng đến một bản cập nhật, khiến một số thay đổi được áp dụng trong khi những thay đổi khác bị ghi đè.
- Trạng thái ban đầu:
- Đầu vào chính:
en~US~SKU12345
cótitle: "Great T-Shirt"
vàdescription: "A great short-sleeve t-shirt."
. - Đầu vào bổ sung: Cùng một sản phẩm có một mục trong nguồn dữ liệu bổ sung có
title: "Awesome T-Shirt"
vàdescription: "An awesome short-sleeve t-shirt."
. - Quy tắc nguồn cấp dữ liệu: Một quy tắc được đặt để lấy
title
từ nguồn dữ liệu bổ sung. Không có quy tắc nào chodescription
. - Kết quả:
Product
đã xử lý cuối cùng cótitle: "Awesome T-Shirt"
vàdescription: "A great short-sleeve t-shirt."
.
- Đầu vào chính:
- Yêu cầu cập nhật: Bạn gửi yêu cầu
patch
để cập nhật nguồn dữ liệu chính, đặttitle
thành"Fantastic T-Shirt"
vàdescription
thành"A fantastic short-sleeve t-shirt."
. - Đang xử lý:
ProductInput
trong nguồn dữ liệu chính được cập nhật để cótitle: "Fantastic T-Shirt"
vàdescription: "A fantastic short-sleeve t-shirt."
.- Quy trình xử lý sẽ chạy.
- Đối với
title
, quy tắc nguồn cấp dữ liệu quy định rằng giá trị từ nguồn dữ liệu bổ sung (Awesome T-Shirt
) sẽ được ưu tiên, ghi đè nội dung cập nhật của bạn. - Đối với
description
, vì không có quy tắc ghi đè, nên giá trị đã cập nhật từ đầu vào chính (A fantastic short-sleeve t-shirt.
) sẽ được sử dụng.
- Sản phẩm cuối cùng: Tiêu đề của
Product
cuối cùng vẫn làAwesome T-Shirt
(nội dung cập nhật của bạn đã bị ghi đè), nhưng nội dung mô tả hiện làA fantastic short-sleeve t-shirt.
(nội dung cập nhật của bạn đã được áp dụng).
Chọn giữa nội dung cập nhật và nguồn dữ liệu bổ sung
Bạn có thể sửa đổi dữ liệu sản phẩm bằng cách sử dụng productinputs.patch
hoặc bằng cách chèn dữ liệu vào nguồn dữ liệu bổ sung. Lựa chọn tốt nhất phụ thuộc vào chiến lược quản lý dữ liệu của bạn.
Để tránh kết quả không dự đoán được, bạn không nên sử dụng cả productinputs.patch
và nguồn dữ liệu bổ sung để quản lý cùng một dữ liệu sản phẩm cho cùng một sản phẩm.
Sau đây là thông tin so sánh chi tiết:
Tính năng | productinputs.patch (Nội dung cập nhật) |
Nguồn dữ liệu bổ sung |
---|---|---|
Phù hợp nhất cho | Thay đổi nhanh chóng, thường xuyên và một phần đối với dữ liệu hiện có (ví dụ: giá, tình trạng còn hàng). | Phân lớp dữ liệu tách biệt một cách hợp lý, quản lý các thuộc tính khác nhau bằng các hệ thống khác nhau hoặc các chế độ ghi đè phức tạp dựa trên quy tắc. |
Cơ chế | Sửa đổi một ProductInput hiện có tại chỗ. |
Tạo một ProductInput mới, riêng biệt trong một nguồn dữ liệu bổ sung. |
Độ chi tiết của dữ liệu | Hoạt động trên các trường cụ thể của một ProductInput . |
Hoạt động trên toàn bộ ProductInput trong nguồn bổ sung. |
Tính liên tục | Các thay đổi sẽ được giữ nguyên cho đến khi cùng một ProductInput bị ghi đè bằng một insert đầy đủ hoặc một patch khác. |
Tính liên tục được kiểm soát bằng các quy tắc nguồn cấp dữ liệu. Có thể thay thế dữ liệu chính vô thời hạn nếu các quy tắc ưu tiên dữ liệu đó. |
Tương tác với quy tắc | Có thể sử dụng mà không cần quy tắc nguồn cấp dữ liệu vì quy tắc này cập nhật nguồn dữ liệu hiện có và ProductInput . |
Bạn phải thiết lập rõ ràng một quy tắc trên nguồn chính để liên kết nguồn bổ sung. |
Thiết lập nguồn dữ liệu | Hoạt động trên một nguồn dữ liệu hiện có. Bạn không cần thêm nguồn mới. | Bạn phải tạo và quản lý các nguồn dữ liệu bổ sung riêng biệt, đồng thời liên kết các nguồn dữ liệu đó bằng quy tắc nguồn cấp dữ liệu. |