Magento – updating the value of custom options

custom-optionsPHP

I'm having an issue with updating the price on custom options. The code that I'm using is

$options = $product->getProductOptionsCollection();
foreach( $options as $option ){
    $values = $option->getValuesCollection();
    foreach( $values as $value ){
        $value->setTitle("test")
        ->setSku("testsku")
        ->setPrice(23.00);
        $value->save();
    }
}
$product->save();

Right now I'm just using this as a test. The strange thing is that the sku, the title and other options like sort order that I had in there before would save fine, but the price will not. Do I need to do something specific for the price to save? Why would everything else update, but the price wont? Thanks for your help.

Best Answer

I think you want to hook int \Mage_Catalog_Model_Resource_Product_Option_Value::_saveValuePrices and check whether the conditions for the saving are met. The code looks right.

if (!$object->getData('scope', 'price')) {

....

if ($object->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE
        && !$object->getData('scope', 'price')) {

...

} else if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE && $object->getData('scope', 'price')) {
Related Topic