简体   繁体   中英

how to change custom option price by query in magento?

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.

请看图片

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

Try the below code with your file in root folder

<?php

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();

$product = Mage::getModel('catalog/product')->load($product_id);
$values  = array();

foreach ($product->getOptions() as $o) {

   $p = $o->getValues();

   foreach($p as $v) {

       $id = $v->getId();

       $values[$id]['option_type_id']= $v->getId();
       $values[$id]['title']= 'test';
       $values[$id]['price']= 'your_price';
       $values[$id]['price_type']= 'fixed';
       $values[$id]['sku']= $value1;
   }

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

$product->save();

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM