Views: 2490
Number of votes: 4
Average rating:

ElencySolutions.MultipleProperty v1.2 Released

The ElencySolutions.MultipleProperty assembly provides a developer with the ability to easily create custom properties that are made up of other property types.  It allows the developer to create properties that are essentially lists of other property types.  This can be done by creating entity classes and decorating them with various MultipleProperty class level and property level attributes.

The properties offer features as drag and drop sorting, the ability to programmatically set property settings for entity properties, property copying, laying out properties within different tabs and various other features.

For more information please refer to previous blog posts that are linked to from here.  Very useful documentation can be found here.

The best way to get to grips with working with the base classes and attributes is to have a quick read of the documentation or to download the #example# and add it to the root of your EPiServer web application.  The example is dependent on PageTypeBuilder!

New Features in v1.2

  • The previous version did not work correctly with EPiServer Commerce.  This was because the various handlers used for commerce intercept most .aspx requests and were bypassing my custom VPP handler for embedded resources.  This has been fixed in this version.
  • A tab index can now be specified when create properties that have property definitions living under different tabs.
  • Issue with commerce and Product picker property fixed.  Basically the product picker inherits PropertyString but does not set the editor control so when ApplyEditChanges is called the property fell over.
  • Minor UI bug fixed.

Installation

The assembly is dependent on EPiServer CMS 6 and onwards.

The easiest way to install the assembly is to get it from the EPiServer nuget feed or you can download it from codeplex.

Example

A full code example can be download from here.  The example demonstrates how you could build an image gallery.  This is also covered in the documentation.

The example below demonstrates how you could create a property that would link to multiple commerce products for recommendations:

  1: namespace ClickAndTalk.CustomProperties
  2: {
  3:     using System;
  4:     using System.Collections.Generic;
  5:     using System.Runtime.Serialization;
  6:     using Mediachase.Commerce.Catalog;
  7:     using ElencySolutions.MultipleProperty;
  8:     using EPiServer.Business.Commerce.UI.Edit.ProductPicker.SpecializedProperties;
  9:     using EPiServer.PlugIn;
 10: 
 11:     [Serializable]
 12:     [PageDefinitionTypePlugIn(
 13:         DisplayName = "Product Recommendations property", 
 14:         Description = "Product Recommendations property - a collection of product recommendations")]
 15:     public class PropertyRecommendationCollection : MultiplePropertyBase<RecommendationCollection, Recommendation>
 16:     {
 17:         public override string GetListItemDescription(Recommendation entity)
 18:         {
 19:             if (entity == null)
 20:                 return string.Empty;
 21: 
 22:             string productId = entity.Product;
 23:             return CatalogContext.Current.GetCatalogEntry(productId).Name;
 24:         }
 25:     }
 26: 
 27:     [Serializable]
 28:     [CollectionDataContract]
 29:     [KnownType(typeof(RecommendationCollection))]
 30:     [MultiplePropertyEntity(
 31:         AddButtonText = "Add new recommendation", 
 32:         ListItemInformationHeader = "Recomendations")]
 33:     public class RecommendationCollection : List<Recommendation>
 34:     {
 35:         public override string ToString()
 36:         {
 37:             return MultiplePropertyHelper.SerializeObject(this);
 38:         }
 39:     }
 40: 
 41:     [Serializable]
 42:     [DataContract]
 43:     [KnownType(typeof(Recommendation))]
 44:     [MultiplePropertyEntity]
 45:     public class Recommendation
 46:     {
 47:         public Recommendation()
 48:         {
 49:             Product = string.Empty;
 50:         }
 51: 
 52:         [MultiplePropertyEntityProperty(Caption = "Product",
 53:             Type = typeof(ProductPickerProperty),
 54:             IsInformationProperty = true,
 55:             SortIndex = 100)]
 56:         [DataMember]
 57:         public string Product { get; set; }
 58: 
 59:     }
 60: }
 61: 
 62: 

When you add the Product Recommendations property to a page type in edit mode you will initially be shown the following:

When you click the "Add new recommendation” button an edit area will appear like the following:

You can then click the “Add” button and the recommendation will be added to the RecommendationCollection. An example is shown of how the properties will be shown when listed.

This is what the editing form will look like when you are editing one of the recommendations within the list:

The code below shows you how you would programmatically work with the property within the page the property has been added too.

  1: protected override void OnLoad(System.EventArgs e)
  2: {
  3:     base.OnLoad(e);
  4: 
  5:     ICatalogSystem catalogContext = CatalogContext.Current;
  6:     RecommendationCollection recommendations = CurrentPage["RecommendedProducts"] as RecommendationCollection;
  7:     IEnumerable<Entry> products = recommendations
  8:         .Select(current => catalogContext.GetCatalogEntry(current.Product));
  9: }

Feedback

Feedback as always is greatly received.  If there are bugs/issues please feel free to email or twitter me @croweman

    (By Allan Thræn , 05 October 2011 15:49, Permanent link)

    This is really nice, and it's something that's been on my todo for a long time, guess I can cross it over for now :-)

    (By Tahir Naveed , 06 October 2011 16:56, Permanent link)

    Do you have any idea, how this works with FindPagesWithCriteria or SearchDataSource. e.g. I have created a property containing an image alt text, and image url. Now will FindPagesWithCriteria searches for the image alt text?

    (By Lee Crowe , 07 October 2011 10:35, Permanent link)

    Hi Tahir

    When the entity objects the MutlipleProperty objects are working with are saved they are serialized to Xml.

    The only way FindPagesWithCriteria will return matches for the alt text will be if you have criteria with the following condition type CompareCondition.Contained. This will basically do a LIKE ‘%alt text%’ search against the database.

    Regarding the SearchDataSource, if you have enabled searching on the page definition property and your SearchDataSource is configured to search pages within the site it will also pick up the image alt text.

    Please bear in mind the following:

    SearchDataSource – This will find matches in all of the stored xml element values (PropertyData values) but will ignore attribute values which would be the desired functionality.

    FindPagesWithCriteria – Because this will do a wildcard search within an xml string you will also pull back matches in the xml structure e.g. element names, attribute values etc etc.

    Hope this helps?

    Lee

    (By Lee Crowe , 18 October 2011 16:46, Permanent link)

    I have had a few people ask whether MultipleProperty can be used with LinkCollections.

    It can indeed but you will need to decorate your entity class with the following class level attribute otherwise the DataContract serializer will fall over.

    [KnownType(typeof(PermanentLinkMapper))]

  Please login to post a comment