title: Setting Magento dropdown (select) value for product
body: <p>I have created quite big import script which is importing products from CSV to magento. I have one remaining  issue to resolve. </p>
  
  <p>I use dropdowns for attributes. Unfortunately I can't set values for those attributes for a single product.
  What I did:</p>
  
  <ul>
  <li>created attribute set [php],</li>
  <li>added dropdown attribute with values to this set [php],</li>
  <li>added new product in proper attribute set and tried to set value for attribute I have created.</li>
  </ul>
  
  <p>I tried few methods, here is the <a href="http://scott.donnel.ly/magento-set-dropdown-attribute-value-of-a-product-add-option-if-not-present/" rel="noreferrer">one</a> looking good for me:</p>
  
  <pre><code>private function setOrAddOptionAttribute($product, $arg_attribute, $arg_value) {
      $attribute_model = Mage::getModel('eav/entity_attribute');
      $attribute_options_model = Mage::getModel('eav/entity_attribute_source_table');
  
      $attribute_code = $attribute_model-&gt;getIdByCode('catalog_product', $arg_attribute);
  
      $attribute = $attribute_model-&gt;load($attribute_code);
  
      $attribute_options_model-&gt;setAttribute($attribute);
      $options = $attribute_options_model-&gt;getAllOptions(false);
  
      // determine if this option exists
      $value_exists = false;
      foreach($options as $option) {
          if ($option['label'] == $arg_value) {
              $value_exists = true;
              break;
          }
      }
  
      // if this option does not exist, add it.
      if (!$value_exists) {
          $attribute-&gt;setData('option', array(
              'value' =&gt; array(
                  'option' =&gt; array($arg_value,$arg_value)
              )
          ));
          $attribute-&gt;save();
      }
  
  
      $product-&gt;setData($arg_attribute, $arg_value);
      $product-&gt;save();
  }
  </code></pre>
  
  <p>Unfortunately it don't work. Any ideas? I'm using Magento 1.7.0.2</p>