Jump to content

[RESOLU]Utiliser bulk_actions delete


Recommended Posts

Bonjour

 

 

Je créer un module simple qui permet d'afficher des slider de produit sur la home.

 

Dans le back-office je liste tous les sliders dans un tableau et active l'action delete pour pouvoir les supprimer.

 

L'action delete ne fonctionne pas ou alors je l'utilise mal(c'est plutôt ca)

 

Si quelqu’un aurai 5 min pour m'expliquer cela serai simpatoch  :)

 

 

Je poste mon model au cas ou

<?php

class Banner extends ObjectModel {
    
    public $id_az_home_product;
    public $id_category;
    public $name;
    public $active;

    public static $definition = array(
        'table' => 'az_home_product',
        'primary' => 'id_az_home_product',
        'multilang' => false,
        'fields' => array(           
            'id_category' => array(
                'type' => self::TYPE_INT,
                'validate' => 'isunsignedInt',
                'required' => true,
                ),
            'name' => array(
                'type' => self::TYPE_STRING,
                'lang' => false,
                'validate' => 'isCleanHtml',
                'required' => true,
                'size' => 255,
                ),
            'active' => array(
                'type' => self::TYPE_BOOL,
                'validate' => 'isBool',
                'required' => true,
                ),
        )
    );

}


Et dans le construct de mon contrôleur Admin 

$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
        $this->addRowAction('edit');
        $this->addRowAction('default');
        $this->addRowAction('delete');
Edited by AlexanderOs (see edit history)
Link to comment
Share on other sites

Je n'avais aucun traitement au niveau de l'action donc je les ajouter dans a fonction postProcess()

en prenant pour model  AdminStatesController cela fonctionne je passe en résolu   :)

        /* Delete banner */
        if (Tools::isSubmit('delete'.$this->table)) {
            if ($this->tabAccess['delete'] === '1') {
                if (Validate::isLoadedObject($object = $this->loadObject())) {
                    /** @var Banner $object */
                    
                        if ($object->delete()) {
                            Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.(Tools::getValue('token') ? Tools::getValue('token') : $this->token));
                        }else {
                        $this->errors[] = Tools::displayError('This state was used in at least one address. It cannot be removed.');
                    }
                } else {
                    $this->errors[] = Tools::displayError('An error occurred while deleting the object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
                }
            } else {
                $this->errors[] = Tools::displayError('You do not have permission to delete this.');
            }
        }

        if (!count($this->errors)) {
            parent::postProcess();
        }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...