Magento CE 1.7.0.2 – Uncaught Exception ‘Mage_Core_Exception’ with Message ‘Select Type Options Required Values Rows’

ce-1.7.0.2custom-options

I'm trying to add a drop_down custom option to my products and am apparently forgetting an element in the array for options. I tried adding value and values but neither remove the error:

Uncaught exception 'Mage_Core_Exception' with message 'Select type
options required values rows.'

This is what I have so far:

require_once 'app/Mage.php';
Mage::app('default');


$productIds = array(29);

$option = array(
    'title' => 'Test Option',
    'type' => 'drop_down',
    'sort_order' => 1,
    'values' => 230, // not working!
    'is_require' => 1,
    'price' => 10,
    'price_type' => 'fixed',
    'sku' => 'testsku'
);

foreach ($productIds as $productId) {
    $product = Mage::getModel('catalog/product')->load($productId);
    $optionInstance = $product->getOptionInstance()->unsetOptions();

    $product->setHasOptions(1);
    if (isset($option['is_require']) && ($option['is_require'] == 1)) {
            $product->setRequiredOptions(1);
    }
    $optionInstance->addOption($option);
    $optionInstance->setProduct($product);
    $product->save();
}

Does anyone see something wrong?

Best Answer

When creating a dropdown custom option you must specify the values and that must be an array.

So try with

$option = array(
    'title' => 'Test Option',
    'type' => 'drop_down',
    'sort_order' => 1,
    'values' => array(230), // this must be an array
    'is_require' => 1,
    'price' => 10,
    'price_type' => 'fixed',
    'sku' => 'testsku'
)