自訂自動比對
如果預設的自動比對策略(OOTB自動比對)不符合您的特定業務需求,請選取自訂比對選項。 此選項支援使用Adobe Developer App Builder來開發自訂符合器應用程式,以處理複雜的符合邏輯,或來自無法將中繼資料填入AEM Assets的協力廠商系統的資產。
設定自訂自動比對
-
從Commerce管理員中,導覽至「Store >設定> ADOBE SERVICES > AEM Assets Integration」。
-
選取 Custom Matcher 作為比對規則。
-
當您選取此比對規則時,Admin會顯示其他欄位,以設定 端點 和自訂比對邏輯所需的驗證引數。
workspace.json
Adobe I/O Workspace Configuration欄位透過匯入App Builder workspace.json設定檔,提供簡化的自訂比對器設定方式。
您可以從workspace.jsonAdobe Developer Console下載檔案。 此檔案包含您App Builder工作區的所有認證和設定詳細資料。
workspace.json| code language-json |
|---|
|
- 將您的
workspace.json檔案從App Builder專案拖放至 Adobe I/O Workspace Configuration 欄位。 或者,您可以按一下瀏覽並選取檔案。
-
系統自動:
- 驗證JSON結構
- 擷取及填入OAuth認證
- 擷取工作區的可用執行階段動作
- 填入 Product to Asset URL 和 Asset to Product URL 欄位的下拉式清單選項
-
從每個流程的下拉式選單中選取適當的執行階段動作。
-
按一下Save Config。
自訂比對器API端點
當您使用App Builder建置自訂符合專案應用程式時,應用程式必須公開下列端點:
- App Builder資產至產品URL端點
- App Builder產品至資產URL端點
App Builder資產至產品URL端點
此端點會擷取與指定資產相關聯的SKU清單:
使用範例
const { Core } = require('@adobe/aio-sdk')
async function main(params) {
// Build your own matching logic here to return the products that map to the assetId
// var productMatches = [];
// params.assetId
// params.eventData.assetMetadata['commerce:isCommerce']
// params.eventData.assetMetadata['commerce:skus'][i]
// params.eventData.assetMetadata['commerce:roles']
// params.eventData.assetMetadata['commerce:positions'][i]
// ...
// End of your matching logic
// Set skip to true if the mapping hasn't changed
const skipSync = false;
return {
statusCode: 200,
body: {
asset_id: params.assetId,
product_matches: [
{
product_sku: "<YOUR-SKU-HERE>",
asset_roles: ["thumbnail", "image", "swatch_image", "small_image"],
asset_position: 1
}
],
skip: skipSync
}
};
}
exports.main = main;
要求
POST https://your-app-builder-url/api/v1/web/app-builder-external-rule/asset-to-product
assetIdeventData回應
{
"asset_id": "{ASSET_ID}",
"product_matches": [
{
"product_sku": "{PRODUCT_SKU_1}",
"asset_roles": ["thumbnail", "image"]
},
{
"product_sku": "{PRODUCT_SKU_2}",
"asset_roles": ["thumbnail"]
}
],
"skip": false
}
asset_idproduct_matchesApp Builder產品至資產URL端點
此端點會擷取與指定SKU相關聯的資產清單:
使用範例
const { Core } = require('@adobe/aio-sdk')
async function main(params) {
// return asset matches for a product
// Build your own matching logic here to return the assets that map to the productSku
// var assetMatches = [];
// params.productSku
// ...
// End of your matching logic
// Set skip to true if the mapping hasn't changed
const skipSync = false;
return {
statusCode: 200,
body: {
product_sku: params.productSku,
asset_matches: [
{
asset_id: "<YOUR-ASSET-ID-HERE>", // urn:aaid:aem:1aa1d5i2-17h8-40a7-a228-e3ur588deee1
asset_roles: ["thumbnail", "image", "swatch_image", "small_image"],
asset_format: "image", // can be "image" or "video"
asset_position: 1
}
],
skip: skipSync
}
};
}
exports.main = main;
要求
POST https://your-app-builder-url/api/v1/web/app-builder-external-rule/product-to-asset
productSKUeventData回應
{
"product_sku": "{PRODUCT_SKU}",
"asset_matches": [
{
"asset_id": "{ASSET_ID_1}",
"asset_roles": ["thumbnail", "image"],
"asset_position": 1,
"asset_format": "image"
},
{
"asset_id": "{ASSET_ID_2}",
"asset_roles": ["thumbnail"],
"asset_position": 2,
"asset_format": "image"
}
],
"skip": false
}
product_skuasset_matchesasset_matches引數包含下列屬性:
asset_idasset_formatimage和video。asset_position略過同步處理
skip引數可讓您的自訂比對器略過特定資產或產品的同步處理。
當您的App Builder應用程式在回應中傳回"skip": true時,規則引擎不會傳送該資產或產品的更新或移除API請求給Commerce。 此最佳化可減少不必要的API呼叫並改善效能。