Copied to clipboard

Flag this post as spam?

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


  • Simon 81 posts 184 karma points
    Nov 14, 2016 @ 10:01
    Simon
    0

    Problems accessing custom properties in FastTrack

    So using FastTrack, I've added a property productBackImage to the ftStore document type. This is a media picker property for picking a background image for the products. It should be recursive so if it's not set on the product level, it should use the store wide value.

    However, on the ftStore template, when I use @Model.productBackImage, I get a error:

     'Umbraco.Web.PublishedContentModels.FtStore' does not contain a definition for 'productBackImage' 
    

    I also have a Merchello Single Product selector set up on a property featuredProduct. If I use:

    @{
        var productId = new Guid(Model.Content.GetProperty("featuredProduct").DataValue.ToString());
        var productContent = merchello.Query.Product.GetByKey(productId).AsProductContent();
     }
    

    I get an error - using Umbraco 7.5.4 - so is this new as I've seen Rusty suggesting this is how it should be done. Umbraco.Core.Models.PublishedContent.PublishedContentWrapped.Content' is inaccessible due to its protection level

    HELP!

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 14, 2016 @ 17:11
    Rusty Swayne
    0

    Hi Simon,

    In order to use a recursive property you need to make sure that the parent node is set. This is done in the FastTrack starter here: https://github.com/Merchello/Merchello/blob/merchello-dev/src/Merchello.FastTrack.Ui/UmbracoEventHandler.cs#L51

    It's important to realize that IProductContent is virtual content so the "parent" is "ftStore" (which it looks like you're doing) - BUT the Umbraco.Web.PublishedContentModels.FtStore looks like you might need to regenerate your models builder model(s) ... in other words, my guess is this is not a Merchello issue, but an is related to your models builder configuration.

    The the single product selector, try not to use the AsProductContent() extension. This will eventually be removed or at very least be moved internal for a number of reasons.

      var productContent = merchello.Query.Product.TypedProductContent(productId);
    
  • Simon 81 posts 184 karma points
    Nov 14, 2016 @ 17:33
    Simon
    0

    Hi Rusty,

    How do I get my product id? As

    var productId = new Guid(Model.Content.GetProperty("featuredProduct").DataValue.ToString());
    

    throws the exception about Model.Content being inaccessible

    Umbraco.Core.Models.PublishedContent.PublishedContentWrapped.Content' is inaccessible due to its protection level
    

    Regarding the Models Builder - huh? Sorry but no idea - is that just a VS recompile?

    Thanks Simon

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 14, 2016 @ 19:42
    Rusty Swayne
    0

    Hi Simon,

    Models Builder is included in Umbraco on install - it was initially introduced as an external package but then integrated directly into the Core. Depending on what setting you have in the web.config

    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <!-- usually the setting you have here -->
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="LiveDll" />
    

    will affect the way the typed model used in the views is generated. Depending on your settings, you may have to go to the developers tab and regenerate the models.

    I've played around with the models builder and in general like it - but have noticed at times you have to giggle the handle so to speak to get things to kick ...

    The Model.Content your referring to in the first question is not generated by Merchello - I'm just assuming it's models builder. If you're not using models builder and using something like the hybrid framework "pattern" - you may have to look at your base models.

    What model is in the inherits in you're view?

    ex.

      @inherits Umbraco.Web.Mvc.UmbracoViewPage<FtStore>
    
  • Simon 81 posts 184 karma points
    Nov 14, 2016 @ 21:28
    Simon
    0

    Hi Rusty,

    I've just added another property to the ftStore document type and now I'm trying to access it which has thrown up all these problems. I haven't changed any settings to do with Model Builder.

    Any ideas?

    Thanks

    Simon

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Nov 14, 2016 @ 22:06
    Rusty Swayne
    0

    Sorry bud - probably start with playing around with the settings and getting familiar with models builder itself.

    The docs are pretty good - https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki

  • Simon 81 posts 184 karma points
    Nov 18, 2016 @ 12:53
    Simon
    0

    For future reference and anyone else finding this. Rebuilding the models helped to a certain extent however....

    The Model Builder uses UpperCamelCase for the property names, not Umbraco's standard lowerCamelCase so although the property that was added had the Umbraco alias of "backImage", it needs to be used as @Model.BackImage in the MVC view

Please Sign in or register to post replies

Write your reply to:

Draft