製品ギャラリー - アセットを追加してプロパティバッグに入れる
日本語翻訳に関する免責事項
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
次のコードを使用して、アセットを追加し、プロパティ バッグに入れます。
using System.Linq; using System.Threading.Tasks; using System.Collections.Generic; using Stylelabs.M.Sdk; using Stylelabs.M.Sdk.Contracts.Base; string executionId = string.Empty; LogScriptCalled(Context, MClient); //Get the Product ID var productId = Context.TargetId.Value; //Add the executionId to Property Bag Context.PropertyBag.Add($"{productId}-executionId", executionId); //Get the Product entity IEntity product = Context.Target as IEntity; if (product == null) { LogInfo(Context, MClient, $"The product entity is null"); return; } //Get the change set (newly added assets) var changeSet = Context.ChangeTracker.GetChangeSet(); var relationChanges = changeSet.RelationChanges; var productGalleryRelationChange = relationChanges.FirstOrDefault(x => x.Name == "ProductToGalleryAsset"); var addedAssetIds = productGalleryRelationChange.NewValues; if (addedAssetIds.Count <= 0) { LogInfo(Context, MClient, $"There are no assets added to the Product Gallery"); return; } var strAddedAssetIds = string.Join(",", addedAssetIds.ToArray()); LogInfo(Context, MClient, $"Product Gallery changed asset Ids: { strAddedAssetIds }"); //Add the asset IDs to Property Bag Context.PropertyBag.Add($"{productId}-{executionId}", strAddedAssetIds); #region Helpers void LogScriptCalled(IActionScriptContext context, IMClient client) { executionId = Guid.NewGuid().ToString("N").Substring(0, 6); LogInfo(context, client, $"{executionId}: Execution started. Context: {context}"); } void LogDebug(IActionScriptContext context, IMClient client, string message) { client.Logger.Debug(LogPrefix(context) + message); } void LogInfo(IActionScriptContext context, IMClient client, string message) { client.Logger.Info(LogPrefix(context) + message); } string LogPrefix(IActionScriptContext context) { return $"{ (context?.TargetId != null ? context.TargetId.Value.ToString() : string.Empty)} | "; } #endregion