← ClaudeAtlas

create-grid-query-builderlisted

Create the Doctrine DBAL QueryBuilder that fetches grid rows, and optionally a GridDataFactory decorator for post-processing. The column aliases must exactly match the column IDs in the Grid Definition. Trigger: "create grid query builder for {Domain}".
jeffsenso/prestashop-skills · ★ 4 · Web & Frontend · score 79
Install: claude install-skill jeffsenso/prestashop-skills
# create-grid-query-builder Read `@.ai/Component/Grid/CONTEXT.md` for the factory trilogy and GridDataFactory decoration pattern. ## 1. Query Builder Create `src/Adapter/{Domain}/Grid/Query/{Domain}QueryBuilder.php` implementing `DoctrineQueryBuilderInterface` or extending `AbstractDoctrineQueryBuilder`: Two required methods: - `getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria): QueryBuilder` — returns rows for the current page - `getCountQueryBuilder(SearchCriteriaInterface $searchCriteria): QueryBuilder` — returns total count (no LIMIT/OFFSET) ### Building the query 1. Base query: `SELECT c.id_{domain}, c.name, c.active FROM ps_{domain} c` 2. For each filter in `$searchCriteria->getFilters()`, add a WHERE clause with parameterized values 3. Apply sorting: map `$searchCriteria->getOrderBy()` to actual column expressions 4. Apply pagination: `->setFirstResult($offset)->setMaxResults($limit)` (search query only, not count) 5. For multilingual columns: LEFT JOIN the `_lang` table with the current language ID **Reference:** `src/Core/Grid/Query/LanguageQueryBuilder.php` (simple), `src/Adapter/Manufacturer/QueryBuilder/ManufacturerQueryBuilder.php` (with joins) ## 2. GridDataFactory (standard) For most grids, the standard `DoctrineGridDataFactory` is sufficient — it calls the query builder automatically. Just wire it in DI: ```yaml prestashop.core.grid.data.factory.{domain}: class: 'PrestaShop\PrestaShop\Core\Grid\Data\Factory\DoctrineGridDataFactory'