In this tutorial, you will learn how to fix the
MaxLength of the description property error when trying to import Episerver commerce products. I hit this error when trying to import product data into Episerver commerce. When creating a product in Episerver Commerce you will need to define a custom product class in code. This class will allow content editor to add the bespoke data unique to your products and varients within the editor. This custom product class will need to inherit from
EntryContentBase in order for it to work.
EntryContentBase defines a property of type
SeoInformation should be used to store the products pages meta data, e.g. the title, description and keywords..
SeoInformation has a max character limit in the database. During import some of our product data exceeded a limit on the SEO description field. I'm still a bit confused why there is such a small a cap on the SEO description field, however, we had to come up with a workaround.
One option would be to manually change the database limit in SQL. I think this solution is too dangerous as it could break APIs and future patches. Mapping an extra property on the product seemed like a good option, however, this would create a confusing and pretty naff solution for content editors. All the
SeoInformation properties would still be visible within the editor. This means the editors could potentially add in the data in the wrong place. A better experince would be hide the
SeoInformation properties so content editor would not get confused 🤔
In Episerver, we can use the
[ScaffoldColumn] attribute to hide things from the content editors. As
SeoInformation can't be removed from
EntryContentBase, it was the best option. In your product and variant definitions override
SeoInformation property and apply the
If you are an Episerver pro, you may be tempted to use the
[Ignore] attribute instead. Do not use this attribute, as Episerver will prevent content editors from publishing products. Using ,
[Ignore] will result in the following error:
Property with name 'SeoInformation' is not part of the ContentType definition
Now we have hidden
SeoInformation properties, the next step was to define my own SEO metadata properties on the product-type:
In the websites 'master' layout, I then used these properties to render the data in the pages
head section, instead of using the out-of-the box ones.
Be warned, due to a silly character limit in commerce, you may not be able to use the out of the box
SeoInformation object defined within
EntryContentBase. To get around this limitation we hide
SeoInformation from content editors using
[ScaffoldColumn] and create our own version. Happy Coding 🤘