[{"data":1,"prerenderedAt":309},["ShallowReactive",2],{"article-\u002Fblog\u002Fsap-commerce-intercepting-populators":3},{"id":4,"title":5,"author":6,"body":7,"description":297,"extension":298,"intro":299,"meta":300,"name":299,"navigation":66,"path":302,"pubDate":303,"role":299,"seo":304,"stem":305,"tags":306,"__hash__":308},"content\u002Fblog\u002Fsap-commerce-intercepting-populators.md","SAP Commerce: Intercepting Populated Item Models Before Persistence","Danny Krämer",{"type":8,"value":9,"toc":295},"minimark",[10,21,24,27,38,41,92,95,140,147,291],[11,12,13,14],"p",{},"Let’s say you have written a new CMS Component and want to intercept the populated item model before persisting it to the database to make some transformations on its data. There is a pretty straightforward explanation on how to do this on the SAP Help ",[15,16,20],"a",{"href":17,"rel":18},"https:\u002F\u002Fhelp.sap.com\u002Fdocs\u002FSAP_COMMERCE\u002F9d346683b0084da2938be8a285c0c27a\u002Fcf0445b16a4f44d9844381a34572d7b8.html",[19],"nofollow","Extending the CMS Item API",[11,22,23],{},"Under \"Configuring the New Populator\" the explanation gets a bit confusing. So here is how it actually works:",[11,25,26],{},"After you created your populator, you create the bean for it:",[28,29,34],"pre",{"className":30,"code":32,"language":33},[31],"language-text","\u003Cbean id=\"customItemContentPopulator\" class=\"path.to.populator.CustomItemContentPopulator\"\u002F>\n","text",[35,36,32],"code",{"__ignoreMap":37},"",[11,39,40],{},"Then the article says the following:",[42,43,44,47],"blockquote",{},[11,45,46],{},"You must then map your Custom Item Type to the new populator to make it visible to the CMS Item Type Populator Provider. The following code shows the configuration for the new populator:",[28,48,52],{"className":49,"code":50,"language":51,"meta":37,"style":37},"language-XML shiki shiki-themes github-dark github-light","\u003Cbean id=\"customItemContentPopulator\" class=\"path.to.populator.CustomItemContentPopulator\"\u002F>\n\n\u003Cbean depends-on=\"cmsContentItemTypePopulatorsMap\" parent=\"mapMergeDirective\">\n        \u003Cproperty name=\"key\" value=\"CustomItem\"\u002F>\n        \u003Cproperty name=\"value\" ref=\"customItemContentPopulator\"\u002F>\n\u003C\u002Fbean>\n","XML",[35,53,54,61,68,74,80,86],{"__ignoreMap":37},[55,56,59],"span",{"class":57,"line":58},"line",1,[55,60,32],{},[55,62,64],{"class":57,"line":63},2,[55,65,67],{"emptyLinePlaceholder":66},true,"\n",[55,69,71],{"class":57,"line":70},3,[55,72,73],{},"\u003Cbean depends-on=\"cmsContentItemTypePopulatorsMap\" parent=\"mapMergeDirective\">\n",[55,75,77],{"class":57,"line":76},4,[55,78,79],{},"        \u003Cproperty name=\"key\" value=\"CustomItem\"\u002F>\n",[55,81,83],{"class":57,"line":82},5,[55,84,85],{},"        \u003Cproperty name=\"value\" ref=\"customItemContentPopulator\"\u002F>\n",[55,87,89],{"class":57,"line":88},6,[55,90,91],{},"\u003C\u002Fbean>\n",[11,93,94],{},"If you do this, only your populator will be called for the component. That means other populators, like the one that will handle the saving of the content slot where the component is contained, will not be called. Often that is, of course, not what we want. The documentation then states the following:",[42,96,97,100],{},[11,98,99],{},"If you want to apply many populators to the same CMS item type, you can use a composite populator to configure the new populator as follows:",[28,101,103],{"className":49,"code":102,"language":51,"meta":37,"style":37},"\u003Cbean id=\"cmsContentItemTypePopulatorsMap\" parent=\"cmsCompositePopulator\">\n \u003Cproperty name=\"populators\">\n     \u003Clist merge=\"true\">\n       \u003Cbean id=\"customItemContentPopulator\" class=\"path.to.populator.CustomItemContentPopulator\"\u002F>\n     \u003C\u002Flist>\n  \u003C\u002Fproperty>\n\u003C\u002Fbean> \n",[35,104,105,110,115,120,125,130,135],{"__ignoreMap":37},[55,106,107],{"class":57,"line":58},[55,108,109],{},"\u003Cbean id=\"cmsContentItemTypePopulatorsMap\" parent=\"cmsCompositePopulator\">\n",[55,111,112],{"class":57,"line":63},[55,113,114],{}," \u003Cproperty name=\"populators\">\n",[55,116,117],{"class":57,"line":70},[55,118,119],{},"     \u003Clist merge=\"true\">\n",[55,121,122],{"class":57,"line":76},[55,123,124],{},"       \u003Cbean id=\"customItemContentPopulator\" class=\"path.to.populator.CustomItemContentPopulator\"\u002F>\n",[55,126,127],{"class":57,"line":82},[55,128,129],{},"     \u003C\u002Flist>\n",[55,131,132],{"class":57,"line":88},[55,133,134],{},"  \u003C\u002Fproperty>\n",[55,136,138],{"class":57,"line":137},7,[55,139,91],{},[11,141,142,143,146],{},"That is fine as far as it goes, but of course you have to add the other populators as well, or you will only have one populator in your map again. Also, you have to add your populators map to the ",[35,144,145],{},"cmsContentItemTypePopulatorsMap",". So your config should look something like this:",[28,148,150],{"className":49,"code":149,"language":51,"meta":37,"style":37},"\u003Calias name=\"dsCustomComponentContentPopulator\" alias=\"defaultCustomComponentContentPopulator\"\u002F>\n    \u003Cbean id=\"customComponentContentPopulator\" class=\"de.custom.components.populators.CustomComponentContentPopulator\" \u002F>\n\n    \u003Cbean id=\"cmsCustomComponentItemTypePopulatorsMap\" parent=\"cmsCompositePopulator\">\n        \u003Cproperty name=\"populators\">\n            \u003Clist merge=\"true\">\n                \u003Cref bean=\"defaultCustomComponentContentPopulator\"\u002F>\n                \u003Cbean class=\"de.hybris.platform.cmsfacades.cmsitems.populators.AbstractCMSComponentContentPopulator\">\n                    \u003Cproperty name=\"contentSlotAdminService\" ref=\"cmsAdminContentSlotService\"\u002F>\n                    \u003Cproperty name=\"uniqueItemIdentifierService\" ref=\"cmsUniqueItemIdentifierService\"\u002F>\n                    \u003Cproperty name=\"validationDtoFactory\" ref=\"validationDtoFactory\"\u002F>\n                    \u003Cproperty name=\"componentTypeAllowedForContentSlotPredicate\" ref=\"componentTypeAllowedForContentSlotPredicate\"\u002F>\n                    \u003Cproperty name=\"relationBetweenComponentsService\" ref=\"relationBetweenComponentsService\"\u002F>\n                \u003C\u002Fbean>\n                \u003Cbean class=\"de.hybris.platform.cmsfacades.cmsitems.populators.CMSItemLinkToggleDataToModelPopulator\">\n                    \u003Cproperty name=\"cmsModelContainsLinkTogglePredicate\" ref=\"cmsModelContainsLinkTogglePredicate\"\u002F>\n                \u003C\u002Fbean>\n            \u003C\u002Flist>\n        \u003C\u002Fproperty>\n    \u003C\u002Fbean>\n\n    \u003Cbean depends-on=\"cmsContentItemTypePopulatorsMap\" parent=\"mapMergeDirective\">\n        \u003Cproperty name=\"key\" value=\"CustomComponent\"\u002F>\n        \u003Cproperty name=\"value\" ref=\"customComponentItemTypePopulatorsMap\"\u002F>\n    \u003C\u002Fbean>\n",[35,151,152,157,162,166,171,176,181,186,192,198,204,210,216,222,228,234,240,245,251,257,263,268,274,280,286],{"__ignoreMap":37},[55,153,154],{"class":57,"line":58},[55,155,156],{},"\u003Calias name=\"dsCustomComponentContentPopulator\" alias=\"defaultCustomComponentContentPopulator\"\u002F>\n",[55,158,159],{"class":57,"line":63},[55,160,161],{},"    \u003Cbean id=\"customComponentContentPopulator\" class=\"de.custom.components.populators.CustomComponentContentPopulator\" \u002F>\n",[55,163,164],{"class":57,"line":70},[55,165,67],{"emptyLinePlaceholder":66},[55,167,168],{"class":57,"line":76},[55,169,170],{},"    \u003Cbean id=\"cmsCustomComponentItemTypePopulatorsMap\" parent=\"cmsCompositePopulator\">\n",[55,172,173],{"class":57,"line":82},[55,174,175],{},"        \u003Cproperty name=\"populators\">\n",[55,177,178],{"class":57,"line":88},[55,179,180],{},"            \u003Clist merge=\"true\">\n",[55,182,183],{"class":57,"line":137},[55,184,185],{},"                \u003Cref bean=\"defaultCustomComponentContentPopulator\"\u002F>\n",[55,187,189],{"class":57,"line":188},8,[55,190,191],{},"                \u003Cbean class=\"de.hybris.platform.cmsfacades.cmsitems.populators.AbstractCMSComponentContentPopulator\">\n",[55,193,195],{"class":57,"line":194},9,[55,196,197],{},"                    \u003Cproperty name=\"contentSlotAdminService\" ref=\"cmsAdminContentSlotService\"\u002F>\n",[55,199,201],{"class":57,"line":200},10,[55,202,203],{},"                    \u003Cproperty name=\"uniqueItemIdentifierService\" ref=\"cmsUniqueItemIdentifierService\"\u002F>\n",[55,205,207],{"class":57,"line":206},11,[55,208,209],{},"                    \u003Cproperty name=\"validationDtoFactory\" ref=\"validationDtoFactory\"\u002F>\n",[55,211,213],{"class":57,"line":212},12,[55,214,215],{},"                    \u003Cproperty name=\"componentTypeAllowedForContentSlotPredicate\" ref=\"componentTypeAllowedForContentSlotPredicate\"\u002F>\n",[55,217,219],{"class":57,"line":218},13,[55,220,221],{},"                    \u003Cproperty name=\"relationBetweenComponentsService\" ref=\"relationBetweenComponentsService\"\u002F>\n",[55,223,225],{"class":57,"line":224},14,[55,226,227],{},"                \u003C\u002Fbean>\n",[55,229,231],{"class":57,"line":230},15,[55,232,233],{},"                \u003Cbean class=\"de.hybris.platform.cmsfacades.cmsitems.populators.CMSItemLinkToggleDataToModelPopulator\">\n",[55,235,237],{"class":57,"line":236},16,[55,238,239],{},"                    \u003Cproperty name=\"cmsModelContainsLinkTogglePredicate\" ref=\"cmsModelContainsLinkTogglePredicate\"\u002F>\n",[55,241,243],{"class":57,"line":242},17,[55,244,227],{},[55,246,248],{"class":57,"line":247},18,[55,249,250],{},"            \u003C\u002Flist>\n",[55,252,254],{"class":57,"line":253},19,[55,255,256],{},"        \u003C\u002Fproperty>\n",[55,258,260],{"class":57,"line":259},20,[55,261,262],{},"    \u003C\u002Fbean>\n",[55,264,266],{"class":57,"line":265},21,[55,267,67],{"emptyLinePlaceholder":66},[55,269,271],{"class":57,"line":270},22,[55,272,273],{},"    \u003Cbean depends-on=\"cmsContentItemTypePopulatorsMap\" parent=\"mapMergeDirective\">\n",[55,275,277],{"class":57,"line":276},23,[55,278,279],{},"        \u003Cproperty name=\"key\" value=\"CustomComponent\"\u002F>\n",[55,281,283],{"class":57,"line":282},24,[55,284,285],{},"        \u003Cproperty name=\"value\" ref=\"customComponentItemTypePopulatorsMap\"\u002F>\n",[55,287,289],{"class":57,"line":288},25,[55,290,262],{},[292,293,294],"style",{},"html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":37,"searchDepth":63,"depth":63,"links":296},[],"To configure a new CMS component populator in SAP Commerce and ensure it works alongside other populators, you need to create the populator, define it as a bean, and include it in a composite populator map to apply multiple populators to the same CMS item type.","md",null,{"image":301},{"url":37,"alt":37},"\u002Fblog\u002Fsap-commerce-intercepting-populators","2024-09-11",{"title":5,"description":297},"blog\u002Fsap-commerce-intercepting-populators",[307],"sap commerce","T6mSAVu3X1dMRvMhbbvnztwXRP9AbtSWV9NoQn5i7q0",1775933922426]