Appearance
Data Object Filter
Filtering on Data Objects can be a useful way to handle complex scenarios where multiple similar pieces of data need to be stored on the same product. For instance, details about the product's availability and location across multiple physical stores can be stored in a data object and retrieved as necessary in a filter.
The filter itself is a simple ProductDataFilter, which is set up to target the data within the data object - requiring another "layer" in the filter to find the desired data. This guide aims to explain how you accomplish this using a simple example.
Data Object and Conditions
To create a filter that targets a Data Object, you must first specify the kind of data that you are trying to target within the Object. For this example, we will be targeting Product Data, so we will use a ProductDataFilter with the Contains condition. This is in order to properly look up data within the object itself.
Within the condition parameters, you can specify an ObjectFilter, which is the heart of what we are trying to accomplish. The ObjectFilter takes its own ObjectValueEqualsCondition, which mirrors the conditions of a regular filter - you can consult our list of conditions here.
The ObjectValueCondition takes two arguments: the Key and the Value. This specifies what data key within the object you want to filter by, and what value should be filtered by. In the example below, we are targeting the key DataKey contained within the object DataObject, and specifying that DataKey must contain the string value String.
JSON Example:
json
{
"$type": "Relewise.Client.Requests.Filters.FilterCollection, Relewise.Client",
"Items": [
{
"$type": "Relewise.Client.Requests.Filters.ProductDataFilter, Relewise.Client",
"Key": "DataObject",
"FilterOutIfKeyIsNotFound": true,
"MustMatchAllConditions": true,
"Conditions": {
"Items": [
{
"$type": "Relewise.Client.Requests.Conditions.ContainsCondition, Relewise.Client",
"Value": {
"Type": "String",
"IsCollection": false
},
"ValueCollectionEvaluationMode": "All",
"ObjectFilter": {
"Conditions": [
{
"$type": "Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueEqualsCondition, Relewise.Client",
"Value": {
"Type": "String",
"Value": "Value",
"IsCollection": false
},
"Negated": false,
"Key": "DataKey"
}
]
},
"TypeName": "ContainsCondition",
"Negated": false
}
]
},
"TypeName": "ProductDataFilter",
"Negated": false
}
]
}Data Object Filter With the SDK
Suppose you have a list of prices that vary both on country and currency. You want to create a Data Object that contains a list of all the country/currency price permutations, and create a filter that targets the relevant one country/currency combination(s).
csharp
var product = new Product();
var prices = new DataObject();
prices.Data["24:11"] = 553;
prices.Data["26:11"] = 738;
prices.Data["28:13"] = 19593;
prices.Data["10:5"] = 499;
product.Data["Prices"] = prices;ts
const product = new ProductUpdateBuilder({
id: 'product-id',
productUpdateKind: 'ReplaceProvidedProperties',
})
.data({
'Prices': DataValueFactory.object({
'24:11': DataValueFactory.number(553),
'26:11': DataValueFactory.number(738),
'28:13': DataValueFactory.number(19593),
'10:5': DataValueFactory.number(499),
}),
})With the data integrated, you can now create the filter by specifying the data key path within the object and then specifying which country/currency combination you want to filter on.
csharp
request.Filters.Add(new VariantDataFilter("Prices", new string[] { "1:1" }, new HasValueCondition()));
// The new string[] { "1:1" } is the object path within Prices to select from.ts
.filters(f => {
// Product
f.addProductDataFilter('Prices', b => b.addHasValueCondition(), undefined, undefined, undefined, { objectPath: ["1:1"] })
})