Jump to content

Grid Component issue


Recommended Posts

Hello

I try to create a module from scratch. To display the data in a list i want to use the grid component. Sadly i really miss more detailed documentation. To learn how the grid component is working, I copy pasted code from here https://devdocs.prestashop.com/1.7/development/components/grid/

The error I get is (see screenshot)

Attempted to load class "ProductGridDefinitionFactory" from namespace "PrestaShop\PrestaShop\Core\Grid\Definition\Factory".
Did you forget a "use" statement for another namespace?

 

My second question is: The documentation says, create a grid definition is not necessary. But is that not needed in every case? It's not really clear for me.

 

here are my services:

services:

  prestashop.core.grid.definition.factory.product_grid_definition_factory:
    class: 'PrestaShop\PrestaShop\Core\Grid\Definition\Factory\ProductGridDefinitionFactory'
    parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition'
    public: true

  # Configure Grid factory to use services we have implemented
  prestashop.core.grid.product_grid_factory:
    class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
    arguments:
      - '@prestashop.core.grid.definition.factory.product_grid_definition_factory' # our definition factory
      - '@prestashop.core.grid.data.factory.product_data_factory'              # our data factory
      - '@prestashop.core.grid.filter.form_factory'                            # core service needed by grid factory
      - '@prestashop.core.hook.dispatcher'                                     # core service needed by grid factory
    public: true


  # Register ProductQueryBuilder
  prestashop.core.grid.query.product_query_builder:
    class: 'Mindeyes\Members\Grid\ProductQueryBuilder'
    parent: 'prestashop.core.grid.abstract_query_builder'
    arguments:
      - "@=service('prestashop.adapter.legacy.context').getContext().language.id"
      - "@=service('prestashop.adapter.legacy.context').getContext().shop.id"
    public: true

  # Configure our Grid Data factory to use the query builder that we registered above
  prestashop.core.grid.data.factory.product_data_factory:
    class: 'PrestaShop\PrestaShop\Core\Grid\Data\Factory\DoctrineGridDataFactory'
    arguments:
      - '@prestashop.core.grid.query.product_query_builder' # service id of our query builder
      - '@prestashop.core.hook.dispatcher' # every doctrine query builder needs the hook dispatcher
      - '@prestashop.core.grid.query.doctrine_query_parser' # parser to get the raw SQL query
      - 'products' # this should match your grid id, in our case it's "products"

 

CleanShot 2022-04-27 at 19.04.24@2x.png

Link to comment
Share on other sites

Which class? If I add it on top of the class where i call the service, it has no impact...

Most of the used classed are PrestaShop core classes...

 

I know about the example module. It didn't get it working. So that's why I wanted to start with the example in the docs.

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

Thank you @knacky for reminding me. 

PHP 7.4

PrestaShop 1.7.8.2

I try to implement the grid demo again and after a while i got it up and running. Except that the system complains about "Undefined class constant 'MIN_MAX' "

So this SQL Filter seems not existing.

 

Can someone explain me what the documentation means with:

Quote

You don’t have to create the Grid Definition by yourself but instead rely on a PrestaShop\PrestaShop\Core\Grid\Definition\Factory\GridDefinitionFactoryInterface. PrestaShop already provides you with an abstract factory implementation PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory that you can use to create Grid definitions.

 

In the grid_demo example they create a Grid Definition. So is it needed to create a definition or not?

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