Show product descriprion only to specific customer role.

9 months ago
Hi.

I want to use nopCommerce for selling video lessons content.

What I need is to show products and short description with demo, but do not show full description. In full description there would be paid content.

So, full descripion would be allowed only for specific customer role.

css display:none DOES NOT WORK FOR US.

Any ideas about how to do it?

Thanks for help in advance.
9 months ago
Hello Zaf,

You can do that using a plugin if you are going to use nopCommerce plugin architecture or if you are customizing source code, it will be more easier.

In both cases, you need to add a new permission record for example "Public store.Display product full description" and then modify product template CSHTML file to use this permission where exactly you want to place it. Once done, you just need to configure this newly added permission record for any customer role that you wanted.

I hope this will help you to solve your problem. There is no other way to do this beside what I told you above.

Thank you,
Atul
9 months ago
zaf wrote:
Hi.

I want to use nopCommerce for selling video lessons content.

What I need is to show products and short description with demo, but do not show full description. In full description there would be paid content.

So, full descripion would be allowed only for specific customer role.

css display:none DOES NOT WORK FOR US.

Any ideas about how to do it?

Thanks for help in advance.



Hello zaf,

it is not a good practise but you achieve this by editing your ProductTemaplate.Simple.cshtml file.

You need to add the @inject Nop.Core.IWorkContext workContext on top like so:

@model ProductDetailsModel
@using Nop.Core.Domain.Seo;
@inject Nop.Core.IWebHelper webHelper
@inject SeoSettings seoSettings
@inject Nop.Core.IWorkContext workContext


Then you need to find the IF statement around your full-description and extend it like so:


@if (!string.IsNullOrEmpty(Model.FullDescription) && workContext.CurrentCustomer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == Nop.Core.Domain.Customers.NopCustomerDefaults.RegisteredRoleName) != null)
                    {
                        <div class="full-description" itemprop="description">
                            @Html.Raw(Model.FullDescription)
                        </div>
                    }


This would work if you are using any of the Default Customer Roles, you just need to edit the last part to fit the exact role you want the content to show to.

However, if you want to add a totally new Customer role, you can then use the following IF statement instead:

@if (!string.IsNullOrEmpty(Model.FullDescription) && workContext.CurrentCustomer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == "Cookies") != null)
                    {
                        <div class="full-description" itemprop="description">
                            @Html.Raw(Model.FullDescription)
                        </div>
                    }



Just instead of Cookies, use the System name for your new Customer role.

Hope this was helpful.

Best Regards,
Valentin.
9 months ago
Nop-Templates.com wrote:
Hi.

I want to use nopCommerce for selling video lessons content.

What I need is to show products and short description with demo, but do not show full description. In full description there would be paid content.

So, full descripion would be allowed only for specific customer role.

css display:none DOES NOT WORK FOR US.

Any ideas about how to do it?

Thanks for help in advance.


Hello zaf,

it is not a good practise butyou achieve this by editing your ProductTemaplate.Simple.cshtml file.

You need to add the @inject Nop.Core.IWorkContext workContext on top like so:

@model ProductDetailsModel
@using Nop.Core.Domain.Seo;
@inject Nop.Core.IWebHelper webHelper
@inject SeoSettings seoSettings
@inject Nop.Core.IWorkContext workContext


Then you need to find the IF statement around your full-description and extend it like so:


@if (!string.IsNullOrEmpty(Model.FullDescription) && workContext.CurrentCustomer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == Nop.Core.Domain.Customers.NopCustomerDefaults.RegisteredRoleName) != null)
                    {
                        <div class="full-description" itemprop="description">
                            @Html.Raw(Model.FullDescription)
                        </div>
                    }


This would work if you are using any of the Default Customer roles, you just need to edit the last part to fit the exact role you want the content to show to.

However, if you want to add a totally new Customer role, you can then use the following IF statement instead:

@if (!string.IsNullOrEmpty(Model.FullDescription) && workContext.CurrentCustomer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == "[b]Cookies") != null[/b])
                    {
                        <div class="full-description" itemprop="description">
                            @Html.Raw(Model.FullDescription)
                        </div>
                    }



Just instead of Cookies, use the System name for your new Customer role.

Hope this was helpful.

Best Regards,
Valentin.


Perfect..

Regards,
Atul