Copied to clipboard

Flag this post as spam?

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


  • Pedro Tavares 10 posts 90 karma points c-trib
    Jan 04, 2016 @ 11:37
    Pedro Tavares
    0

    Strongly typed extended properties

    Hi all,

    Is there any way to extend this code to a custom Product class where I have the extended product properties?

    _products = Content.HasValue("products")
              ? Content.GetPropertyValue<IEnumerable<IProductContent>>("products").ToArray()
              : Enumerable.Empty<IProductContent>().ToArray();
    

    Thanks,

    Pedro

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jan 04, 2016 @ 16:38
    Rusty Swayne
    0

    Hey Pedro,

    Are you trying to extend the IProductContent to include typed properties?

    Assuming you're new class implements IPublishedContent you could use Ditto .As("").

    You could also create your own factory to build your model off of IProductContent or for something quick add extension methods off of IProductContent.

    I'd have to look this up, but I'm guessing there is a way to unregister Merchello's PropertyValueConverter for the Product List View data type and write your own to map directly to your model ... would love to see the solution on this if you do it.

  • Ben McKean 272 posts 549 karma points
    Jul 06, 2016 @ 11:24
    Ben McKean
    0

    Did you ever find solution to this?

    I too am using Ditto and Merchello and would like to map my extended properties to my Ditto Model as some are using composites

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Jul 06, 2016 @ 16:34
    Rusty Swayne
    0

    Hey Ben,

    In Merchello 2.1.0 the Product List View PropertyValueConverter now returns a type of ProductContentListView which implements IEnumerable<IProductContent> (so there is no breaking change).

    I've not used the most recent Ditto, but you used to be able to write custom value resolvers based off their base type. I've heard these are legacy and there is a more preferred easier way to do the same thing.

    Ditto should return the ProductContentListView by default (since it's just using Merchello's PropertyValueConverter). In order to get a typed (your type) enumeration of products, you would need to do a Ditto .As("[MYTYPE"] on each of the products in the enumerable - which would be done in the custom converter.

  • Ben McKean 272 posts 549 karma points
    Jul 06, 2016 @ 18:12
    Ben McKean
    0

    Hi Rusty

    I managed to get it work by just using my Model (IProductContent) for product related properties and then done a Model.As

    Ditto does indeed return the ProductContentListView.

    Think thats the right way to go :)

    Thanks

    Ben

Please Sign in or register to post replies

Write your reply to:

Draft