Class Ecommerce.Querying
- Namespace
- Dynamicweb.Ecommerce.Notifications
- Assembly
- Dynamicweb.Ecommerce.dll
Class Querying. This class cannot be inherited.
public sealed class Ecommerce.Querying
- Inheritance
-
Ecommerce.Querying
- Inherited Members
Fields
AfterQuery
The after query
public const string AfterQuery = "DWN_QUERYING_AfterQuery"
Field Value
BeforeQuery
The before query
public const string BeforeQuery = "DWN_QUERYING_BeforeQuery"
Field Value
BeforeQueryDatabase
Before query database notification
public const string BeforeQueryDatabase = "DWN_QUERYING_BeforeQueryDatabase"
Field Value
Examples
using System.Collections.Generic;
using Dynamicweb.Core;
using Dynamicweb.Data;
using Dynamicweb.Extensibility.Notifications;
using static Dynamicweb.Ecommerce.Notifications.Ecommerce.Querying;
namespace Dynamicweb.Ecommerce.Examples.Notifications;
/// <summary>
/// Subscribing on Cart.Created event
/// </summary>
[Subscribe(BeforeQueryDatabase)]
public class BeforeQueryDatabaseObserver : NotificationSubscriber
{
/// <summary>
/// This notification is thrown every time an index based search has been done
/// </summary>
/// <param name="notification"></param>
/// <param name="args"></param>
public override void OnNotify(string notification, NotificationArgs args)
{
if (args is not BeforeQueryDatabaseArgs cArgs)
return;
var autoids = new List<long>();
using (var dataReader = Database.CreateDataReader($"SELECT ProductAutoID FROM EcomProducts WHERE ProductAutoID in ({cArgs.AutoIds.ToString()}) ORDER BY ProductNumber"))
{
while (dataReader.Read())
{
autoids.Add(Converter.ToInt64(dataReader["ProductAutoID"]));
}
}
cArgs.AutoIds = autoids;
}
}
Remarks
Use this to change the search results after the index query has been done or to change the sorting of the results. The args contains a list of autoids (AutoIds) that can be used to search further. Return the autoids in the order they should be sorted.