Three Handy NopCommerce Hacks You Can Do Without Plugins

One of the things I love about nopCommerce is its flexibility for customization and ease of extending functionality via plugins. With 1250+ plugins (free and paid), there is a plugin for every need and budget. Installing plugins on a nopCommerce site is a great user-friendly way to add new features and functionalities. The plugins aren't the answer all the time. You do not need plugin(s) every time. You may wish to add a new feature to your store site, because nopCommerce alone can do many cool things with little customization.

What is nopCommerce?

nopCommerce is an open source e-Commerce software, that is based on ASP.NET (MVC) and it contains both a catalog frontend and an administration tool backend. nopCommerce is a fully customizable shopping cart. (Source: www.nopcommerce.com).

Let me explain in detail

Prerequisite(s)

 

1) Preventing first attribute item from being selected in a dropdown menu

In nopCommerce, the product attributes allow store owners to offer customizable products so that the customers can make the changes to those products as per their needs / requirements. One of the best things about the product attributes is dynamic product pricing i.e. the list price is changed dynamically, as a customer is adding or removing the attributes on the product page. This way, a customer is aware of how attributes are affecting the price of the product before adding the product to the shopping cart.

Product attributes can be added in nopCommerce as:
  • Dropdown list
  • Radio list
  • Checkboxes
  • Textbox
  • Multiline textbox
  • Date picker
  • File upload
  • Color squares
  • Read-only checkboxes

If we specifically talk about "Dropdown list", when attribute values are added in the list, the first value in the list is always the default value. It is not an issue or a bug, but it is by design in nopCommerce.

Here is an example of the values in a dropdown list product attribute.

product

By default, this Dropdown menu attribute looks like as shown below:

menu

Here, we can see that the first value is selected by default in the Dropdown menu(attribute). Hence, the problem is that, when a customer tries to add the product in the shopping cart, by default 8GB RAM will be selected and there is some possibility of placing a wrong order unintentionally. This also leads to pricing issue, because the customer will be charged an extra $50 for it.

Hack (Solution)

This problem can be fixed in the code by going to,

Nop.Web\Views\Product\_ProductAttributes.cshtml

Views

Let's open the view "_ProductAttributes.cshtml" and look for the code, given below:

  1. @if(!attribute.IsRequired)  
  2. {   
  3.   <option value = "0" > -- - < /option>   
  4. }  
Now, replace it with the code, given below:
  1. <option value="0">--Please Select--</option>  
Save changes and go to the publilc store (open the customizable product page) and you will see the Dropdown menu attribute, as shown below:

menu

This solution will prevent the first attribute item from being selected in a Dropdown menu.

 
 
 
2) Changing default admin URL

In nopCommerce, the administration section can be viewed by any user with "admin role" by going to the URL www.YourStore.com/Admin.

Security is always one of the most important things to consider, when it comes to managing an E-commerce store site. An E-commerce store site manages all the online transactions and the customer's personal information. Some store owners believe that difficult URLs for private pages / sections of a site is one way to keep away the hackers.

If you are one of those store owners (or providing a solution to those store owners), you can change the default admin URL by making some customization in the source code of nopCommerce.

Here is the default URL for the administration section: www.YourStore.com/Admin

URL


Hack (Solution)

Go to: Nop.Admin\AdminAreaRegistration.cs

AdminAreaRegistration.cs

Open "AdminAreaRegistration.cs" file and look for the code, given below:
  1. public override void RegisterArea(AreaRegistrationContext context)  
  2. {  
  3.     context.MapRoute(  
  4.         "Admin_default",  
  5.         "Admin/{controller}/{action}/{id}",  
  6.         new  
  7.         {  
  8.             controller = "Home", action = "Index", area = "Admin", id = ""  
  9.         },  
  10.         new []   
  11.         {  
  12.             "Nop.Admin.Controllers"  
  13.         }  
  14.     );  
  15. }  
By looking at the code, we can see that "Admin" term has been defined in the RegistrationArea. If we change this term to something else, it should update the admin URL.

