I am listening to the sales_quote_save_before event to notice when an item is added to the cart. Once its fired, I iterate through the items options like this:
$quote = $observer->getEvent()->getQuote();
foreach ($quote->getAllItems() as $item) {
$options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
foreach($options['options'] as $option) {
if($option['label'] == 'myOptionA') {
// Here I want to change the selected value for the option
}
}
}
As you see, as soon as a certain option (myOptionA in the example) is reached, I want to change the selected option. So lets say myOptionA is a drop down and has 4 possible values. In case value 1 is selected, I want to set value 4 for that item. So when the cart is finished loading it should have value 4 for myOptionA. Not just its name, but its price as well. How could I do that?