Jump to content

Product filter


Recommended Posts

i'm new to developing prestashop modules and could go a long way but now i'm stuck on the following,

I am creating a form in the back office in which products can be searched. I would like to see that if I change the text in the textbox, the filter will immediately compare.

I already have this code:

public function renderForm(){  

  $fields_form = [

      'form' => [

          'legend' => ['title' => $this->l('Nieuw product toevoegen aan kast'), 'icon' => 'icon-file'],

          'input'  => [

              [

                  'type'     => 'text',

                  'label'    => $this->l('Product zoeken'),

                  'name'     => 'product_search',

                  'desc'     => $this->module->l('Welk product wil u toevoegen aan de kast'),

                  'hint'     => $this->l('Als het product er niet tussen staat moet u deze eerst toevoegen aan de webshop'),

                  'required' => true,

              ],            

              [

                  'type'     => 'text',

                  'label'    => $this->l('Aantal in de kast'),

                  'name'     => 'product_amount',

                  'desc'     => $this->module->l('het aantal producten wat in de kast staat'),

                  'required' => true,

              ],

              [

                  'type'     => 'select',

                  'label'    => $this->l('Product kiezen'),

                  'name'     => 'product_name',

                  'options'  => [

                    'query' => $this->getImageSizes(),

                    'id'    => 'name',

                    'name'  => 'name',

                ],

              ],

          ],

          'submit' => [

              'title' => $this->l('Save'),

              'class' => 'btn btn-primary btn-mc pull-right',

          ],

      ],

  ];

 return $helper->generateForm([$fields_form]);

}

 

private function getImageSizes()

  {

      $query = new DbQuery();

      $query->select('id_product, name');

      $query->from('product_lang');

      //$query->where('name = "Glas"');

$result = array();

$compleet = array();

$result = Db::getInstance()->executeS($query);

$search = Tools::getValue('product_search');

foreach ($result as $line){

  if(str_contains(strtolower($line['name']), strtolower($search))){

$compleet[] = $line;

  }

}

      try {

          return $compleet;

      } catch (Exception $exception) {

          $this->errors[] = $exception->getMessage();

          return [];

      }

  }

 

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