title: Magento: Custom product attribute to select a CMS page
body: <p>I want to add a new product attribute that renders a drop-down list with all CMS pages as its options.
  I created an extension and wanted to add this attribute via the install script. but after running this, Magento corrupted the eav_entity_type table...</p>
  
  <p><strong>What I tried so far:</strong></p>
  
  <p>mysql4-install-0.1.0.php:</p>
  
  <pre class="lang-php prettyprint-override"><code>$installer = $this;
  
  $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
  
  $installer-&gt;startSetup();
  
  $setup-&gt;addAttribute('catalog_product', 'test_report', array(
      'label' =&gt; 'Test report',
      'required' =&gt; false,
      'input' =&gt; 'select',
      'source' =&gt; 'cmspageselect/entity_source',
      'default' =&gt; 'none',
      'position' =&gt; 1,
      'sort_order' =&gt; 3,
  ));
  
  $installer-&gt;endSetup();
  </code></pre>
  
  <p>Source for cmspageselect/entity_source class:</p>
  
  <pre class="lang-php prettyprint-override"><code>class Mandarin_CMSPageSelect_Model_Source extends Mage_Eav_Model_Entity_Attribute_Source_Abstract {
      /**
      * Retrieve Full Option values array
      *
      * @param bool $withEmpty       Add empty option to array
      * @return array
      */
      public function getAllOptions($withEmpty = true)
      {
          $storeId = $this-&gt;getAttribute()-&gt;getStoreId();
          if (!is_array($this-&gt;_options)) {
              $this-&gt;_options = array();
          }
          if (!isset($this-&gt;_options[$storeId])) {
              $collection = Mage::getResourceModel('cms/page_collection')
                  -&gt;setPositionOrder('asc')
                  -&gt;setStoreFilter($this-&gt;getAttribute()-&gt;getStoreId())
                  -&gt;load();
              $this-&gt;_options[$storeId] = $collection-&gt;toOptionIdArray();
          }
  
          $options = $this-&gt;_options[$storeId];
          if ($withEmpty) {
              array_unshift($options, array('label' =&gt; '', 'value' =&gt; ''));
          }
  
          return $options;
      }
  
      /**
      * Get a text for option value
      *
      * @param string|integer $value
      * @return string
      */
      public function getOptionText($value)
      {
          $isMultiple = false;
          if (strpos($value, ',')) {
              $isMultiple = true;
              $value = explode(',', $value);
          }
  
          $options = $this-&gt;getAllOptions(false);
  
          if ($isMultiple) {
              $values = array();
              foreach ($options as $item) {
                  if (in_array($item['value'], $value)) {
                      $values[] = $item['label'];
                  }
              }
              return $values;
          }
  
          foreach ($options as $item) {
              if ($item['value'] == $value) {
                  return $item['label'];
              }
          }
          return false;
      }
  }
  </code></pre>
  
  <p>As I said, instead of creating the new attribute "test_report", Magento just corrupted the eav_entity_type table. There was no error message nor log entry about what happened.</p>
  
  <p>How can I create such an attribute?</p>
  
  <p>Thanks,
  aeno</p>