Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Umbraco v7.4.2, TC v3.1.1
I have added 2 checkboxes (True/False) to my Variant DocType, but when I try to access the value, it always returns false:
variant.GetPropertyValue<bool>("currentlyUnavailable")
Where "variant" is of type VariantPublishedContent.
I have a number of Textstring fields and they work, I also have a dropdown and that works - but the checkboxes don't. Am I doing something wrong?
What happens if you just call GetPropertyValue without the generic type?
GetPropertyValue
The same result - always false (actually 'False')
variant.GetPropertyValue("currentlyUnavailable")
Are you able to look into the cmsPropertyData DB table and try and find the stored value? It'll be interesting to see if it's a problem saving it, or a problem retreiving it.
cmsPropertyData
In the Variant JSON, it is stored as
"currentlyUnavailable": "1",
Ok, so it is being stored ok. And does it all work ok in the back office? it remembers the value etc when you move to and from a product?
Yes, the back office works OK.
I have managed to get the data value by overriding the Variant class (ModelsBuilder):
[ImplementPropertyType("currentlyUnavailable")] public bool CurrentlyUnavailable { get { var rawVal = Properties.FirstOrDefault(t => t.PropertyTypeAlias == "currentlyUnavailable"); if (rawVal == null) return false; return (rawVal.DataValue.ToString() == "1"); } }
Which is OK, but it just means I have to create a Variant object just to get the value of the checkboxes.
Ahh, ok, so this is via ModelsBuilder. How are you actually getting your variant? I'm intregued how you are actually using it with ModelsBuilder 🤔
I get all variants for the product using
var variants = TC.GetVariants(storeId, productPage).ToList();
then loop through using
foreach (var variant in variants)
Currently, I need to create a Variant
var varRecord = new Variant(variant);
(although I could have the previously mentioned code in-line, I suppose)
So, the first version works but the second doesn't
var unavail = varRecord.CurrentlyUnavailable; var unavail = variant.GetPropertyValue<bool>("currentlyUnavailable");
In the end, what I have now is working and looks cleaner, but TC does appear to have a problem getting the value for a checkbox.
Strange. I'll try and replicate it this evening and see what I can find.
Typical. I've just tested this on my local demo install (Umbraco 7.12.4 though) and this worked as it should.
Add checkbox to variants doctype
Add property to variants data type as extra info
Set values on variants
Loop through variants in template
Output values of onSale property to screen
Yes, typical indeed! At least I have a method for making it work, so I'll carry on with that.
Thanks for your help.
No problem. Sorry I couldn't track it down for you, but glad you at least have a workaround.
I think this might be something to do with the version of ModelsBuilder that's being used, and how the core ValueConverters have changed.
Your override should work fine on this occasion, and is something I've done myself on legacy umbraco sites.
v7.4.2 is quite an old version of Umbraco :-)
Further more... this might be insightful
https://issues.umbraco.org/issue/U4-9925
Also, Looking at the docs, V7.4.2 is where the True/False with a default value option was introduced - so likely to have been buggy :-)
https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/true-false
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Checkboxes on Variants
Umbraco v7.4.2, TC v3.1.1
I have added 2 checkboxes (True/False) to my Variant DocType, but when I try to access the value, it always returns false:
Where "variant" is of type VariantPublishedContent.
I have a number of Textstring fields and they work, I also have a dropdown and that works - but the checkboxes don't. Am I doing something wrong?
What happens if you just call
GetPropertyValue
without the generic type?The same result - always false (actually 'False')
Are you able to look into the
cmsPropertyData
DB table and try and find the stored value? It'll be interesting to see if it's a problem saving it, or a problem retreiving it.In the Variant JSON, it is stored as
Ok, so it is being stored ok. And does it all work ok in the back office? it remembers the value etc when you move to and from a product?
Yes, the back office works OK.
I have managed to get the data value by overriding the Variant class (ModelsBuilder):
Which is OK, but it just means I have to create a Variant object just to get the value of the checkboxes.
Ahh, ok, so this is via ModelsBuilder. How are you actually getting your variant? I'm intregued how you are actually using it with ModelsBuilder 🤔
I get all variants for the product using
then loop through using
Currently, I need to create a Variant
(although I could have the previously mentioned code in-line, I suppose)
So, the first version works but the second doesn't
In the end, what I have now is working and looks cleaner, but TC does appear to have a problem getting the value for a checkbox.
Strange. I'll try and replicate it this evening and see what I can find.
Typical. I've just tested this on my local demo install (Umbraco 7.12.4 though) and this worked as it should.
Add checkbox to variants doctype
Add property to variants data type as extra info
Set values on variants
Loop through variants in template
Output values of onSale property to screen
Yes, typical indeed! At least I have a method for making it work, so I'll carry on with that.
Thanks for your help.
No problem. Sorry I couldn't track it down for you, but glad you at least have a workaround.
I think this might be something to do with the version of ModelsBuilder that's being used, and how the core ValueConverters have changed.
Your override should work fine on this occasion, and is something I've done myself on legacy umbraco sites.
v7.4.2 is quite an old version of Umbraco :-)
Further more... this might be insightful
https://issues.umbraco.org/issue/U4-9925
Also, Looking at the docs, V7.4.2 is where the True/False with a default value option was introduced - so likely to have been buggy :-)
https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/true-false
is working on a reply...