i have a product with custom options (the fields are not required). When the customer has put the product in the cart he should have the possibility to set the custom options for the product in the cart.
Following solution helps me to make this possible: How to programmatically set a customizable Option in magento2?
I have only one problem: If the user has not selected an option on the product view, the solution of @skymeissner does not work. I can set the option for the quote item but it got not saved.
have somebody any solution for this problem ?
UPDATE: I found out that it is required to save the itemoptions.
This must be placed after setting the option VALUE. But this does not work, cause the option "option_ids" got not saved. If I execute the code again, than it works like expected. Then I can change the value und every time I change it, it works like expected. Only the first time it doesn't work.
If you set it after "options_ids". The system will exit with following exception:
Fatal error: Uncaught Error: Call to a member function getValue() on null in /vendor/magento/module-catalog/Model/Product/Type/AbstractType.php on line 822.
This error occurs because the option "option_*" (the option value) got not saved.
Somebody any ideas ?