I am looking to create complex product variants from code using CMS Import. So far I have the CMS Import part down pat but I was curious how to go about mapping a Preset to attributes.
For example, if I have a Glove Size Preset, I would want to put the attributes I programmatically create under the Glove Size Preset.
How does this structure determine the preset it applies too?
I understand the structure and how the Guids relate etc. but am concerned how to relate the attributes I create relate to a Preset if that makes sense?
I know this is sort of unexplored terrain at this point and meshing two systems can be tedious but I have successfully mapped a CSV price value to a Vendr.Price data type successfully, so progress is progress.
Thanks for your continued effort with all of the recent questions.
Really nice work on getting this CMSImport stuff working. I'd be REAALY interested to see this when it's all done.
Regarding presets, there really isn't any linkage between the variants and the preset to track, rather presets are just pre-defined filters used by the UI when you create your variant so it will just limit the number of attributes you can pick from. The only linkage a variant has is with the attributes themselves so that's really all you need to worry about.
I posted this also over in the CMS Import - Using the API support forum, but here you go.
Like I said it is fairly generic.
Put the .cs file in your controllers folder of your solution, obviously make sure it builds and compiles
Start an Import in CMS Import
The Parse method should get hit by a breakpoint when you put one in the method
You should also be careful to make sure the class inherits from an IFieldProvider so that CMS Import knows what its working with. Hope that makes sense
Here is the Attribute Declaration for the entirety of the class (this tells CMS Import to only fire this when we come across a Price cell from a CSV File) This needs to be the datatype your putting values into, hence Vendr.Price
Here is the Parse Method (Responsible for data processing)
public object Parse(object value, ImportPropertyInfo property, FieldProviderOptions fieldProviderOptions)
{
//create new decimal to hold value
var price = new Decimal();
//if value is blank in your source file (I used CSV) then compensate for that and place a value you
//would know into the price field so you can either manually change it or account for it in some way
if (value != null && value.AsString() != "")
{
price = Decimal.Parse(value.AsString());
}
else
{
price = Decimal.Parse("1234.56");
}
//create the data structure you need to send the data in
//in the case of Vendr.Price you need { currencyId guid (found in back office) , price value from source file }
var data = new Dictionary<string, decimal> {
{ "05c1c00a-fd2d-41f9-b5af-017d7c739f60", price }
};
//serialize the data and return the value - done
return JsonConvert.SerializeObject(data);
}
Following up here...I have the raw data formatted and being recieved by CMS Import all the way until it tries to map my Variant Editor block style code to the field...
I wanted to check if this was accurate...
I have a field in umbraco called Product Variants, which is of the Data Type Vendr.VariantsEditor.
Now the way you tell CMS Import to look for a specific field and prepare the data is to use something like this:
Hmm, the alias is correct, but I'm not sure what the error there is, that might be one for Richard.
Just on another point, the variants property on your doctype need to be named variants so you might want to change that, but I don't believe this is your problem here.
Lol Gave me a good laugh as that’s what I used to see if I needed to name it something specific. I understand why it needs to be that specific, just wasn’t aware to make it that Alias.
Create Complex Variants from code
Matt,
I am looking to create complex product variants from code using CMS Import. So far I have the CMS Import part down pat but I was curious how to go about mapping a Preset to attributes.
For example, if I have a Glove Size Preset, I would want to put the attributes I programmatically create under the Glove Size Preset.
How does this structure determine the preset it applies too?
}
I understand the structure and how the
Guids
relate etc. but am concerned how to relate the attributes I create relate to a Preset if that makes sense?I know this is sort of unexplored terrain at this point and meshing two systems can be tedious but I have successfully mapped a CSV price value to a Vendr.Price data type successfully, so progress is progress.
Thanks for your continued effort with all of the recent questions.
Hi Kyle,
Really nice work on getting this CMSImport stuff working. I'd be REAALY interested to see this when it's all done.
Regarding presets, there really isn't any linkage between the variants and the preset to track, rather presets are just pre-defined filters used by the UI when you create your variant so it will just limit the number of attributes you can pick from. The only linkage a variant has is with the attributes themselves so that's really all you need to worry about.
Looking forward to see how this goes
Matt
Matt, so if I’m understanding correctly as long as I create my stuff with the correct attribute aliases and such everything should line up?
I have been talking with Richard so I think between the experience you two hold I can get this working…
Hey Kyle,
That's correct yes. So long as the aliases match, you should be good 👍
Glad we can work together to get you there 😁
Matt
Awesome,
I’ll get started on it and let you know if I come across any hiccups.
I am genuinely surprised no one has traveled down this road prior as it seems like something that could be really useful.
Thanks Matt, I will keep in touch
Matt,
One more thing, if you want the field provider code for a Vendr.Price let me know. It’s fairly generic as I am using a CSV file right now
I’d be happy to provide it.
Definitely 👍
Matt,
I posted this also over in the CMS Import - Using the API support forum, but here you go.
Like I said it is fairly generic.
.cs
file in your controllers folder of your solution, obviously make sure it builds and compilesParse
method should get hit by a breakpoint when you put one in the methodYou should also be careful to make sure the class inherits from an
IFieldProvider
so that CMS Import knows what its working with. Hope that makes senseHere is the Attribute Declaration for the entirety of the class (this tells CMS Import to only fire this when we come across a Price cell from a CSV File) This needs to be the datatype your putting values into, hence Vendr.Price
Here is the Dependiency Injection of the Umbraco Content Service if needed
Here is the Parse Method (Responsible for data processing)
Let me know if you need anything else
Matt,
Following up here...I have the raw data formatted and being recieved by CMS Import all the way until it tries to map my Variant Editor block style code to the field...
I wanted to check if this was accurate...
I have a field in umbraco called Product Variants, which is of the Data Type
Vendr.VariantsEditor
.Now the way you tell CMS Import to look for a specific field and prepare the data is to use something like this:
I have price working in a similar fashion, just cant get the VariantEditor to work as such.
Thanks
Hmm, the alias is correct, but I'm not sure what the error there is, that might be one for Richard.
Just on another point, the variants property on your doctype need to be named
variants
so you might want to change that, but I don't believe this is your problem here.Matt
What does changing my alias from “Product Variants” to “Variants” actually do in terms of Vendr?
I’ll change my property alias, to conform, just curious what it does when having that alias?
Is that what you look at to display the variants in the back office?
Thanks.
Hi Kyle,
It's just that's the property alias we assume for the variants editor as we will have to look up the value at various points.
You can review the docs here for a list of properties that can be defined on an Umbraco node and what Vendr expects their alias to be https://vendr.net/docs/core/2.0.0/umbraco-v9/key-concepts/umbraco-properties/
Matt
Lol, actually just reliased
variants
isn't on that list 🤦♂️ Something for me to fix in the new year 😁Matt,
Lol Gave me a good laugh as that’s what I used to see if I needed to name it something specific. I understand why it needs to be that specific, just wasn’t aware to make it that Alias.
It’s all good
Hi Kyle,
I'm bumping your thread a couple of years later.
I'm really interested in knowing if you managed to make the import work with the complex variants.
is working on a reply...