Set ordine delle opzioni degli attributi MultiSelect all'interno di script di installazione

magento.stackexchange https://magento.stackexchange.com/questions/840

  •  16-10-2019
  •  | 
  •  

Domanda

In uno dei moduli che stiamo sviluppando abbiamo bisogno di creare un attributo di selezione multipla con diverse opzioni. E 'molto importante che queste opzioni sono dato un certo ordine per impostazione predefinita.

Questo è il codice corrente per aggiungere l'attributo:

$installer->addAttribute('catalog_product', 'tariffplan_sms_slider', array(
    'attribute_set'     => 'Randomattributeset',
    'group'             => 'Sample',
    'type'              => 'varchar',
    'default'           => 0,
    'required'          => false,
    'visible'           => true,
    'backend'           => 'eav/entity_attribute_backend_array',
    'frontend'          => '',
    'label'             => 'Random label',
    'note'              => '',
    'input'             => 'multiselect',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
    'option'            => array ('value' => 
                            array(
                                'one' => array("Low"),
                                'two' => array("Medium"),
                                'three' => array('High'),
                                'four' => array('Unlimited')
                            )
                        ),
    'visible'           => true,
    'required'          => false,
    'user_defined'      => true,
    'default'           => 0,
    'visible_on_front'  => false,
    'used_in_product_listing'   => false,
    'unique'            => false
));

Come potete vedere sto dando una serie di opzioni per questo attributo che verrà creato. Per di più mi piacerebbe impostare l'ordine (vedi campi di input posizione nel backend) di ciascuna opzione .

Ho provato quanto segue al di sotto, ma non funziona:

 'option'           => array (
                            'value' => array(
                                'one' => array("Don't care"),
                                'two' => array("Low"),
                                'three' => array('High'),
                                'four' => array('Unlimited')
                            ),
                            'order' => array(
                                'one' => 0,
                                'two' => 1,
                                'three' => 2,
                                'four' => 3
                            )
                        ),

Versione: Magento ver. 1.7.0.1

Qualcuno ha un'idea?

È stato utile?

Soluzione

Fisso io stesso, cercando al addAttributeOption() metodo Mage_Eav_Model_Entity_Setup interna:

Risultato:

$installer->addAttribute('catalog_product', 'tariffplan_sms_slider', array(
    'attribute_set'     => 'Randomattributeset',
    'group'             => 'Sample',
    'type'              => 'varchar',
    'default'           => 0,
    'required'          => false,
    'visible'           => true,
    'backend'           => 'eav/entity_attribute_backend_array',
    'frontend'          => '',
    'label'             => 'Random label',
    'note'              => '',
    'input'             => 'multiselect',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
    'option'            => array (
                            'values' => array(
                                '1' => 'Low',
                                '2' => 'Medium',
                                '3' => 'High',
                                '4' => 'Unlimited'
                            )
                        ),
    'visible'           => true,
    'required'          => false,
    'user_defined'      => true,
    'default'           => 0,
    'visible_on_front'  => false,
    'used_in_product_listing'   => false,
    'unique'            => false
));

Per coloro che non si vede immediatamente che, fondamentalmente, solo bisogno di cambiare il valore assegnato alla chiave "opzione" da:

'option'            => array ('value' => 
                            array(
                                'one' => array("Low"),
                                'two' => array("Medium"),
                                'three' => array('High'),
                                'four' => array('Unlimited')
                            )
                        ),

Per (vedere come Valore ito cambiato in Valori ):

'option'            => array (
                            'values' => array(
                                '1' => 'Low',
                                '2' => 'Medium',
                                '3' => 'High',
                                '4' => 'Unlimited'
                            )
                        ),
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top