Problema nella visualizzazione del supporto Multi-Select Drop Down in Modulo personalizzato

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

  •  12-12-2019
  •  | 
  •  

Domanda

Ho un modulo comunitario personalizzato in cui voglio consentire il menu a discesa Multi-Select del negozio.

Sto già visualizzando il menu a discesa ma quando salvo il suo valore e quindi, se modifico il modulo, non vedo il valore selezionato che evidenzia sebbene il valore sia memorizzato correttamente nel database.

Qualcuno può farmi sapere, cosa mi manca nella forma?

È stato utile?

Soluzione

Puoi aggiungere questo nel tuo modulo .php

$fieldset->addField('store_id','multiselect',array(
            'name'      => 'stores[]',
            'label'     => Mage::helper('banners')->__('Store View'),
            'title'     => Mage::helper('banners')->__('Store View'),
            'required'  => true,
            'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true)
        ));
.

E devi avere la funzione nel modulo con funzione _afterLoad

class Mage_Banners_Model_Mysql4_Banners extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {    
        // Note that the banners_id refers to the key field in your database table.
        $this->_init('banners/banners', 'banners_id');
    }


 protected function _afterLoad(Mage_Core_Model_Abstract $object)
{

    $select = $this->_getReadAdapter()->select()
        ->from($this->getTable('banners_store'))
        ->where('banners_id = ?', $object->getId());

    if ($data = $this->_getReadAdapter()->fetchAll($select)) {
        $storesArray = array();
        foreach ($data as $row) {
            $storesArray[] = $row['store_id'];
        }
        $object->setData('store_id', $storesArray);
    }

    return parent::_afterLoad($object);

}
.

Il codice sopra è solo per il tuo aiuto puoi impostarlo secondo il nome della colonna e le tabelle del database

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top