I have 32000 products in Magento,

When I added them I have set custom option attribute to products they work perfectly, but now I want to change the price of custom option attribute of all products.

enter image description here

Is there any way to change price by query or any other tricks ??

1 Answer 1


$magePath = 'app/Mage.php'; 

require_once $magePath;



ini_set('display_errors', 1);



$product_ids = array(2);
//Product Id = 2, you can use any product id
$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*/


$product = $productmodel->load($product_id);

$options = $product->getProductOptionsCollection();

if (isset($options)) { 

foreach ($options as $o) { 

$title = $o->getTitle();

this block is for changing information of specific option from collection options inside
current product
the save method for this option in end of code

if ($title == "Line 1/Front") { 


$o->setTitle("Line 1/Ftont"); 





this block for update or add information of specific value inside current option

$optionType = $o->getType(); 

//test type

if ($optionType == "drop_down") { 

//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("/said$/i", $v->getTitle())) { 

//update and save







this ligne is important i collecte all value required for normalize save function 
related to current option



create new value object you can use $option->getValueInstance() for working with 

$value = Mage::getModel('catalog/product_option_value'); 







this ligne is important (relation forigien key) for related this new value
to specific option



this ligne is important i collecte all value required for normalize save function   
related to current option





  • where i have to put this code ?? and $values[$v->getId()]['price']= 23; what is 23 here can you explain me please ?
    – dp4solve
    Jul 28, 2014 at 7:39
  • You can do it programmatically if you wish too, by putting the file on root: <?php require_once('app/Mage.php'); //Path to Magento umask(0); Mage::app(); Jul 28, 2014 at 7:41
  • Update my answer now the file will work on root Jul 28, 2014 at 7:42
  • $values[$v->getId()]['price']= 23 what is 23 here ??
    – dp4solve
    Jul 28, 2014 at 7:42
  • I have updated my code copy a paste this on root, and check your product whose product id is passed in it. First create a test product and hit the file url so that you can understand better Jul 28, 2014 at 7:51

Your Answer

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

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