1

I'm trying to update the option values of an existing product custom option.

This is the code I've developed:

$product = Mage::getModel("catalog/product")->load($productId);
$titolo = 'Test';
$prezzo = 123.00;
foreach ($product->getOptions() as $custom_option) {
    if (self::CUSTOM_OPTION_TITLE == $custom_option->getTitle()) {
        $custom_option_values = $custom_option->getValues();
        $values = array();
        foreach($custom_option_values as $custom_option_value)
        {
            if($custom_option_value["sku"] == $skuOpzione) {

                $values[$custom_option_value->getId()]['option_type_id']= $custom_option_value->getId();
                $values[$custom_option_value->getId()]['option_id']= $custom_option_value->getOptionId();
                $values[$custom_option_value->getId()]['default_title']= $titolo;
                $values[$custom_option_value->getId()]['store_title']= $titolo;
                $values[$custom_option_value->getId()]['title']= $titolo;
                $values[$custom_option_value->getId()]['default_price']= floatval($prezzo);
                $values[$custom_option_value->getId()]['default_price_type']= 'fixed';
                $values[$custom_option_value->getId()]['store_price']= floatval($prezzo);
                $values[$custom_option_value->getId()]['store_price_type']= 'fixed';
                $values[$custom_option_value->getId()]['price']= floatval($prezzo);
                $values[$custom_option_value->getId()]['price_type']= 'fixed';

                $custom_option_value->setValues($values);
                $custom_option_value->saveValues();
            }
        }

        $product->save();
    }
}

All seems to work fine but when I check the product I see 'Title' updated but not the 'Price'. Why?

  • have you a result? I have this Problem, too :-( Dave – David Apr 13 '18 at 9:10
  • I don't know if it can still be useful but it's necessary set: $custom_option_value->setStoreId('0'); – Shaibon May 20 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.