Jump to content

Afficher une liste basée sur un array personnalisé dans un module admin controller


Recommended Posts

Bonjour à tous,

Savez-vous pourquoi la helperlist ne s'affiche pas ? Voici le code :

 public function initContent()
    {
        $this->initList();
        
    }
private function initList()
    {
        $id_sms_rule=Tools::getValue('id_sms_rule');
        $conditions=MassSMSSeeCustomers::generate_array_of_customers($id_sms_rule);
        $data=MassSMSSeeCustomers::generate_select_customer_with_condition($conditions);

        // Définit les colonnes à afficher dans la helperlist
        $columns = array(
            'product_id' => array(
                'title' => $this->trans('Product ID', array(), 'Admin.Global'),
                'width' => 25
            ),
            'prod_name' => array(
                'title' => $this->trans('Product Name', array(), 'Admin.Global'),
                'width' => 'auto'
            ),
            'phone_mobile' => array(
                'title' => $this->trans('Phone Mobile', array(), 'Admin.Global'),
                'width' => 'auto'
            ),
            'id_customer' => array(
                'title' => $this->trans('Customer ID', array(), 'Admin.Global'),
                'width' => 25
            ),
            'cus_date_add' => array(
                'title' => $this->trans('Customer Date Add', array(), 'Admin.Global'),
                'width' => 'auto'
            ),
            'ord_date_add' => array(
                'title' => $this->trans('Order Date Add', array(), 'Admin.Global'),
                'width' => 'auto'
            )
        );

        $this->table = 'ycsms_condition';
        $this->className = 'MassSMSCondition';
        $this->identifier = 'id_sms_condition';

        $this->fields_list = $columns;
        $helper_list = new HelperList();
        $helper_list->module = $this;
        $helper_list->title = 'test';
        $helper_list->shopLinkType = '';
        $helper_list->identifier = 'id_customer';
        $helper_list->table = '';
        $helper_list->show_toolbar = true;
        $helper_list->currentIndex =$this->context->link->getAdminLink('AdminMassSMSSeeCustomers').'&id_sms_rule='.
            (int)Tools::getValue('id_sms_rule');
        // This is needed for displayEnableLink to avoid code duplication
        $this->_helperlist = $helper_list;

        $helper_list->listTotal = count($data);
        return $helper_list->generateList($data, $this->fields_list);
    }

$conditions et $data sont corrects, et les $columns correspondent bien à $data.

Merci d'avance.

Edited by PrestashopUser03 (see edit history)
Link to comment
Share on other sites

Visiblement, il faudrait assigner le contenu de mon array au controller, j'ai donc fait ça :

    public function __construct(){
        $this->fields_list=$this->generateFieldsList();
        $this->bootstrap=true;
        parent::__construct();
    }

    private function generateFieldsList()
    {
        $data = $this->getArrayData();
        $fields_list = array();
        foreach ($data as $item) {
            foreach ($item as $key => $value) {
                $fields_list[$key] = array(
                    'title' => $key,
                    'align' => 'center',
                    'class' => 'fixed-width-xs'
                );
            }
            break;
        }
        return $fields_list;

    }

    public function getArrayData()
    {
        $id_sms_rule=Tools::getValue('id_sms_rule');
        $conditions=MyFunction::generate_array_of_customers($id_sms_rule);
        $data=MyFunction::generate_select_customer_with_condition($conditions);
        foreach ($data as $key=> $value) {
            $data[$key]['id_data']=$key +1;
        }
        dump($data);
        return $data;
    }

 

Ca m'affiche bien la les bonnes colonnes mais pas le contenu de mon tableau personnalisé. De plus, le controller continue à se baser sur la table configuration (d'où les 1722 entrées) alors que le but est justement d'afficher le contenu de mon array.

SI vous avez des pistes, je suis preneur.

 

 

image.png

Link to comment
Share on other sites

  • PrestashopUser03 changed the title to Afficher une liste basée sur un array personnalisé dans un module admin controller

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...