/// <summary>
    /// Get where condition for unigrid
    /// </summary>
    /// <returns>Where condition</returns>
    private WhereCondition GetWhereCondition()
    {
        string productNameFilter = txtProductName.Text;

        // To display ONLY product - not product options
        var where = new WhereCondition().WhereTrue("SKUEnabled").And().WhereNull("SKUOptionCategoryID");

        if (!string.IsNullOrEmpty(productNameFilter))
        {
            // Alias for COM_SKU
            var variants = new QuerySourceTable("COM_SKU", "variants");

            // Get IDs of products containing filter text; search among variants too
            var ids = new IDQuery <SKUInfo>()
                      .Columns(new QueryColumn("COM_SKU.SKUID"))
                      .Source(s => s.LeftJoin(variants, "COM_SKU.SKUID", "variants.SKUParentSKUID",
                                              new WhereCondition()
                                              .WhereContains("variants.SKUName", productNameFilter)
                                              .Or()
                                              .WhereContains("variants.SKUNumber", productNameFilter)))
                      .Where(
                new WhereCondition()
                .WhereContains("COM_SKU.SKUName", productNameFilter)
                .Or()
                .WhereContains("COM_SKU.SKUNumber", productNameFilter));

            // Add the condition
            where.Where(w => w.WhereIn("SKUID", ids));
        }

        where.Where(GetSiteWhereCondition(SiteContext.CurrentSiteID));

        return(where);
    }
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    public void ReloadData()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        if (!DisplayNoDataMessage)
        {
            uniSelector.ZeroRowsText = string.Empty;
        }

        // Need to set uni-selector value again after basic form reload
        if (AllowMultipleChoice)
        {
            uniSelector.Value = mMultipleChoiceValue;
        }

        var where = new WhereCondition();

        if (ProductOptionCategoryID > 0)
        {
            where.WhereEquals("SKUOptionCategoryID", ProductOptionCategoryID);
        }
        else
        {
            var productSiteWhere = new WhereCondition();

            // Add global products
            if (DisplayGlobalProducts)
            {
                productSiteWhere.Where(w => w.WhereNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific products
            if (DisplaySiteProducts)
            {
                productSiteWhere.Or().Where(w => w.WhereNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Where(productSiteWhere);
        }

        // Exclude standard products if needed
        if (!DisplayStandardProducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Product.ToStringRepresentation());
        }

        // Exclude memberships if needed
        if (!DisplayMemberships)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Membership.ToStringRepresentation());
        }

        // Exclude e-products if needed
        if (!DisplayEproducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.EProduct.ToStringRepresentation());
        }

        // Exclude bundles if needed
        if (!DisplayBundles)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Bundle.ToStringRepresentation());
        }

        // Exclude products with product options if needed
        if (DisplayOnlyProductsWithoutOptions)
        {
            where.WhereNotIn("SKUID", new IDQuery <SKUOptionCategoryInfo>("SKUID"));
        }

        if (DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            var optionsSiteWhere = new WhereCondition();

            // Add global options
            if (DisplayGlobalOptions)
            {
                optionsSiteWhere.Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific options
            if (DisplaySiteOptions)
            {
                optionsSiteWhere.Or().Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Or().Where(optionsSiteWhere);
            where = new WhereCondition().Where(where);
        }

        // Filter out only enabled items
        if (DisplayOnlyEnabled)
        {
            where.WhereTrue("SKUEnabled");
        }

        if (!DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            where.WhereNull("SKUOptionCategoryID");
        }

        if (DisplayProductVariants)
        {
            // Alias for COM_SKU
            var parents = new QuerySourceTable("COM_SKU", "parentIDs");

            // Select IDs of all products that are not parents of variants
            var ids = new IDQuery <SKUInfo>()
                      .Columns(new QueryColumn("COM_SKU.SKUID"))
                      .Source(s => s.LeftJoin(parents, "COM_SKU.SKUID", "parentIDs.SKUParentSKUID"))
                      .Where(new WhereCondition().WhereNull("parentIDs.SKUID"));

            where.WhereIn("SKUID", ids);
        }
        else
        {
            // Do not display variants
            where.WhereNull("SKUParentSKUID");
        }

        // Add items which have to be on the list
        var additionalList = AdditionalItems.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

        if (additionalList.Length > 0)
        {
            var ids = ValidationHelper.GetIntegers(additionalList, 0);
            where.Or().WhereIn("SKUID", ids);
        }

        // Selected value must be on the list
        if (SKUID > 0)
        {
            where.Or().WhereEquals("SKUID", SKUID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }