Skip to content

Instantly share code, notes, and snippets.

@VIVEKLUCKY249
Created February 17, 2017 20:51
Show Gist options
  • Save VIVEKLUCKY249/f02c531737d5dce8d811a3011fd14aa3 to your computer and use it in GitHub Desktop.
Save VIVEKLUCKY249/f02c531737d5dce8d811a3011fd14aa3 to your computer and use it in GitHub Desktop.
<?php
$magePath = 'app/Mage.php';
require_once $magePath;
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
error_reporting(E_ALL);
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product_ids = array(1004);
$productmodel = Mage::getModel('catalog/product');
foreach ($product_ids as $product_id) {
$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 == "Go ahead ?") {
//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
$v->setTitle("Ja")->setSku("Vivek")->setPriceType("fixed")->setSortOrder(2)->setPrice(floatval(300.0000));
$v->setStoreId(0);
$v->setOption($o)->save();
$cos[] = $v->toArray($co);
}
}
}
$o->setData("values", $cos)->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment