Inhalte aufrufen

Profilbild

display a link only to a specific role

roles

  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
4 Antworten zu diesem Thema

#1 razy69

razy69

    Member

  • Members
  • 15 Beiträge

Geschrieben: 18 September 2014 - 20:35

hi,

i  create a link in Menu.cshtml.

but i want to display this link to Only customers who have a specific role.

i create a role with the name SpecialCustmers.

 

how can i display my link only to this role???

 

thanks.



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3417 Beiträge

Geschrieben: 18 September 2014 - 20:53

See SmartStore.Services.Customers.CustomerExtentions for helpfull methods.
In your case somewhat like
bool isSpecialCustmer = _workContext.CurrentCustomer.IsInCustomerRole("SpecialCustmers");
Where "SpecialCustmers" is the system name of the role. Render the link only if isSpecialCustmer is true.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#3 razy69

razy69

    Member

  • Members
  • 15 Beiträge

Geschrieben: 19 September 2014 - 07:24

Thank you. But I received the following Compilation error:

 

Compiler Error Message: CS0103: The name '_workContext' does not exist in the current context

 

Please Help me.

 

Thanks a lot



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3417 Beiträge

Geschrieben: 19 September 2014 - 11:22

If you want to use the code directly in Menu.cshtml: Add
@using SmartStore.Services.Customers;
And resolve it like
@{
    bool isSpecialCustmer = EngineContext.Current.Resolve<SmartStore.Core.IWorkContext>().CurrentCustomer.IsInCustomerRole("SpecialCustmers");
}

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#5 razy69

razy69

    Member

  • Members
  • 15 Beiträge

Geschrieben: 20 September 2014 - 07:12

thanks for your answer.