/**
  * Returns QueryBuilder for products.
  *
  * @param CategoryInterface $category
  *
  * @return QueryBuilder
  */
 protected function getCategoryProductsQueryBuilder(CategoryInterface $category = null)
 {
     $queryBuilder = $this->getRepository()->createQueryBuilder('p')->leftJoin('p.image', 'i')->leftJoin('p.gallery', 'g');
     if ($category) {
         $queryBuilder->leftJoin('p.productCategories', 'pc')->andWhere('pc.category = :categoryId')->setParameter('categoryId', $category->getId());
     }
     return $queryBuilder;
 }
 /**
  * @param CategoryInterface $category
  * @param Options           $options
  * @param array             $choices
  * @param int               $level
  */
 private function childWalker(CategoryInterface $category, Options $options, array &$choices, $level = 1)
 {
     if ($category->getChildren() === null) {
         return;
     }
     foreach ($category->getChildren() as $child) {
         if ($options['category'] && $options['category']->getId() == $child->getId()) {
             continue;
         }
         $choices[$child->getId()] = sprintf("%s %s", str_repeat('-', 1 * $level), $child);
         $this->childWalker($child, $options, $choices, $level + 1);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function setParent(CategoryInterface $parent = null, $nested = false)
 {
     $this->parent = $parent;
     if (!$nested && $parent) {
         $parent->addChild($this, true);
     }
 }
 /**
  * Finds $category place in $tree.
  *
  * @param CategoryInterface $category
  * @param array             $tree
  */
 protected function putInTree(CategoryInterface $category, array &$tree)
 {
     if (null === $category->getParent()) {
         $tree[$category->getId()] = $category;
     } else {
         $this->putInTree($category->getParent(), $tree);
     }
 }