0
votes

I downloaded and installed SyliusTaxonomiesBundle, and when I want to create a taxon (linked to a taxonomy), I get the following problem:

Catchable Fatal Error: Argument 1 passed to Sylius\Bundle\TaxonomiesBundle\Doctrine\ORM\TaxonRepository::getTaxonsAsList() must implement interface Sylius\Bundle\TaxonomiesBundle\Model\TaxonomyInterface, null given, called in /home/jeremy/web/vendor/sylius/taxonomies-bundle/Sylius/Bundle/TaxonomiesBundle/Form/Type/TaxonChoiceType.php on line 70 and defined in /home/jeremy/web/vendor/sylius/taxonomies-bundle/Sylius/Bundle/TaxonomiesBundle/Doctrine/ORM/TaxonRepository.php line 25

the problem at this level : https://github.com/pjedrzejewski/SyliusTaxonomiesBundle/blob/master/Form/Type/TaxonChoiceType.php

    /**
 * {@inheritdoc}
 */
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $repository = $this->taxonRepository;
    $choiceList = function (Options $options) use ($repository) {
        $taxons = $repository->getTaxonsAsList($options['taxonomy']);

        if (null !== $options['filter']) {
            $taxons = array_filter($taxons, $options['filter']);
        }

        return new ObjectChoiceList($taxons);
    };

    $resolver
        ->setDefaults(array(
            'choice_list' => $choiceList
        ))
        ->setRequired(array(
            'taxonomy',
            'filter'
        ))
        ->setAllowedTypes(array(
            'taxonomy' => array('Sylius\Bundle\TaxonomiesBundle\Model\TaxonomyInterface'),
            'filter' => array('\Closure', 'null')
        ))
    ;
}

and the method getTaxonsAsList is here : https://github.com/pjedrzejewski/SyliusTaxonomiesBundle/blob/master/Doctrine/ORM/TaxonomyRepository.php

class TaxonRepository extends EntityRepository implements TaxonRepositoryInterface
{
public function getTaxonsAsList(TaxonomyInterface $taxonomy)
{
    return $this->getQueryBuilder()
        ->where('o.taxonomy = :taxonomy')
        ->andWhere('o.parent IS NOT NULL')
        ->setParameter('taxonomy', $taxonomy)
        ->orderBy('o.left')
        ->getQuery()
        ->getResult()
    ;
}

}

Can you help me please, thank you very much

2

2 Answers

0
votes

I use the standalone bundle. and I had the same problem.

I solved my problem by adding "$this->setRoot(new Taxon())" in the constructor of my taxonomy Class.

I overwride the taxonomy model and taxon and it's work for me.

use Doctrine\ORM\Mapping as ORM;

use Sylius\Component\Taxonomy\Model\Taxonomy as BaseTaxonomy;

use Syn\CoreBundle\Entity\Taxon;
/**
 * Class Taxonomy.
 * 
 * @ORM\Table(name="syn_taxonomy")
 * @ORM\Entity
 */
class Taxonomy extends BaseTaxonomy
{
    /**
     * {@inheritdoc}
     */
    public function __construct()
    {
        $this->setRoot(new Taxon());
    }
}

Class Taxon

use Doctrine\ORM\Mapping as ORM;

use Sylius\Component\Taxonomy\Model\Taxon as BaseTaxon;

/**
 * Class Taxon.
 * 
 * @ORM\Table(name="syn_taxon")
 * @ORM\Entity
 */
class Taxon extends BaseTaxon
{
}
0
votes

I had exactly the same problem.

I also did override the models from the TaxonomyBundle. And also placed the setRoot method in the constructor from the Taxonomy. It actually did fixed a error but not the error as described on top.

The problem is that the syliusResourceController is loaded instead of the SyliusTaxonController. You can check this by entering php app/console container:debug | grep taxon in the console

you can change the controller like this:

sylius_taxonomy:
    driver: doctrine/orm
    classes:
        taxonomy:
            model: App\CoreBundle\Model\Taxonomy
        taxon:
            controller: Sylius\Bundle\TaxonomyBundle\Controller\TaxonController
            model: App\CoreBundle\Model\Taxon