I can update existing cart values:
$item = $quote->getItemById($itemId);
$item->getOptionByCode('option_code')->setValue($value);
$item->saveItemOptions();
But this only works if the option already exists, e.g. an unchecked checkmark custom option will not be included in the item options when adding the product to cart. I tried adding the options with $item->addOption()
but that doesn't work because the option is not included in the $item->getProduct()->getCustomOptions()
, and trying to add the custom option there also modifies the actual product instead of just the cart item product.
Is there a way to add an existing custom option to an existing cart item without removing and re-adding the item?