apr 23

Un buon tutorial:
http://www.magentix.fr/modules-magento/ajouter-categorie-attributs-champs-personnalises.html

Se però il campo aggiuntivo deve essere una select popolata dinamicamente, serve qualche ulteriore passo.
Il file mysql4-install-0.1.0.php dovrà essere così:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
startSetup();
 
$installer->addAttribute('catalog_category', 'drilldown_link', array(
                        'type'              => 'int',
                        'backend'           => '',
                        'frontend'          => '',
                        'label'             => 'Attributo collegato (drilldown L2):',
                        'input'             => 'select',
                        'class'             => '',
                        'source'            => 'bundle/drilldownl2',
                        'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                        'visible'           => 1,
                        'required'          => 0,
                        'user_defined'      => 0,
                        'default'           => '',
                        'searchable'        => 0,
                        'filterable'        => 0,
                        'comparable'        => 0,
                        'visible_on_front'  => 0,
                        'unique'            => 0,
                        'position'          => 1,
			'note'		    => '',
			'apply_to'	    => 'bundle',
                    ));
 
$installer->endSetup();

Le righe modificate rispetto al tutorial seguito sono:
'input' => 'select'
'source' => 'bundle/drilldownl2'

con la seconda, specifichiamo il model che Magento andrà a cercare per popolare la select.
In altre parole, il sistema si aspetta di trovare questo file:
app/code[/local]/Mage/Bundle/Model/drilldownl2.php
che dovrà contenere un metodo getAllOptions().
Ecco il codice:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
 
class Mage_Bundle_Model_DrilldownL2 extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
 public function getAllOptions()
 {
 if (is_null($this->_options)) {
 $this->_options = array();
 
 $this->_options = array(
 array(
 'label' => Mage::helper('bundle')->__('Uno'),
 'value' =>  1
 ),
 array(
 'label' => Mage::helper('bundle')->__('Due'),
 'value' =>  0
 ),
 );
 }
 return $this->_options;
 }
}
 
?>
Tagged with:
preload preload preload