David, thank you. I've found the API documention yesterday after posting the question but it doesn't seem to work. I've checked the SKUIDs many times, they are correct, the cartItemParams object looks correct as well, but when I call shoppingService.AddItemToCart(cartItemParams) nothing gets added to the cart and the method returns null.
After digging through the Ecommerce module code of the CMS itself, I noticed, that instead of using the parent SKUID and the option SKUIDs list (like it implies in the documention), Kentico uses the variant SKUID and only puts the options of type Products into the list (in my case only one of the options).
// The optionId list includes no attributes and I use the variantSkuId
var options = optionIds.Select(c => new ShoppingCartItemParameters{ SKUID = c }).ToList();
var cartItemParams = new ShoppingCartItemParameters(variantSkuId, quantity, options);
ShoppingService.AddItemToCart(cartItemParams);
Strangly, I also have to convert the List<int>
to List<ShoppingCartItemParameters>
. If I pass the list of SKUIDs directly to new ShoppingCartItemParameters(...)
the ProductOptions list property of cartItemParams
will be empty. It seems to ignore the list of option SKUIDs. However, when I use List<ShoppingCartItemParameters>
it works.
So this works now :). I was happy when I found the API documention but I think it was misleading. I had no luck getting it to work with options of type Attribute and with the List<int>
. Maybe it's a bug, I don't know. I was surprised that Kentico itself does it different (see method GetShoppingCartItemParameters() in ShoppingCartItemSelector.ascx.cs ).
I have one more question. Is it possible to use different quantities for products and product options? Let's say I order 1000 resistors and want them shipped as tape and reel. I this case my quantity of 1000 resistors would have 1 quantity of the tape and reel option. If the tape and reel can only hold 1000 parts, I will need 2 tape and reel options for 2000 resistors. I noticed, whenever I change the quantity of the product, the quantity of the option gets updated automatically. Is it somehow possible to modify the calculation of the option quantity?