Click or drag to resize
EcommerceQueryingBeforeQueryDatabase Field
Before query database notification

Namespace: Dynamicweb.Ecommerce.Notifications
Assembly: Dynamicweb.Ecommerce (in Dynamicweb.Ecommerce.dll) Version: 1.7.0
Syntax
public const string BeforeQueryDatabase = "DWN_QUERYING_BeforeQueryDatabase"

Field Value

Type: String
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.
Examples
C#
using System;

namespace Dynamicweb.Ecommerce.Examples.Notifications
{
    /// <summary>
    /// Subscribing on Cart.Created event
    /// </summary>
    [Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Querying.BeforeQueryDatabase)]
    public class BeforeQueryDatabaseObserver : Dynamicweb.Extensibility.Notifications.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, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
        {
            if (args == null || !(args is Dynamicweb.Ecommerce.Notifications.Ecommerce.Querying.BeforeQueryDatabaseArgs))
                return;
            var cArgs = (Dynamicweb.Ecommerce.Notifications.Ecommerce.Querying.BeforeQueryDatabaseArgs)args;

            var autoids = new System.Collections.Generic.List<Int64>();

            using (var myDr = Dynamicweb.Data.Database.CreateDataReader($"SELECT ProductAutoID FROM EcomProducts WHERE ProductAutoID in ({cArgs.AutoIds.ToString()}) ORDER BY ProductNumber"))
            {
                while (myDr.Read())
                {
                    autoids.Add(Dynamicweb.Core.Converter.ToInt64(myDr["ProductAutoID"]));
                }
            }

            cArgs.AutoIds = autoids;


        }
    }
}
See Also