Action bouton prestashop



  • ![text alternatif](![url de l'image](![url de l'image](![url de l'image](url de l'image))))
    J'ai implémenté les interfaces mais j'ai pas pu définir les actions des boutons pour que je puisse ajouter , modifier supprimer .

    <?php
           
    class AdminModifPriceController extends ModuleAdminController
    {
        public function __construct()
        {
          
            $this->bootstrap = true;
            $this->table = 'prices';
            $this->className = 'ModifPrice';
     
        
             $this->list_reduction_type = array(
                'percentage' => $this->l('Percentage'),
                'amount' => $this->l('Amount')
            );
    
            $this->addRowAction('edit');
            $this->addRowAction('delete');
    
            $this->context = Context::getContext();
    
     
            $this->bulk_actions = array(
                'delete' => array(
                    'text' => $this->l('Delete selected'),
                    'confirm' => $this->l('Delete selected items?'),
                    'icon' => 'icon-trash'
                )
            );
    
            $this->fields_list = array(
                'id_update_prices' => array(
                    'title' => $this->l('ID'),
                    'align' => 'center',
                    'class' => 'fixed-width-xs'
                ),
                'Nom regle' => array(
                    'title' => $this->l('Name'),
                    'filter_key' => 'a!name',
                    'width' => 'auto'
                ),
                'reductionTest' => array(
                    'title' => $this->l('Type de reduction'),
                    'filter_key' => 's!name'
                ),
                'varaintePrice' => array(
                    'title' => $this->l('Valeur de reduction'),
                    'filter_key' => 's!name'
                ),
                'site' => array(
                    'title' => $this->l('Site'),
                    'filter_key' => 's!name'
                ),
                 'categorie' => array(
                    'title' => $this->l('Categorie'),
                    'filter_key' => 's!name'
                ),
    
    
               
                'dateNewProducts' => array(
                    'title' => $this->l('Date debut'),
                    'align' => 'right',
                    'type' => 'datetime',
                ),
                'categ_id' => array(
                    'title' => $this->l('Date fin'),
                    'align' => 'right',
                    'type' => 'datetime'
                ),
            );
    
            parent::__construct();
        }
    
      public function renderForm()
        {
            if (!$this->object->id) {
                $this->object->price = -1;
            }
    
      
     $this->fields_form = array(
    
                'legend' => array(
    
                    'title' => $this->l('Nouvelle regle'),
    
                    'icon' => 'icon-dollar'
    
                ),
    
               'input' => array(
    
                    array(
    
                        'type' => 'text',
    
                        'label' => $this->l('Name'),
    
                        'name' => 'name',
    
                        'maxlength' => 32,
    
                        'required' => true,
    
                        'hint' => $this->l('Forbidden characters').' <>;=#{}'
    
                    ),
    
                    
    
                     array(
    
                        'type' => 'select',
    
                        'label' => $this->l('Reduction type'),
    
                        'name' => 'reduction_type',
    
                        'options' => array(
    
                            'query' => array(array('reduction_type' => 'amount', 'name' => $this->l('Amount')), array('reduction_type' => 'percentage', 'name' => $this->l('Percentage'))),
    
                            'id' => 'reduction_type',
    
                            'name' => 'name'
    
                        ),
    
                    ),
    
                     array(
    
                        'type' => 'text',
    
                        'label' => $this->l('Reduction'),
    
                        'name' => 'reduction',
    
                        'required' => true,
    
                    ),
    
                    
    
                      array(
    
                        'type' => 'datetime',
    
                        'label' => $this->l('From'),
    
                        'name' => 'from'
    
                    ),
    
                    array(
    
                        'type' => 'datetime',
    
                        'label' => $this->l('To'),
    
                        'name' => 'to'
    
                    ),
    
                    array(
    
                        'type' => 'text',
    
                        'label' => $this->l('Site'),
    
                        'name' => 'from_quantity',
    
                        'maxlength' => 10,
    
                        'required' => true,
    
                    ),
    
                      array(
    
                        'type' => 'select',
    
                        'label' => $this->l('Categorie'),
    
                        'name' => 'id_group',
    
                        'options' => array(
    
                            'query' => array_merge(array(0 => array('id_group' => 0, 'name' => $this->l('All categories')))),
    
                            'id' => 'id_group',
    
                            'name' => 'name'
    
                        ),
    
                    ),
    
                    
    
                ),
    
                'submit' => array(
    
                    'title' => $this->l('Save')
    
                ),
    
                
    
            );
    
          
    
        
            return parent::renderForm();
        }
       public function processSave()
        {
            $_POST['price'] = Tools::getValue('leave_bprice_on') ? '-1' : Tools::getValue('price');
            if (Validate::isLoadedObject(($object = parent::processSave()))) {
                /** @var SpecificPriceRule $object */
                $object->deleteConditions();
                foreach ($_POST as $key => $values) {
                    if (preg_match('/^condition_group_([0-9]+)$/Ui', $key, $condition_group)) {
                        $conditions = array();
                        foreach ($values as $value) {
                            $condition = explode('_', $value);
                            $conditions[] = array('type' => $condition[0], 'value' => $condition[1]);
                        }
                        $object->addConditions($conditions);
                    }
                }
                $object->apply();
                return $object;
            }
        }
    
        public function postProcess()
        {
            Tools::clearSmartyCache();
            return parent::postProcess();
        }
    
    public function initPageHeaderToolbar()
        {
            if (empty($this->display)) {
                $this->page_header_toolbar_btn['new_specific_price_rule'] = array(
                    'href' => self::$currentIndex.'&addupdate_prices&token='.$this->token,
                    'desc' => $this->l('Ajout regle', null, null, false),
                    'icon' => 'process-icon-new'
                );
            }
    
            parent::initPageHeaderToolbar();
        }
    
    
    public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
        {
            parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
    
            foreach ($this->_list as $k => $list) {
                if ($list['reduction_type'] == 'amount') {
                    $this->_list[$k]['reduction_type'] = $this->list_reduction_type['amount'];
                } elseif ($list['reduction_type'] == 'percentage') {
                    $this->_list[$k]['reduction_type'] = $this->list_reduction_type['percentage'];
                }
            }
        }
    
     
    }
    
    <?php
    class  ModifPrice extends ObjectModel
    {
        public $name;
        public $reduction;
        public $reduction_type;
        public $from;
        public $to;
        public $site;
        public $id_categorie;
    
             public static $definition = array(
            'table' => 'update_prices',
            'primary' => 'id_update_prices',
            'fields' => array(
                'name' =>  array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true),
                'reduction' =>  array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
                'reduction_type' => array('type' => self::TYPE_STRING, 'validate' => 'isReductionType', 'required' => true),
                'from' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'required' => false),
                'to' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'required' => false),
                'site' =>   array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'required' => false),
                'id_categorie' =>  array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'required' => false),
    
            ),
        );
    
    

  • administrators

    En dehors de ton problème, ton code présente de nombreux problème.

    1. Tu ne dois jamais utiliser $_POST, et surtout jamais comme cela
    2. Si chaque fois que ta page s'affiche tu invalides le cache, ton code va avoir détruire les performances de tous le système

    Concernant ton problème, l'ajout, la suppression se font sur les listes par défaut, pas sur la page création/édition



  • Bonjour,
    cette doc vous aidera peut être : http://doc.prestashop.com/display/PS16/Using+the+HelperList+class


Se connecter pour répondre
 

Il semble que votre connexion ait été perdue, veuillez patienter pendant que nous vous re-connectons.