Handy NopCommerce Hacks You Can Do Without Plugins - Part Two

I hope you got some good usage out of my first installment of the "Handy NopCommerce Hacks You Can Do Without Plugins" series. In case you missed it, you can find the "Part 1" of this series here.

nopCommerce is one of the most widely used e-Commerce solutions in .NET framework and it is backed by a very active and helpful community. There is no shortage of the ways in which you can tweak your nopCommerce site , as per your requirements / needs. There are many times, you come across a feature and you start thinking, how you can get the same feature on your nopCommerce store site. You can always find a 3rd party theme or a plugin, which matches your needs,  as the nopCommerce community offers 1250+ extensions, but in some cases, you can simply tweak your nopCommerce site (source code) and accomplish the same results (i.e. feature) without any plugin.


Download nopCommerce Source Code (used in this article): Version 3.70.
Displaying customer's name on homepage to add a personal touch
When you go to a coffee shop and someone asks you - "Would you like to try our new coffee flavor?", the first thing that comes to your mind is, it's an advertisement (nothing special about it). But, if you go to a coffee shop and someone asks you "the usual?", it gives you a feeling of personal touch. It is always nice to be remembered , because it makes you feel special.
You can imagine the homepage of an e-Commerce site as a cash register, where you will see the banners, advertisements and sometimes, you are asked to try a new product (just like the coffee shop). There is nothing new about it, because you will find the same approach on every other e-Commerce website. When the Website remembers you and displays your name saying "Welcome John", it makes you feel like an online business is going one step extra to add a personal touch to the store site.
Creating personalized online experiences has a high impact on ROI (Return on investment).
This is how the default homepage looks like in nopCommerce: 
Hack (Solution)
Go to: Nop.Web/Views/Home/Index.cshtml
Add the code, given below, at the top of your (homepage) view page "Index.cshtml". 
  1. @using Nop.Core  
  2. @using Nop.Core.Domain.Customers  
  3. @using Nop.Core.Infrastructure  
  4. @using Nop.Services.Common  
After adding the code, given above, your Index.cshml page should look like:   
  1. @using Nop.Core  
  2. @using Nop.Core.Domain.Customers  
  3. @using Nop.Core.Infrastructure  
  4. @using Nop.Services.Common  
  6. @{  
  7.     Layout = "/Views/Shared/_ColumnsOne.cshtml";  
  8. }  
  9. <div class="page home-page">  
  10.     <div class="page-body">  
  11.         @Html.Widget("home_page_top")  
  12.         @Html.Action("TopicBlock""Topic"new { systemName = "HomePageText" })  
  13.         @Html.Widget("home_page_before_categories")  
  14.         @Html.Action("HomepageCategories""Catalog")  
  15.         @Html.Widget("home_page_before_products")  
  16.         @Html.Action("HomepageProducts""Product")  
  17.         @Html.Widget("home_page_before_best_sellers")  
  18.         @Html.Action("HomepageBestSellers""Product")  
  19.         @Html.Widget("home_page_before_news")  
  20.         @Html.Action("HomePageNews""News")  
  21.         @Html.Widget("home_page_before_poll")  
  22.         @Html.Action("HomePagePolls""Poll")  
  23.         @Html.Widget("home_page_bottom")  
  24.     </div>  
  25. </div>
In this example, the homepage (index.cshml) code looks like:  
  1. @using Nop.Core  
  2. @using Nop.Core.Domain.Customers  
  3. @using Nop.Core.Infrastructure  
  4. @using Nop.Services.Common  
  6. @{  
  7.     Layout = "/Views/Shared/_ColumnsOne.cshtml";  
  8. }  
  9. <div class="page home-page">  
  10.     <div class="page-body">  
  11.         @Html.Widget("home_page_top")  
  12.         @Html.Action("TopicBlock""Topic"new { systemName = "HomePageText" })  
  14.         @{  
  15.             var currentCustomer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;  
  17.             if (!currentCustomer.IsGuest())  
  18.             {  
  19.                 var name = currentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName);  
  21.                 if (!string.IsNullOrEmpty(name))  
  22.                 {  
  23.                     <div style="font-size:22px; color:red;">  
  24.                         <div id="addcustname" style="display: inline-block; ">Welcome to the store site:</div> <div id="custname" style="font-weight:bold;display: inline-block;">@name!</div>  
  25.                         <br/><br />  
  26.                     </div>  
  27.                 }  
  28.             }  
  29.         }  
  31.         @Html.Widget("home_page_before_categories")  
  32.         @Html.Action("HomepageCategories""Catalog")  
  33.         @Html.Widget("home_page_before_products")  
  34.         @Html.Action("HomepageProducts""Product")  
  35.         @Html.Widget("home_page_before_best_sellers")  
  36.         @Html.Action("HomepageBestSellers""Product")  
  37.         @Html.Widget("home_page_before_news")  
  38.         @Html.Action("HomePageNews""News")  
  39.         @Html.Widget("home_page_before_poll")  
  40.         @Html.Action("HomePagePolls""Poll")  
  41.         @Html.Widget("home_page_bottom")  
  42.     </div>  
  43. </div>  
Here, is the result!
With the help of this easy hack (solution), you can make your nopCommerce site homepage; a little more personalized!
Adding product ID to product detail page
Every store owner has a different set of requirements, when it comes to displaying the product information. Some prefer detailed product descriptions, while some prefer SKU numbers and some store owners prefer detailed specifications & so on..
nopCommerce already offers an option to display MPN (manufacturer part number), SKU number and GTIN (global trade item number) etc.
If a store owner wants to display the Product ID number on the product detail page? As of now, there is no out of the box option in nopCommerce to display the Product ID. Here are the steps to make it happen!
This is how, the default product page looks like:
Hack (Solution)
Go to: Nop.Web\Views\Product\ProductTemplate.Simple.cshtml
Open "ProductTemplate.Simple.cshtml" and look for this code - 
  1. <!--SKU, MAN, GTIN, vendor-->  
  2. @Html.Partial("_SKU_Man_GTIN_Ven", Model)  
We will add "@Model.Id" in order to display the product ID on this product template view. In order to do so, let's add the product ID like this:  
  1. <!--START CUSTOM CODE-->  
  2. <p><strong>Product ID: </strong>@Model.Id</p><br/>  
  3. <!--END CUSTOM CODE-->  
This is how, your code should look: 
  1. <!--product reviews-->  
  2.                        @Html.Partial("_ProductReviewOverview", Model.ProductReviewOverview)  
  3.                        <!--manufacturers-->  
  4.                        @Html.Partial("_ProductManufacturers", Model.ProductManufacturers)  
  5.                        <!--availability-->  
  6.                        @Html.Partial("_Availability", Model)  
  8.                        <div style="border-style: groove; padding: 10px; width:200px;">  
  9.                            <!--START CUSTOM CODE-->  
  10.                            <p><strong>Product ID: </strong>@Model.Id</p><br/>  
  11.                            <!--END CUSTOM CODE-->  
  12.                        </div>  
  13.                        <br/>  
  15.                            <!--SKU, MAN, GTIN, vendor-->  
  16.                            @Html.Partial("_SKU_Man_GTIN_Ven", Model)  
  17.                            <!--delivery-->  
  18.                            @Html.Partial("_DeliveryInfo", Model)  
  19.                            <!--sample download-->  
  20.                            @Html.Partial("_DownloadSample", Model)  
Now, save the changes and go to the product detail page (on public store).
Here, is the result!
I hope many nopCommerce users / developers will find this article (handy nopCommerce hacks) useful.


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now