# Create Grid Query Builder

> >

- **Type:** Skill
- **Install:** `agentstack add skill-jeffsenso-prestashop-skills-create-grid-query-builder`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [jeffsenso](https://agentstack.voostack.com/s/jeffsenso)
- **Installs:** 0
- **Category:** [Developer Tools](https://agentstack.voostack.com/c/developer-tools)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [jeffsenso](https://github.com/jeffsenso)
- **Source:** https://github.com/jeffsenso/prestashop-skills/tree/main/skills/prestashop-module-development/ps9-core-ai/Component/Grid/skills/create-grid-query-builder

## Install

```sh
agentstack add skill-jeffsenso-prestashop-skills-create-grid-query-builder
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 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'
    arguments:
        - '@prestashop.core.admin.{domain}.query_builder'
        # ... hook dispatcher, query parser, etc.
```

## 3. GridDataFactory decorator (if post-processing needed)

When grid data needs transformation after query execution (e.g. resolving image URLs from IDs, formatting computed columns), create a decorator:

- Create a class implementing `GridDataFactoryInterface`
- Inject the original `GridDataFactory`
- In `getData(SearchCriteriaInterface $searchCriteria)`: call the wrapped factory, then modify the `RecordCollection`
- Register with `decorates:` in DI YAML

```php
class {Domain}GridDataFactory implements GridDataFactoryInterface
{
    public function __construct(
        private readonly GridDataFactoryInterface $dataFactory,
    ) {}

    public function getData(SearchCriteriaInterface $searchCriteria): GridData
    {
        $gridData = $this->dataFactory->getData($searchCriteria);
        $modifiedRecords = $this->applyModifications($gridData->getRecords());
        return new GridData($modifiedRecords, $gridData->getRecordsTotal(), $gridData->getQuery());
    }
}
```

**Reference:** Check existing `*GridDataFactory` decorators in `src/Adapter/` for examples.

## Rules

Conventions (column alias matching, parameterized queries, PK aliasing, count query rules, decoration preference) are in [Grid/CONTEXT.md](../../CONTEXT.md#query-builders).

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [jeffsenso](https://github.com/jeffsenso)
- **Source:** [jeffsenso/prestashop-skills](https://github.com/jeffsenso/prestashop-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-jeffsenso-prestashop-skills-create-grid-query-builder
- Seller: https://agentstack.voostack.com/s/jeffsenso
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
