Can somebody please provide me with an example of how to add variants to the Teacommerce Variant Editor programmicaly?
We have a setup where we create new product via the Umbraco ContentService, but we also need to add product variants programmicaly, how can we do that?
The variants is just a normal Umbraco property editor. You can create a variant using Umbraco backoffice, go to the DB and see the JSON structure of the variant and then mimic that when you import. You still need to call SetStock for your products and variants.
We have not made a function to import the variants as its just Umbraco JSON content. I can see it would be a bit easier to import using an API, but until that, you will have to use the Umbraco API and set content using the content service as you would normally do with properties.
The id is just a guid generated by the java script that generates the variant combinations. So you can just generate some id's. The id is used when you add a variant to the cart.
Hope you share the code that you are making - it might be great for others to see this as well :)
Create variants programmicaly (Tea Commerce)
Hi
Can somebody please provide me with an example of how to add variants to the Teacommerce Variant Editor programmicaly?
We have a setup where we create new product via the Umbraco ContentService, but we also need to add product variants programmicaly, how can we do that?
Hi Carsten
The variants is just a normal Umbraco property editor. You can create a variant using Umbraco backoffice, go to the DB and see the JSON structure of the variant and then mimic that when you import. You still need to call SetStock for your products and variants.
Kind regards
Anders
Hi Anders
So there is no official function to do this, I have to copy the behavior of Umbraco backoffice?
We have not made a function to import the variants as its just Umbraco JSON content. I can see it would be a bit easier to import using an API, but until that, you will have to use the Umbraco API and set content using the content service as you would normally do with properties.
Hi Anders
I have a little trouble figuring out where the id property comes from - I mean, where does:
"id": "1628e2d8-a159-6642-0d1e-af9a94a3ceae" "id": "fd4b6488-c32f-e5d9-3e37-af4ba0911768"
in the below json come from? What does they refer to?
{ "variants": [ { "id": "1628e2d8-a159-6642-0d1e-af9a94a3ceae", "documentTypeAlias": "Variant", "validation": { "holesInVariants": false, "duplicatesFound": false }, "properties": { "stock": "", "productName": "", "sku": "", "priceDKK": "" }, "combination": [ { "name": "20", "id": 1086, "groupName": "Størrelse", "groupId": 1081 } ] }, { "id": "fd4b6488-c32f-e5d9-3e37-af4ba0911768", "documentTypeAlias": "Variant", "validation": { "holesInVariants": false, "duplicatesFound": false }, "properties": { "stock": "", "productName": "", "sku": "", "priceDKK": "" }, "combination": [ { "name": "22", "id": 1087, "groupName": "Størrelse", "groupId": 1081 } ] } ], "variantGroupsOpen": { "1081": true } }
Hi Carsten
The id is just a guid generated by the java script that generates the variant combinations. So you can just generate some id's. The id is used when you add a variant to the cart.
Hope you share the code that you are making - it might be great for others to see this as well :)
Kind regards
Anders
is working on a reply...