Jump to content

[PS 8.2.0] Error when adding Filter to new Column


Recommended Posts

Hello all,

I have created my new module, which adds a id (from a cookie) to the order table. Showing the new column in the order grid works.
(in hookActionOrderGridDefinitionModifier)
 

    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        $definition = $params['definition'];
    
        // Voeg de kolom toe aan de grid
        $columns = $definition->getColumns();
        $columns->addAfter('payment', 
            (new DataColumn('ref_code'))
                ->setName('Referrer Code')
                ->setOptions([
                    'field' => 'ref_code',
                ])
        );
    
        // Voeg de filter toe aan de grid
        $filters = $definition->getFilters();
        $filters->add(
            (new Filter())
                ->setType('text')
                ->setName('ref_code')
                ->setOptions([
                    'required' => false,
                    'attr' => [
                        'placeholder' => 'Referrer Code',
                    ],
                ])
                ->setAssociatedColumn('ref_code')
        );
    }

But the part of adding the filter gives an error:
Compile Error: Cannot declare class PrestaShop\PrestaShop\Core\Product\Search\Filter, because the name is already in use.
And then it shows where the class is used:
 

//in modules/ps_facetedsearch/tests/php/FacetedSearch/Mock/Filter.php (line 23)

     * @license   https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
     */
    namespace PrestaShop\PrestaShop\Core\Product\Search;
    class Filter
    {
        /**
         * @var string the filter label
         */
        private $label = '';

I have tested/played with these above the code, but in my class:
 

use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
//use PrestaShop\PrestaShop\Core\Grid\Filters\TextFilter;
//use PrestaShop\PrestaShop\Core\Grid\Filters\Filter;
//use PrestaShop\PrestaShop\Core\Search\Filters;

I have the other function as well, but I can't test this, because of the eror.
 

    public function hookActionOrderGridQueryBuilderModifier(array $params)
    {
        $searchQueryBuilder = $params['search_query_builder'];

        $searchQueryBuilder->addSelect('rt.ref_code');

        $searchQueryBuilder->leftJoin(
            'o', // De alias van de orders tabel
            _DB_PREFIX_ . 'reseller_tracking', 
            'rt', 
            'rt.id_order = o.id_order' 
        );

        $searchCriteria = $params['search_criteria'];

        $filters = $searchCriteria->getFilters();
        if (!empty($filters['ref_code'])) {
            $searchQueryBuilder->andWhere('rt.ref_code LIKE :ref_code');
            $searchQueryBuilder->setParameter('ref_code', '%' . pSQL($filters['ref_code']) . '%');
        }
    }

I have already tried with:
(new Filter())
And
(new TextFilter())

Already looked and used code from here:
Tutorials


Could somebody help me?
Thanks in advance,

Brian

 

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