Related Data for product variants

Posted by Community Admin on 05-Aug-2018 12:39

Related Data for product variants

All Replies

Posted by Community Admin on 28-Jan-2016 00:00

I have a given scenario and I am wondering how this could be structured in the Sitefinity eCommerce module.

I essentially have two product types, a full product and spare part. As expected spare parts relate to full products and some spare parts can relate to different full products.

I have modeled this structure in Sitefinity fine using a Related Data property on the full product with the ability to select multiple spare parts per product.

My issue arises when I create variants of the full product and the main variant attribute is essentially the design print on the full product. I need to be able to associate a spare part to a specific variant, an example being a replacement cover that has the specific design print on so can only ever be associated with a variant of a full product. So in effect I just need a Related Data property against the variant rather than the product itself if that makes sense.

Is this possible out of the box in Sitefinity? If not, can I structure my product / spare parts in manner that I can query spare parts on a variant basis? Or do I need to model this outside of Sitefinity?

Thanks.

PS I am fairly new to Sitefinity development so if there is anything I could have missed please let me know.

Posted by Community Admin on 02-Feb-2016 00:00
Hello Brett,

You can select image or images for the product variation, for the specific product (Product -> Variations). This is available out of the box.
If you want to add a custom field to the product attribute (Ecommerce -> Attributes), this will require custom implementation.
Let me know if you want to add an image field to the Product Attribute.

Regards,
Nikola Zagorchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
Posted by Community Admin on 02-Feb-2016 00:00

Hi Nikola,

I guess my problem closely resembles that to which you can add images to specific product variations or 'product attributes' as you describe them. So rather than selecting images how can I select a collection of another product type (in my case spare parts) to relate directly to a product attribute.How would I go about putting in a custom implementation for this functionality?

Thanks

 

 

Posted by Community Admin on 02-Feb-2016 00:00

Since my previous post I've in some respect managed to model this via the advanced settings for ProductVariationsBackendDefinition.

So now I can select the 'spare part' product type as part of the properties for a product variant,but now whenever I do, I get a script error suggesting a null argument exception.

I've attached the error being given on the product variant property view and the settings I created to configure the RelatedDataField on the view.

Can you suggest why I may be getting the script error?

Thanks,

Posted by Community Admin on 03-Feb-2016 00:00
Hi Brett,

The easiest way to achieve adding an image field to the product attributes is the following:

Create a custom field for the type using the MetaDataManager, so we can persist the data in the database:
var metadataManager = MetadataManager.GetManager();
           var dynamicType = metadataManager.GetMetaType(typeof(ProductAttributeValue));
           if (dynamicType == null)
               dynamicType = metadataManager.CreateMetaType(typeof(ProductAttributeValue));
 
           var fields = dynamicType.Fields.Where(f => f.FieldName == "ImageUrl").ToList();
           if (fields.Count == 0)
           
               var metaField = metadataManager.CreateMetafield("ImageUrl");
               metaField.DBSqlType = "NVARCHAR(100)";
               metaField.DBType = "LONGVARCHAR";
               metaField.ClrType = typeof(string).FullName;
               metaField.Parent = dynamicType;
               dynamicType.Fields.Add(metaField);
 
               metadataManager.SaveChanges(true);
           

Go to Advanced settings -> Content View -> Controls -> ProductAttributeValueBackendDefinition -> Views -> ProductAttributesValuesBackendEdit -> Sections -> MainSection -> Fields, create new ImageFieldElement. Set the DataFieldName and FieldName to ImageUrl (the metafield name). Set the DisplayMode to Write.
Do the same for the ProductAttributesValuesBackendInsert.

This way you are able to add an image to the product attribute. The field saves the image Url. The above implementation is the one that can be achieved using out of the box functionality and field control.
For related media/data fields a much more complicated metadata mapping should be done, as well as, changes to the service that persists the values for the product attribute.

Hope this helps.

Regards,
Nikola Zagorchev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 
Posted by Community Admin on 04-Feb-2016 00:00

Hi Nikola,

Thanks for the code snippet, but I think my problem does require an implementation for Related Data fields, so can you indicate where I may be able to find help in creating the metadata mapping and the changes to the service that persists the values.

I'm not sure if you saw my previous post but I mentioned building the relationship via the backend settings screens and managed to get some form of success but I get a script error when I try to choose using the product selector.

Thanks,

Brett

This thread is closed