Exluding Products from Search

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
cierra
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Sun May 29, 2011 5:11 pm

Exluding Products from Search

Post by cierra » Thu Jun 16, 2011 9:08 am

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.

User avatar
s_ismail
Commander (CMDR)
Commander (CMDR)
Posts: 162
Joined: Mon Nov 09, 2009 12:20 am
Contact:

Re: Exluding Products from Search

Post by s_ismail » Thu Jun 16, 2011 9:39 am

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.

cierra
Ensign (ENS)
Ensign (ENS)
Posts: 19
Joined: Sun May 29, 2011 5:11 pm

Re: Exluding Products from Search

Post by cierra » Fri Jun 17, 2011 1:56 pm

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.

User avatar
s_ismail
Commander (CMDR)
Commander (CMDR)
Posts: 162
Joined: Mon Nov 09, 2009 12:20 am
Contact:

Re: Exluding Products from Search

Post by s_ismail » Sat Jun 18, 2011 2:42 am

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

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Exluding Products from Search

Post by mazhar » Sat Jun 18, 2011 2:58 am

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.

Post Reply