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
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);
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.
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.
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
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:I also have a Merchello Single Product selector set up on a property
featuredProduct
. If I use: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!
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.Hi Rusty,
How do I get my product id? As
throws the exception about Model.Content being inaccessible
Regarding the Models Builder - huh? Sorry but no idea - is that just a VS recompile?
Thanks Simon
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
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.
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
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
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 viewis working on a reply...