0

一連の基準に基づいて、発行中にサイトコア アイテムに DMS プロファイル カードを添付する必要があります。

それ、どうやったら出来るの?

4

1 に答える 1

1

元の回答を削除し、代わりにこれを投稿しました。

これは、パイプラインに追加されるプロセッサである、ラフで準備ができており、完全にテストされていないクラスです。publishItem(「Sitecore ASP.NET CMS を使用してアイテムのパブリッシュを傍受する」を参照してください)

これは、同様の結果を達成する Sitecore Powershell プロジェクトにあるコードに基づいています: Console / PowerShellIntegrations / Commandlets / Analytics / SetAnalyticsProfileCardCommand.cs

使用するプロファイル カードを選択するロジックを追加する必要があることに注意してください。

using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Publishing.Pipelines.PublishItem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace SC7Test.Business.Processors
{
    class SetProfileCard : PublishItemProcessor
    {
        public override void Process(PublishItemContext context)
        {
            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var publishItem = db.GetItem(context.ItemId);

            // Add your logic here.
            var profileCardItem = db.GetItem("One of several profile card item ID's based on your selection logic");
            var profileCardValue = profileCardItem["Profile Card Value"];

            var doc = new XmlDocument();
            doc.LoadXml(profileCardValue);

            if (doc.DocumentElement != null && doc.GetElementsByTagName("profile").Count > 0 &&
                doc.GetElementsByTagName("profile")[0] != null)
            {

                XmlNode xmlNode = doc.GetElementsByTagName("profile")[0];

                if (xmlNode.Attributes != null)
                {
                    XmlAttribute presetAttribute = xmlNode.Attributes["presets"] ?? doc.CreateAttribute("presets");

                    presetAttribute.Value = profileCardItem.Name.ToLower() + "|100||";
                    xmlNode.Attributes.Append(presetAttribute);
                }         
            }

            using (new EditContext(publishItem, false, false))
            {
                publishItem["__Tracking"] = doc.InnerXml;
            }

        }
    }
}
于 2014-05-26T18:11:40.420 に答える