London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!


Oct 5, 2011
  4646
(4 votes)

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

Oct 05, 2011

Comments

Oct 5, 2011 03:49 PM

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 :-)

Oct 6, 2011 04:56 PM

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?

Oct 7, 2011 10:35 AM

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

Oct 18, 2011 04:46 PM

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 comment.
Latest blogs
Optimizely Frontend Hosting Beta – Early Thoughts and Key Questions

Optimizely has opened the waitlist for its new Frontend Hosting capability. I’m part of the beta programme, but my invite isn’t due until May, whil...

Minesh Shah (Netcel) | Apr 23, 2025

Developer Meetup - London, 21st May 2025

The London Dev Meetup has been rescheduled for Wednesday, 21st May and will be Candyspace 's first Optimizely Developer Meetup, and the first one...

Gavin_M | Apr 22, 2025

Frontend hosting for PaaS & SaaS CMS

Just announced on the DXP, we FINALLY have a front end hosting solution coming as part of the DXP for modern decoupled solutions in both the PaaS a...

Scott Reed | Apr 22, 2025

Routing to a page in SaaS CMS

More early findings from using a SaaS CMS instance; setting up Graph queries that works for both visitor pageviews and editor previews.

Johan Kronberg | Apr 14, 2025 |

Developer Meetup - London, 24th April 2025

Next Thursday, 24th April will be Candyspace 's first Optimizely Developer Meetup, and the first one held in London this year! We've have some...

Gavin_M | Apr 14, 2025

Successful Digitalization for SMEs: How Optimizely One can Revolutionize Your Business Processes

"Achieve digital excellence with Optimizely One: Boost efficiency, delight customers, secure growth." In today's digital world, it's crucial for...

Frank Hohmeyer | Apr 11, 2025