Hide zero price (i.e. price set by product attributes)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
I have a number of items, like drill bits for example, which I will create a 'main' product for and individual Simple product types for and then associate with a product attribute. This works nicely (though a bit obtuse trying to figure out how to configure it.) The price is set by the attribute only, they base price is zero. This works well EXCEPT that on the category view of the 'main' product the price is shown as $0.00 which is not ideal.

In the searches I have done for this subject I have seen other suggest various code changes for various versions of nopCommerce but non of them seem to relate to the current (3.8) version. This seems like it would be a commonly requested/needed feature but it is not built in so I'm left with figuring out how to add it. Obviously I don't want to hide all prices, just those where products price field is set to 0.00.

I have been fumbling around in the code and would 'assume' this would be done in the 'view' part of the code and I have found ...\nopCommerce_3.80_Source\Presentation\Nop.Web\Views\Product\_ProductPrice.cshtml but then there is going to be some underlying C# code associated with the model that might be a better location for changes.

I am not fluent with web based code but from browsing thee above .cshtml file we eventually get to line #33:

<div class="@if (String.IsNullOrWhiteSpace(Model.PriceWithDiscount))
       {
           <text>product-price</text>
       }
       else
       {
           <text>non-discounted-price</text>
       }">


So if there is no 'ModelPriceWithDiscount' then 'product-price' is used? I am unfamiliar with this type of markup though I gather that this section of code is run 'in-line'.

Any pointers as to where to look or how to accomplish this task would be much appreciated.
7 years ago
That inline code is just selecting which class to use (for styling that one div).  There are a lot of other code/divs there for displaying various prices, so it may be best to just wrap them all up with a big "if price is not 0", e.g.:

if (Model.Price != decimal.Zero)
{
...
}


(of course, that assumes that you don't have any products that require showing the $0 price)
7 years ago
Thanks. As it turns out "...\nopCommerce_3.80_Source\Presentation\Nop.Web\Views\Product\_ProductPrice.cshtm" is for the product detail page. Since the products I have set up this way require an attribute to be selected the displayed price will always be non-zero.

After a bit more poking around I found "...\nopCommerce_3.80_Source\Presentation\Nop.Web\Views\Shared\_ProductBox.cshtml" which is used for the category view of products.

Starting on line 51:


<div class="add-info">
     @Html.Widget("productbox_addinfo_before", Model.Id)
     @if(Model.ProductPrice.Price.Remove(0,1) != "0.00") @*<----this is what was added*@
     {


Since Model.ProductPrice returns a string I trimmed off the currency symbol (i.e. $. or Euro symbol) and then test against "0.00" . I know this is crude as it does not account for localizations were the radix convention swaps the use of comma and period. Perhaps someone knows a better way? Maybe a simple test is if the first character to the right of the currency symbol is zero?
7 years ago
Try referencing PriceValue property (it's a decimal)

        public partial class ProductPriceModel : BaseNopModel
        {
            ...
            public decimal PriceValue { get; set; }
7 years ago
That works! Thanks for your help. Now for the tiny task of populating the database with products :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.