Posted on 08/05/2018 06:23:02
Hi Adrian,
For ItemCreator related documentation you asked you can look here - https://doc.dynamicweb.com/api/html/fa78dc65-fe4b-192f-bf93-db50d205750d.htm
For Api example to modify selected product in item field type of product you can use something like this:
using System.Collections.Generic;
using System.Linq;
class ItemWithProductFieldExample
{
public ItemWithProductFieldExample() { }
private const string productItemPrefix = "p_";
private const string productVariantSeparator = ":";
public void addProduct(List<string> productItems, string productId, string variantId)
{
if (!string.IsNullOrWhiteSpace(productId))
{
productItems.Add($"{productItemPrefix}{productId}:{variantId}");
}
}
public void deleteProduct(List<string> productItems, string productId, string variantId)
{
if (!string.IsNullOrWhiteSpace(productId) && productItems.Count > 0)
{
var productItemToDelete = $"{productItemPrefix}{productId}";
if (!string.IsNullOrWhiteSpace(variantId))
{
productItemToDelete = $"{productItemToDelete}:{variantId}";
}
for(var i = productItems.Count-1; i>=0;i--) {
if (productItems[i] == productItemToDelete || productItems[i] == $"{productItemToDelete}:") {
productItems.RemoveAt(i);
}
}
}
}
public void main()
{
var item = Services.Items.GetItem("SelectorFields", "1"); //"SelectorFields" - itemtype system name; "1" - item id
string fieldValue = item["Product"].ToString(); //"Product" - field system name
var productFieldItems = fieldValue.Split(',').ToList();
//add product to item field
addProduct(productFieldItems, "PROD34", "");
//delete product to item field
deleteProduct(productFieldItems, "PROD34", "");
item["Product"] = string.Join(",", productFieldItems);
item.Save();
}
}
BR, Viktor.