MAGexpert : les experts en développement Magento
20fév/120

Ajouter une toolbar dans un module personnalisé Magento

Vous souhaitez rajouter une toolbar dans votre module personnalisé comme sur la page de liste des produits ?

Créer un nouveau Block de type Mage_Catalog_Block_Product_List dans app/code/local/Namespace/Monmodule/Block/MonBlock.php et ajouter cette fonction :

public function getToolbarHtml() {
        $this->setToolbar($this->getLayout()->createBlock('catalog/product_list_toolbar', 'Toolbar'));
        $toolbar = $this->getToolbar();
        $toolbar->enableExpanded();
        $toolbar->setAvailableOrders(array(
                    'ordered_qty' => $this->__('Position'),
                    'name' => $this->__('Name'),
                    'price' => $this->__('Price')
                ))
                ->setDefaultDirection('desc')
                ->setCollection($this->_productCollection);

        $pager = $this->getLayout()->createBlock('page/html_pager', 'Pager');
        $pager->setCollection($this->_productCollection);
        $toolbar->setChild('product_list_toolbar_pager', $pager);
        return $toolbar->_toHtml();
    }

Vous n'avez alors plus qu'à appeler votre méthode dans votre phtml (app/design/fontend/default/monmodule/monmodule.phtml avec $this->getToolbarHtml().

20fév/120

Afficher l’éditeur WYSIWYG dans un module personnalisé

Ajouté la fonction suivante dans app/code/local/Namespace/Module/Block/Adminhtml/Module/Edit/Edit.php :

protected function _prepareLayout() {
// Load Wysiwyg on demand and Prepare layout
        if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
            $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
        }
        return parent::_prepareLayout();
}

Ensuite, pour activer l'éditeur de WYSIWYG pour votre attribut, ajouter la propriété wysiwyg (app/code/local/Namespace/Module/Block/Module/Edit/tab/Form.php) :

$fieldset->addField('description', 'editor', array(
            'name' => 'description',
            'label' => Mage::helper('recipe')->__('Description'),
            'title' => Mage::helper('recipe')->__('Description'),
            'style' => 'width:700px; height:200px;',
            'wysiwyg' => true,
            'required' => true,
));