updating BasketItem custom fields
Posted: Thu Aug 26, 2010 5:45 pm
Hi, We are utilizing the BasketItem.CustomFields feature to save additional personalization data the customer provides for us when adding a product to the cart. We need to be able to update the key/string value. I don't see an update method so I've been using the Remove method and then re-adding using Add. This doesn't seem to do the trick since I get an error saying that the 'key already exists. Any thoughts? I couldn't find much documentation on the customFields API.. Judging from the boards, this seems to be a recent feature?
Here's our code:
//check if custom field exists in the database
BasketItem dbCurrentBasketItem = BasketItemDataSource.Load(_basketItemID);
if (dbCurrentBasketItem.CustomFields.ContainsKey(fieldname))
{
dbCurrentBasketItem.CustomFields.Remove(fieldname);
dbBasketItem.Save();
}
//now re-add the updated key/string combo
item.CustomFields.Add(fieldname, b_filename);
item.Save();
Here's our code:
//check if custom field exists in the database
BasketItem dbCurrentBasketItem = BasketItemDataSource.Load(_basketItemID);
if (dbCurrentBasketItem.CustomFields.ContainsKey(fieldname))
{
dbCurrentBasketItem.CustomFields.Remove(fieldname);
dbBasketItem.Save();
}
//now re-add the updated key/string combo
item.CustomFields.Add(fieldname, b_filename);
item.Save();