<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by The Ensconced Armamentarium</title> <link>https://world.optimizely.com/blogs/The-Ensconced-Armamentarium/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>Entry SortOrder Property, Where Are You?</title>            <link>https://world.optimizely.com/blogs/The-Ensconced-Armamentarium/Dates/2012/6/Entry-SortOrder-Property-Where-Are-You/</link>            <description>&lt;p&gt;An EPiServer partner developer asked a question today about the entry sort order property. He could find the interface to affect changes on catalog entry sort order values in Commerce Manager, but couldn’t intuitively find the API hooks within the &lt;em&gt;Mediachase.Commerce.dll&lt;/em&gt; assembly. I thought this would be a good topic for an initial blog post.&lt;/p&gt;  &lt;p&gt;The sort property for a catalog entry is actually manipulated via a different strongly typed dataset object than the &lt;font face=&quot;Courier New&quot;&gt;CatalogEntryDto&lt;/font&gt;, namely the &lt;font face=&quot;Courier New&quot;&gt;CatalogRelationDto&lt;/font&gt;. In this &lt;a title=&quot;Data Transfer Object&quot; href=&quot;http://en.wikipedia.org/wiki/Data_Transfer_Object&quot; target=&quot;_blank&quot;&gt;DTO&lt;/a&gt;, we use the &lt;font face=&quot;Courier New&quot;&gt;NodeEntryRelation&lt;/font&gt; datatable and find the desired records based on a unique combination of CatalogId, CatalogNodeId, and CatalogEntryId. Once we have a reference to the row we can affect the &lt;font face=&quot;Courier New&quot;&gt;SortOrder&lt;/font&gt; property and then persist changes as needed.&lt;/p&gt;  &lt;p&gt;To get this dataset object, you can use one of the three &lt;font face=&quot;Courier New&quot;&gt;GetCatalogRelationDto()&lt;/font&gt; method overloads from the &lt;font face=&quot;Courier New&quot;&gt;CatalogContext&lt;/font&gt; singleton. The easiest one in this case is the one that takes an integer entry id. &lt;/p&gt;  &lt;p&gt;In this method, execution is passed to the &lt;font face=&quot;Courier New&quot;&gt;CatalogRelationManager&lt;/font&gt;, then down to the &lt;font face=&quot;Courier New&quot;&gt;CatalogRelationAdmin&lt;/font&gt; where the stored procedure &lt;font face=&quot;Courier New&quot;&gt;[ecf_CatalogRelationByChildEntryId]&lt;/font&gt; is executed. Query results are mapped to three of &lt;font face=&quot;Courier New&quot;&gt;CatalogRelationDto&lt;/font&gt;&#39;s datatables: CatalogNodeRelation, CatalogEntryRelation, NodeEntryRelation. At this point you can iterate through the strongly typed (CatalogRelationDto.NodeEntryRelationRow) datarows of the NodeEntryRelation datatable.&lt;/p&gt;  &lt;p&gt;Below is a trivial example. (Apologies if the blog theme horizontally truncates the syntax highlighted portion below.)&lt;/p&gt;  &lt;div class=&quot;csharpcode&quot;&gt;   &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;rem&quot;&gt;// set parameters&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; catalogEntryId = 7;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; newSortOrderValue = 10;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;&amp;#160;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;CatalogRelationDto catalogRelationDto = &lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;  CatalogContext.Current.GetCatalogRelationDto();&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;&amp;#160;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   8:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt; (CatalogRelationDto.NodeEntryRelationRow row &lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   9:  &lt;/span&gt;  &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; catalogRelationDto.NodeEntryRelation)&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  10:  &lt;/span&gt;{&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  11:  &lt;/span&gt;  &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (row.RowState != DataRowState.Deleted &lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  12:  &lt;/span&gt;    &amp;amp;&amp;amp; row.CatalogEntryId == catalogEntryId)&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  13:  &lt;/span&gt;  {&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  14:  &lt;/span&gt;    &lt;span class=&quot;rem&quot;&gt;// set the value of our NodeEntryRelationRow instance&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  15:  &lt;/span&gt;    row.SortOrder = newSortOrderValue;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  16:  &lt;/span&gt;  }&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  17:  &lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Finally, to persist those datarow changes you can use the &lt;font face=&quot;Courier New&quot;&gt;SaveCatalogRelationDto()&lt;/font&gt; method from the &lt;font face=&quot;Courier New&quot;&gt;CatalogContext&lt;/font&gt; singleton. The easiest one in this case is the one that takes an integer entry id.&lt;/p&gt;

&lt;div class=&quot;csharpcode&quot;&gt;
  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;rem&quot;&gt;// persist changes&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (catalogRelationDto.HasChanges())&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;{&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;  CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);&lt;/code&gt;&lt;/pre&gt;

  &lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;style type=&quot;text/css&quot;&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &quot;Courier New&quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;In this method, execution is again passed to the &lt;font face=&quot;Courier New&quot;&gt;CatalogRelationManager&lt;/font&gt;&lt;font face=&quot;Arial&quot;&gt; which raises some pre and post processing pipeline events around the save operation and clears old cached records. The save operation is handled by &lt;/font&gt;a &lt;font face=&quot;Courier New&quot;&gt;CatalogRelationAdmin&lt;/font&gt; instance where the &lt;font face=&quot;Courier New&quot;&gt;DataHelper&lt;/font&gt; class is used to persist the dataset.&lt;/p&gt;

&lt;p&gt;When looking at the catalog API, you’ll come across this pattern frequently. There is a singleton class funneling calls through a single instance of &lt;font face=&quot;Courier New&quot;&gt;ICatalogSystem &lt;/font&gt;&lt;font face=&quot;Arial&quot;&gt;which contains the underlying concrete definition based on configuration. From there methods usually go through a manager class where other framework tasks can be injected, such as caching objects and raising events. Finally, the baton is passed to an admin class where the intended work is done. You may also run head first into the &lt;em&gt;Mediachase.MetaDataPlus.dll&lt;/em&gt; assembly, but that is a blog post for another day. Along the way there are strongly typed datasets for ease of programming that seemingly map directly against the database schema and database objects, as well as C# &lt;/font&gt;&lt;a title=&quot;Plain Old CLR Object&quot; href=&quot;http://en.wikipedia.org/wiki/Plain_Old_CLR_Object&quot; target=&quot;_blank&quot;&gt;POCO&lt;/a&gt; objects to abstract away the details. &lt;/p&gt;

&lt;p&gt;We should see these libraries, and the layers that allow presentation, integration, and other functions above improve and innovate in future versions, can’t wait!&lt;/p&gt;</description>            <guid>https://world.optimizely.com/blogs/The-Ensconced-Armamentarium/Dates/2012/6/Entry-SortOrder-Property-Where-Are-You/</guid>            <pubDate>Thu, 14 Jun 2012 18:42:00 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>