Search code examples
symfony3akeneopim

Token cannot be null on the instantiation of the Product Query Builder. / Query Akeneo 2


I would like to create a command akeneo into my bundle who query my products like this.

So, after multiple test, i have always this error:

In ProductQueryBuilderFactory.php line 68:
Token cannot be null on the instantiation of the Product Query Builder.

Here is my code :

$pqbFactory =  $this->getApplication()->getKernel()->getContainer()->get('pim_catalog.query.product_query_builder_factory');
$pqb = $pqbFactory->create(['default_locale' => 'fr_FR', 'default_scope' => 'ecommerce']);  // error

Solution

  • To complete Julien's answer, note that this error comes only if you are using the Enterprise Edition (EE). Indeed, in the EE, we decorate the normal product_query_builder_factory to apply permission.

    If you don't want to apply permission (and don't use any token), you can use the pim_catalog.query.product_query_builder_factory_without_permission:

    <?php
    
    require __DIR__.'/vendor/autoload.php';
    
    $kernel = new AppKernel('dev', true);
    $kernel->boot();
    
    $pqbFactory =  $kernel->getContainer()->get('pim_catalog.query.product_query_builder_factory_without_permission');
    $pqb = $pqbFactory->create(['default_locale' => 'fr_FR', 'default_scope' => 'ecommerce']);  // you won't have any error