Magento: Пользовательский атрибут продукта для выбора страницы CMS

я хочу добавить новый атрибут продукта, который отображает раскрывающийся список со всеми страницами CMS в качестве его параметров. Я создал расширение и хотел добавить этот атрибут через скрипт установки. но после запуска Magento испортил таблицу eav_entity_type ...

То, что я пробовал до сих пор:

mysql4-install-0.1.0.php:

$installer = $this;

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$installer->startSetup();

$setup->addAttribute('catalog_product', 'test_report', array(
    'label' => 'Test report',
    'required' => false,
    'input' => 'select',
    'source' => 'cmspageselect/entity_source',
    'default' => 'none',
    'position' => 1,
    'sort_order' => 3,
));

$installer->endSetup();

Источник для класса cmspageselect / entity_source:

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->getAttribute()->getStoreId();
        if (!is_array($this->_options)) {
            $this->_options = array();
        }
        if (!isset($this->_options[$storeId])) {
            $collection = Mage::getResourceModel('cms/page_collection')
                ->setPositionOrder('asc')
                ->setStoreFilter($this->getAttribute()->getStoreId())
                ->load();
            $this->_options[$storeId] = $collection->toOptionIdArray();
        }

        $options = $this->_options[$storeId];
        if ($withEmpty) {
            array_unshift($options, array('label' => '', 'value' => ''));
        }

        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->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;
    }
}

Как я сказал, что вместо создания нового атрибута test_report Magento просто испортил таблицу eav_entity_type. Не было ни сообщения об ошибке, ни записи в журнале о том, что произошло.

Как я могу создать такой атрибут?

Спасибо, aeno

7
задан aeno 18 January 2012 в 09:11
поделиться