Share via


Commerce Foundation ContentSelector CommerceQuery

Use this query to run the Commerce Server ContentSelector object’s GetContent() method and return the selected content as a list of advertisement commerce entities.

In order to configure Advertisements such as that they are only visible in specific channels, displayable Commerce Server discounts and advertisements must contain a targeting expression that utilizes the TargetingContext.channel property using a require action. This can be done using the Commerce Server Marketing Manager application. If no such targeting expressions are configured, the displayable discounts and advertisements will be visible on all channels.

Syntax

        CommerceEntity targetingContext = new CommerceEntity("TargetingContext");
            targetingContext.Properties["Channel"] = "Default";

            CommerceEntity searchModel = new CommerceEntity("ContentSelector");
            searchModel.Properties["CampaignHistory"] = HttpContext.Current.Request.Cookies["CampaignHistory"].Value.Split(',');
            searchModel.Properties["ContextNames"] = new string[] { "Advertising" };
            searchModel.Properties["PageGroup"] = "All";
            searchModel.Properties["Size"] = "Banner";
            searchModel.Properties["UserId"] = "{1C6AD3D6-0AC3-437c-9161-79E49ADCD9C9}";
            searchModel.Properties["CatalogName"] = "Adventure Works Catalog";
            searchModel.Properties["ProductId"] = "AW200-12";
            searchModel.Properties["TargetingContext"] = new CommerceRelationship(targetingContext);

            CommerceQuery<ContentSelector> query = new CommerceQuery<ContentSelector>();
            query.SearchCriteria.NumberOfItemsToReturn = 1;
            query.SearchCriteria.Model.TargetingContext = new CommerceRelationship(targetingContext.ToCommerceEntity());

            CommerceResponse response = SiteContext.ProcessRequest(query.ToRequest());
            CommerceQueryOperationResponse queryResponse = (CommerceQueryOperationResponse)response.OperationResponses[0];
            CommerceEntity contentSelector = queryResponse.CommerceEntities[0];

            CommerceRelationshipList selectedAdvertisementList = (CommerceRelationshipList)contentSelector.Properties["Advertisements"];
            string selectedAdContent = (string)selectedAdvertisementList[0].Target.Properties["Content"];

            HttpCookie newCampaignHistory = new HttpCookie(
                "CampaignHistory",
                string.Join(",", (string[])contentSelector.Properties["CampaignHistory"]));
            HttpContext.Current.Response.Cookies.Add(newCampaignHistory);

Operation Sequence Components

Operation Sequence Component

Description

ContentSelectorLoader

Gets the correct Commerce Server ContentSelector object from the ContentSelectionContextCollectionProvider and populates it with all data from ContentSelector commerce entity provided in the search criteria. In addition, if a property named "channel" exists on the TargetingContext profile, you need to populate this property so that the Content Selection Framework (CSF) pipeline can target the current channel.

ContentSelectorExecutor

Calls ContentSelector.GetContent() and populates the operation response based on the results. The response ContentSelector commerce entity must contain the updated PageHistory and CampaignHistory as calculated by the CSF pipeline.

ContentSelectorAdvertisementProcessor

Loads all advertisement objects that are related to the parent ContentSelector object.

Related Operation

Description

CommerceQueryRelatedItem<Advertisements>

Retrieves the advertisements that are related to a ContentSelector as part of a CommerceQuery<ContentSelector> operation.

Valid Query Operations

Property

Description

FirstItemIndex

If this is anything other than null or zero, the system throws an exception.

ReturnTotalItemCount

Supported.

Model

Required. This have the model name ContentSelector. The following table lists the ContentSelector properties that the search supports:

PropertyUsage
ContextNamesRequired.
UserIdOptional.
AddressIdOptional.
CatalogNameOptional.
ProductIdOptional.
VariantIdOptional.
TargetingContextOptional.
PageGroupOptional (defaults to "All").
SizeOptional.
ContentVarietyOptional.
PageHistoryOptional.
CampaignHistoryOptional.

Return Value

This query returns a CommerceQueryOperationResponse containing one ContentSelector commerce entity whose Advertisements relationship list contains the targeted advertisement selected.

Exceptions

Microsoft Multi-Channel Commerce Foundation can throw the following exception during this operation:

  • FaultException<GeneralOperationFault>

Remarks

This operation supports the CommerceModelSearch search criteria, and the CommerceContentSelector search model.

Being channel aware is optional. If the Commerce Server TargetingContext profile does not contain a Channel property the system will not thrown an exception.

See Also

Other Resources

Developing with the Commerce Foundation Marketing System

Commerce Foundation ContentSelector

CommerceQuery