Context

We learned in section Creating your first mappings that one of its tasks is to tell EC what base-feature that holds the configuration for some entity. Figure 1 shows the most basic mapping:

 

Figure 1: The context mapping for the ‘Product’-entity on channel “My Channel”

This basically tells, that if someone fires a GetProducts-request on channel ‘My Channel’ we will find these products in a feature named Product. This feature must be a selectable feature and will 99% of the time hold a configuration in Perfion.

Separated by / (front slash) you can give EC more information about this Context. Consider the mapping in Figure 2:

Figure 2: Now the “from”-value consists of three parts: The feature name, a view and finally a search

The two new parts are containing a name of a system view (See Perfion API for more information on what a system view is). In versions before version 4.5 2019 R1, this view is not really used by EC. In 4.5 2019 R1 and later, the view is used by the *-mapping to be able to map all features in a standard view by creating a single mapping. See more on *-mapping.

In Perfion v. 4.5.36 is the capability to write a “-“ (a minus or dash) as the view name telling the EC API that it should omit selecting any data from any system view. In some installations, that is can give a performance improvement. I.e. writing for example “Product/-/MyProductSearch“ or simply “Product/-“ as from-value for the Context-mapping will make EC API stop selecting from any System view. Doing that will effectively disable the *-mapping.

The 3rd part of the base-value of the context node is the name of a search that somehow limits what products are to be fetched by EC. If you, for example, have some products in “Draft”-state and some in “Production” you might be interested only to have “Production”-products fetched by UC. This is done by specifying the name of the Search-feature that make sure only products marked “Production” is fetched. In Figure 2 this search-feature is named MyProductSearch.

One way to create such a search is as follows:

First let us create a feature holding the value for each product that determines whether they are “Draft” or “Production”. That is done by creating a string feature named ProductState as can be seen in Figure 3.

 

Make sure to assign this feature to the configuration of Product and in Feature Data allow it to hold either of the two values “Draft” and “Production” (not shown).

Now assign a value for “ProductState” to all your products as shown for three products in Figure 4.

An easy way to create a query fetching only products in production is to right click on any cell having the value “Production” and click “Filter by value”. This filters everything else away. The exact filter query can be obtained by clicking the filter-icon shown in below.

In the Filter Editor, switch to “Advanced Mode” and copy the Perfion Query onto the clipboard.

With this query on the clipboard, go to “Feature Data” and create a value for the feature ECommerceSearches. This is actually a feature created as part of auto creating features for EC (described in chapter Auto creating Features). This value must be named the same as the 3rd part of the context-node, in this case it MyProductSearch (See Figure 2).

Now right-click on this newly created value and pick “Edit Query…” from the menu as shown in Figure 7.

In the Query-window that appears, paste in the copied query. This has been done in Figure 8:

From here you only need to click “OK”.

To test that filter is working, go to the “API Query Tool”-window and ask for, say, the 3 products we tagged up in Figure 18: The ones numbered DFGR1181, DFGR1280 and DFGR1686, respective. If everything works as expected, only the first two products should be returned, since the final one, DFGR1686, is in Draft-mode.

This request does indeed that:

<Execute method="GetProducts" refreshconfiguration="true">   <Parameter id="Channel" value="My Channel" />   <Parameter id="ExcludeMappings" value="*" />   <Parameter id="Keys">     <Value>DFGR1181</Value>     <Value>DFGR1280</Value>     <Value>DFGR1686</Value>   </Parameter>  </Execute>

And the result is:

<Response>   <Result>     <Channel name="My Channel">       <TotalCount>2</TotalCount>       <Products>         <Product id="622" ecommerceproduct="DFGR1280" />         <Product id="623" ecommerceproduct="DFGR1181" />       </Products>     </Channel>   </Result> </Response>

Notice that, as expected, EC only returns two products.

If you get an error message from EC, typically saying that some Perfion Query went wrong, check the naming and casing of the feature names. It is, unfortunately, quite easy to get these wrong.