Page 1 of 1

Exluding Products from Search

Posted: Thu Jun 16, 2011 9:08 am
by cierra
How do Exclude specific products from coming up in the site search? I know it seems like an odd request, but we have duplicate products we had to create in order to do a customized quick shopping form. We don't want those showing up, as we want people to go to the form only for those products. I can't find a way to segment out a specific category or product and keep it out of the internal search.

Re: Exluding Products from Search

Posted: Thu Jun 16, 2011 9:39 am
by s_ismail
If you don't want to show duplicate products anywhere else in store side then on making their visibility to private/hidden will not be accessible anywhere in store side including in search also.

Re: Exluding Products from Search

Posted: Fri Jun 17, 2011 1:56 pm
by cierra
We do need them to shore up in our store, on the page we created for them. Just not in the search because then it takes the customer away from the page we created and into the regular product page, which will be quite confusing to them.

Re: Exluding Products from Search

Posted: Sat Jun 18, 2011 2:42 am
by s_ismail
Well,
I think you need to write a custom query. I have done some basic work for you check it out

Go to ConLib SearchPage.ascx.cs and locate this code

Code: Select all

protected void BindProductList()
    {
        Trace.Write(this.GetType().ToString(), "Begin BindProductList");
        ProductList.DataSource = ProductDataSource.NarrowSearch(_FilteredKeywords, this.CategoryId, _ManufacturerId, 0, 0, _PageSize, (_HiddenPageIndex * _PageSize), SortResults.SelectedValue);
        ProductList.DataBind();
        NoSearchResults.Visible = (_SearchResultCount == 0);
        SearchResultsAjaxPanel.Update();
        Trace.Write(this.GetType().ToString(), "End BindProductList");
    }


and replace with this code

Code: Select all

 protected void BindProductList()
    {
        Trace.Write(this.GetType().ToString(), "Begin BindProductList");
       string excludeProducts="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16";//Replace with your own excluded Product Ids  
        ProductList.DataSource = LoadProducts(excludeProducts); //ProductDataSource.NarrowSearch(_FilteredKeywords, this.CategoryId, _ManufacturerId, 0, 0, _PageSize, (_HiddenPageIndex * _PageSize), SortResults.SelectedValue);
        ProductList.DataBind();
        NoSearchResults.Visible = (_SearchResultCount == 0);
        SearchResultsAjaxPanel.Update();
        Trace.Write(this.GetType().ToString(), "End BindProductList");
    }

    protected List<Product> LoadProducts(string productids)
    {        
        CommerceBuilder.Data.Database database = Token.Instance.Database;
        string sql = ("SELECT ProductId  FROM ac_Products WHERE ProductId NOT IN (" + productids + ")");//Comma seperated product ids 
        List<Product> filteredProducts = new List<Product>();
        using (System.Data.Common.DbCommand selectCommand = database.GetSqlStringCommand(sql))
        {            
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read())
                {
                    int prodId = dr.GetInt32(0);
                    Product product= ProductDataSource.Load(prodId);
                    if(product!=null)
                        filteredProducts.Add(product);
                }

            }
        }
        return filteredProducts;
    }

For more details about custom query have a look at this
http://wiki.ablecommerce.com/index.php/Custom_Queries

Re: Exluding Products from Search

Posted: Sat Jun 18, 2011 2:58 am
by mazhar
Products with visibility hidden will not be shown in store/search by still can be accessed by their direct URLs. So if you will be linking these products manually then hidden viability may work for you.