Let's update this code to this,
  1. public override void RegisterArea(AreaRegistrationContext context)   
  2. {  
  3.     context.MapRoute(  
  4.         "Admin_default",  
  5.         "StoreAdminSite51325/{controller}/{action}/{id}",  
  6.         new  
  7.       {  
  8.             controller = "Home", action = "Index", area = "Admin", id = ""  
  9.         },  
  10.         new []  
  11.       {  
  12.             "Nop.Admin.Controllers"  
  13.         }  
  14.     );  
  15. }  
Save the changes and rebuild your solution. Now, try running your Website and by going to the default admin URL, you will see this error message:

error

Let's try the new updated admin URL: www.YourStore.com/StoreAdminSite51325

URL

There is no to very little chance that anyone can guest your administration section URL after applying this hack (solution).

 
 
 
3) Adding "search by SKU" to basic search

There are many online businesses that maintain their inventory by SKU number. SKU number is a very important aspect of the online business; i.e., unique identification number of a product, by which a product can be searched on E-commerce store sites. nopCommerce allows the option to store owners to add the SKU number, while adding the product(s) from the administration section.

If your customers are familiar with the SKU number of the product(s), there is always a possibility that they will search the products by SKU # on your store site.

nopCommerce does offer the option (out of the box) on the public store to search the product(s) by SKU, but in order to do that, the customer needs to go in "Advanced search" and Check the option to search in the product description, given below:

search

Hack (Solution)

We can easily add "Search by SKU" to the basic search so that customers do not have to go to "Advanced search" or enable the option to search by description in order to search a product by its SKU #.

In order to accomplish this, we will need to make a minor customization in the source code.

Go to: Nop.Web\Controllers\CatalogController.cs

Controllers

Open the file "CatalogController.cs" and look for "searchSku: searchInDescriptions" in the code.
  1. //products   
  2. products = _productService.SearchProducts(   
  3. categoryIds: categoryIds,   
  4. manufacturerId: manufacturerId,   
  5. storeId: _storeContext.CurrentStore.Id,   
  6. visibleIndividuallyOnly: true,   
  7. priceMin: minPriceConverted,   
  8. priceMax: maxPriceConverted,   
  9. keywords: searchTerms,   
  10. searchDescriptions: searchInDescriptions,   
  11. searchSku: searchInDescriptions,   
  12. searchProductTags: searchInProductTags,   
  13. languageId: _workContext.WorkingLanguage.Id,   
  14. orderBy: (ProductSortingEnum)command.OrderBy,   
  15. pageIndex: command.PageNumber - 1,   
  16. pageSize: command.PageSize);   
  17. model.Products = PrepareProductOverviewModels(products).ToList();   
Simply, replace "searchSku: searchInDescriptions," with "searchSku: true", as shown below:
  1. //products   
  2. products = _productService.SearchProducts(   
  3. categoryIds: categoryIds,   
  4. manufacturerId: manufacturerId,   
  5. storeId: _storeContext.CurrentStore.Id,   
  6. visibleIndividuallyOnly: true,   
  7. priceMin: minPriceConverted,   
  8. priceMax: maxPriceConverted,   
  9. keywords: searchTerms,   
  10. searchDescriptions: searchInDescriptions,   
  11. searchSku: true,   
  12. searchProductTags: searchInProductTags,   
  13. languageId: _workContext.WorkingLanguage.Id,   
  14. orderBy: (ProductSortingEnum)command.OrderBy,   
  15. pageIndex: command.PageNumber - 1,   
  16. pageSize: command.PageSize);   
  17. model.Products = PrepareProductOverviewModels(products).ToList();   
Save the changes and compile your solution to view the public store.

Try searching a product by its SKU number via a basic search option and you will get the product in the search results without going into "Advanced search" option, as shown below:

search
I hope many nopCommerce users / developers will find this article (handy nopCommerce hacks) useful.

 

  • nopCommerce can be downloaded here.
  • nopCommerce Version (used in this article): Version 3.70.
  • nopCommerce Support.