Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Magnus Jonsson 33 posts 53 karma points
    Mar 31, 2011 @ 10:24
    Magnus Jonsson
    0

    How to get Product DisplayName with razor?

    Hi,

    I've started to play around using razor-macros with ucommerce as demoed in this blogpost: http://www.publicvoid.dk/BuildingWebshopsWithUmbracoRazorAndTheUCommerceEcommerceFrameworkOhMy.aspx

    But, How do I get a Prodocts DisplayName-property?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Mar 31, 2011 @ 10:58
    Søren Spelling Lund
    0

    Hi Magnus,

    You need to access the language specific objects to get the display name. Basically each product has an number of these attached, one for each enabled language, which hold display name, description, and any multilingual properties you've defined via the product definition.

    You can do the following to get at it:

    var product = Product.All().First(); // get some product
    string displayName = product.GetDescription("en-us").DisplayName;
  • Magnus Jonsson 33 posts 53 karma points
    Mar 31, 2011 @ 12:48
    Magnus Jonsson
    0

    Great! Thanks // Magnus

  • hansdesmedt 10 posts 31 karma points
    Aug 09, 2012 @ 12:00
    hansdesmedt
    1

    if you want the current language, I do this:

    var context = ObjectFactory.Instance.Resolve<ILocalizationContext>();
    var test = context.CurrentCulture;

     

    CurrentCulture uses the language set up with "Manage Hostnames" in umbraco, most likely you want this in multi language site

    DefaultCulture uses the control panel setting, so this is more correct then the browsersetting

     

     

     

     

     

  • Naorem Rainson 10 posts 30 karma points
    Nov 07, 2012 @ 08:07
    Naorem Rainson
    0

    Hi Soren,

    When i tried your code,it gives an error saying that "The name 'Product' does not exist in the current context". How can i solve this ?

    regards

    Rainson

  • Søren Spelling Lund 1797 posts 2786 karma points
    Nov 09, 2012 @ 13:08
    Søren Spelling Lund
    0

    I didn't include the using statement.

    You want to add this (for Razor):

    @using UCommerce.EntitiesV2
    @{
      var product = Product.All().First(); // get some product
      string displayName = product.GetDescription("en-us").DisplayName;

    Hope this helps.

Please Sign in or register to post replies

Write your reply to:

Draft