Magento 2 – Update Cart Custom Option Value

addtocartcustom-optionsmagento2quoteitemupgrade

Currently am using magento 2.2.5,

while adding the product to the cart the custom options values are stored in the quote_item_option table correctly.

while updating the custom options programmatically it has not changed in the quote_item_option table and doesn't throw any exception.

Please guide me with the proper solutions.

Best Answer

Without understanding what exactly you want to achieve with your change of option value: If you just want to modify the value of an already set option, I guess you can simplify your code in _saveCartItemEngravingOptionValue.

Remove the line $cartItem->setOptions($options)->save(); (the option is already in the cart item) and just call save on the specific option object:

$option->setValue(...)->save();

That should save the changes if you get into that part of the code (I would suggest to add some logging to your code, to see if that is the case).

Related Topic