Jump to content

[PS v8.1.3] Change 'id_product' filter type for admin product grid.


Recommended Posts

I am creating a module, I want to change `id_product` filter for the admin product grid from IntegerMinMaxFilterType to TextType. I managed to do it using hookActionProductGridDefinitionModifier:

    public function hookActionProductGridDefinitionModifier(array $params)
    {
        if (empty($params['definition']))
            return;

        /** @var PrestaShop\PrestaShop\Core\Grid\Definition\GridDefinitionInterface $definition */
        $definition = $params['definition'];

        $filters = $definition->getFilters();

        $filters
            ->remove('id_product')
            ->add(
                (new Filter('id_product', TextType::class))
                    ->setTypeOptions([
                        'required' => false,
                        ])
                    ->setAssociatedColumn('id_product')
            )
		;
    }

The filter field has changed, but after entering a value in it and clicking "Search", I get an error:

Quote

PrestaShop\PrestaShop\Core\Grid\Query\Filter\DoctrineFilterApplicator::computeMinMaxCase(): Argument #1 ($value) must be of type array, string given, called in /src/Core/Grid/Query/Filter/DoctrineFilterApplicator.php on line 93

 

Can you tell me what else I should change and where?

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

hi.

For this to be valid, you also need to have an override twig template.
/src/PrestaShopBundle/Resources/views/Admin/Product/CatalogPage/Lists/products_table.html.twig

Old:

obrazek.png.58d7c36ade75a11d0acef7059e5b57c9.png

 

Sample:

<td>
  <input
         type="text"
         class="form-control"
         placeholder="{{ "Search ID."|trans({}, 'Admin.Catalog.Help') }}"
         name="filter_column_id_product"
         value="{{ filter_column_id_product }}"
         aria-label="{{ "%inputId% input"|trans({'%inputId%': 'filter_column_id_product'}, 'Admin.Global') }}"
         {% if filters_disabled %}disabled{% endif %}
   />
</td>

 

And ./src/Adapter/Product/AdminProductDataProvider.php

obrazek.thumb.png.6166199fe04c9241c45502e2617f2166.png

Edited by ps8moduly.cz (see edit history)
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...