November Happy Hour will be moved to Thursday December 5th.

How to add meta fields to Cart

Vote:
 

Guys, could you provide an example of configurations that allow meta fields "MetaField1" for ecommerce Cart object:

cart0["MetaField1"] = 5; //for example

As I understand I have to declare metafield somehow first to use it in application.

Thank you!

#88461
Jul 14, 2014 16:12
Vote:
 

Hi,

The answer of David is for the administration/manual approach. You can also do it programmatically, by those API:s

Mediachase.MetaDataPlus.Configurator.MetaField.Create(...)

Mediachase.MetaDataPlus.Configurator.MetaClass.AddField(MetaField,...)

Regards.

/Q

#88472
Jul 15, 2014 6:05
Vote:
 

David, Quan, thank you for the answers. David, yes, I have to do it via API. 

Quan, I have an issue related to Mediachase.MetaDataPlus.Configurator.MetaClass.AddField - it always adds row with SystemMetaClassId = 0 to MetaField table. But I need to specify the class (otherwise contraints exception about uniqe (Name, SystemMetaClassId) pair is thrown). But I haven't found any methods to specify SystemMetaClassId on creation. Maybe you can recommend something?

#88489
Jul 15, 2014 11:26
Vote:
 

Hi,

You don't have to specify SystemMetaClassId on creation. That should be done automatically. Can you post your code here?

Regards.

/Q

#88492
Jul 15, 2014 11:37
Vote:
 

var mc = MetaClass.Load(OrderContext.MetaDataContext, OrderConfiguration.Instance.MetaClasses.ShoppingCartClass.Name);

(...)

var metaField = MetaField.Create(MetaDataContext.Instance, metaFieldCreatingParam.Namespace, metaFieldCreatingParam.Name, metaFieldCreatingParam.FriendlyName, metaFieldCreatingParam.Description, metaFieldCreatingParam.MetaDataType, metaFieldCreatingParam.Length, metaFieldCreatingParam.AllowNulls, metaFieldCreatingParam.MultiLanguageValue, metaFieldCreatingParam.AllowSearch, metaFieldCreatingParam.IsEncrypted);


mc.AddField(metaField);

Should this code set SystemMetaClassId field? Possible field SystemMetaClassId is something obsolete, since MetaClassMetaFieldRelation table exists?..

#88494
Jul 15, 2014 11:46
Vote:
 

Yes, it should work. The relations between metaclasses and metafields are stored in MetaClassMetaFieldRelation, and I don't see any problem with your code. What's the error you got?

/Q

#88498
Jul 15, 2014 12:32
Vote:
 

There is no problems with the code if I don't have DisplayName in MetaField table yet, but there is problem that I have already metafiled with Name="DisplayName" and SystemMetaClassId = 0, but let's say it doesn't suit my purposes because of length. Can I create another metafield called "DisplayName" with another length? Is it possible? 

So could you please clarify conception a little: now all metafields in MetaField table are "globally" defined? I mean that for example if I need assign DisplayName field to some metaclass and this field already exists in MetaField table, should I use this existent field? I am not able to create another one with other parameters (like length, isNullable, etc) that fits the needs of some concrete metaclass, am I right?

#88500
Jul 15, 2014 12:45
Vote:
 

So why not just delete the old Display Name then create a new one? Having two meta fields with same name is not recommended.

Regards.

/Q

#88522
Jul 16, 2014 1:09
Vote:
 
#88542
Jul 16, 2014 14:04
Vote:
 

Quan, ok, understood. Thank you for the comments.

#88543
Jul 16, 2014 14:04
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.