Search by Product Id

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
Hi

I noticed that when using the Search textbox if I enter the full SKU number and hit enter no results return even though there is a product with that number (I copied the SKU from the product). However if enter the SKU and wait until the app does a background search, the product is brought up as a hint. Any reason why this happens?

Using nopCommerce 3.20
10 years ago
rahr1 wrote:

Hi

I noticed that when using the Search textbox if I enter the full SKU number and hit enter no results return even though there is a product with that number (I copied the SKU from the product). However if enter the SKU and wait until the app does a background search, the product is brought up as a hint. Any reason why this happens?

Using nopCommerce 3.20


Hi,

Yes, By default nopCommerce Search By SKU is not enabled.

It's just one line change.

You can edit CatalogController.cs file in Nop.Web\Controllers.

..\Presentation\Nop.Web\Controllers\CatalogController.cs

In CatalogController.cs file search for keyword 'serachSku:' and check that values.
If it 'searchSku: searchInDescriptions' changes it to 'searchSku: true'

compile code and check by searching item by sku.

"searchSku: searchInDescriptions"
Replace above line with
"searchSku: true"

After this change code will look like below. I've commented original line and added change in new line.
            
products = _productService.SearchProducts(
  categoryIds: categoryIds,
  manufacturerId: manufacturerId,
  storeId: _storeContext.CurrentStore.Id,
  visibleIndividuallyOnly: true,
  priceMin: minPriceConverted,
  priceMax: maxPriceConverted,
  keywords:model.Q,
  searchDescriptions: searchInDescriptions,
  
        //Change to Enable Search By Sku in NopCommerce.
        //searchSku: searchInDescriptions,
  searchSku: true,

  searchProductTags: searchInProductTags,
  languageId:_workContext.WorkingLanguage.Id,
  pageIndex: command.PageNumber - 1,
  pageSize: command.PageSize);
model.Products = PrepareProductOverviewModels(products).ToList();
            
Please +1 vote if it help you.

This code is for nop 3.20.

Thanks.
Ajay Saksena
10 years ago
It worked. Thanks Ajay
9 years ago
How do you get it working to Search on SKU in version 3.50?
9 years ago
kevinwn wrote:
How do you get it working to Search on SKU in version 3.50?


Hi,

Please follow this steps.
Go to
Path :
..\Nop_Project_Folder\Presentation\Nop.Web\Controllers\CatalogController.cs

Open CatalogController.cs

Now go following method and modify code as modified below.

Method Name :

[NopHttpsRequirement(SslRequirement.No)]
        [ValidateInput(false)]
        public ActionResult Search(SearchModel model, CatalogPagingFilteringModel command)


Code Change:

                    //products
                    products = _productService.SearchProducts(
                        categoryIds: categoryIds,
                        manufacturerId: manufacturerId,
                        storeId: _storeContext.CurrentStore.Id,
                        visibleIndividuallyOnly: true,
                        priceMin: minPriceConverted,
                        priceMax: maxPriceConverted,
                        keywords:model.Q,
                        searchDescriptions: searchInDescriptions,

                        //Original Code
                        //searchSku: searchInDescriptions,

                        //updated code
                        searchSku: true,

                        searchProductTags: searchInProductTags,
                        languageId: _workContext.WorkingLanguage.Id,
                        orderBy: (ProductSortingEnum)command.OrderBy,
                        pageIndex: command.PageNumber - 1,
                        pageSize: command.PageSize);
                    model.Products = PrepareProductOverviewModels(products).ToList();


update searchSku=true in code this will enable search by sku.
This code starts at line number 1337 in nop 3.50.

Hope this will work for you.
9 years ago
If you do not want to change .cs and you like SQL,

Find the store procedure --ProductLoadAllPaged  

Instead of   
  --SKU
    IF @SearchSku = 1
          BEGIN
      SET @sql = @sql + '
      UNION
      SELECT p.Id
      FROM Product p with (NOLOCK)
      WHERE '
      IF @UseFullTextSearch = 1
        SET @sql = @sql + 'CONTAINS(p.[Sku], @Keywords) '
      ELSE
        SET @sql = @sql + 'PATINDEX(@Keywords, p.[Sku]) > 0 '
    END

Use
  --SKU
    --IF @SearchSku = 1
          --BEGIN
      SET @sql = @sql + '
      UNION
      SELECT p.Id
      FROM Product p with (NOLOCK)
      WHERE '
      IF @UseFullTextSearch = 1
        SET @sql = @sql + 'CONTAINS(p.[Sku], @Keywords) '
      ELSE
        SET @sql = @sql + 'PATINDEX(@Keywords, p.[Sku]) > 0 '
    --END
8 years ago
to shahdat45ict

Thanks! Your way is best, Too Simple, goes directly to what I want.

I have another question, I have a item name like: Vacuum Autoclave with Air Pump. I like to show it when people just search two words: Vacuum Air OR Vacuum Pump. How to make this happened?

Thanks again!
8 years ago
To shahdat45ict
Hi, Please disregard my previous question, I think the system works in that way already.
Thanks again for your smart solution, have a nice day!
James
8 years ago
Glad to see the your issue is resolved. Yes, search applies contains operation. Thank you.
8 years ago
To shahdat45ict

Hi, Thanks for your help. I have a question for you. As your way works directly at SQL procedure, later on for any upgrade version, it will work automatically. I don't need to work on the SQL procedure again, which I had to do each time on the ASP source code before for every version upgrade.

Is this correct?

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.