I just don't get it. I have installed Magento CE in my site.

But when I run following code as custom script from root directory, it doesn't set product custom option value price to my desired value, $v->setPrice is not working at all, while the other value functions do work, why is that ??

$magePath = 'app/Mage.php';
require_once $magePath;
ini_set('display_errors', 1);
$product_ids  = array(897);
$productmodel = Mage::getModel('catalog/product');
foreach ($product_ids as $product_id) {
    /**i use this two arrays for collecte value because i uses inside setData of 
    current option*/
    $cos     = array();
    $co      = array();
    $product = $productmodel->load($product_id);
    $options = $product->getProductOptionsCollection();
    if (isset($options)) {
        foreach ($options as $o) {
            $title = $o->getTitle();
            $optionType = $o->getType();
            //test type
            if ($optionType == "drop_down" && $title == "New Custom Title") {
                //getting collection of value related to current option
                $values = $o->getValuesCollection();
                $found  = false;
                foreach ($values as $k => $v) {
                    //test existing of value for update
                    if (1 == preg_match("/Ja$/i", $v->getTitle())) {
                        //update and save
                        this ligne is important i collecte all value required for normalize save function 
                        related to current option
                        $cos[] = $v->toArray($co);
            $o->setData("values", $cos)->save();

1 Answer 1


You need to set Store Id before saving option value price and title. This line will resolve your problem: $v->setStoreId('0'); Enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.