public function testOnPreBuildWithoutCategoryId()
 {
     $event = $this->createPreBuildEvent();
     $this->requestProductHandler->expects($this->once())->method('getCategoryId')->willReturn(false);
     $this->doctrine->expects($this->never())->method('getRepository');
     $this->listener->onPreBuildProducts($event);
 }
 /**
  * @param PreBuild $event
  */
 protected function addFilterByCategory(PreBuild $event)
 {
     $categoryId = $this->requestProductHandler->getCategoryId();
     if (!$categoryId) {
         return;
     }
     /** @var CategoryRepository $repo */
     $repo = $this->doctrine->getRepository($this->dataClass);
     /** @var Category $category */
     $category = $repo->find($categoryId);
     if (!$category) {
         return;
     }
     $includeSubcategoriesChoice = $this->requestProductHandler->getIncludeSubcategoriesChoice();
     $productCategoryIds = [$categoryId];
     if ($includeSubcategoriesChoice) {
         $productCategoryIds = array_merge($repo->getChildrenIds($category), $productCategoryIds);
     }
     $config = $event->getConfig();
     $config->offsetSetByPath('[source][query][where][and]', ['productCategory.id IN (:productCategoryIds)']);
     $config->offsetSetByPath(DatasourceBindParametersListener::DATASOURCE_BIND_PARAMETERS_PATH, ['productCategoryIds']);
     $event->getParameters()->set('productCategoryIds', $productCategoryIds);
     $this->addCategoryJoin($event->getConfig());
 }
 public function testGetIncludeSubcategoriesChoiceWithEmptyRequest()
 {
     $this->requestProductHandler->setRequest(null);
     $this->assertEquals(RequestProductHandler::INCLUDE_SUBCATEGORIES_DEFAULT_VALUE, $this->requestProductHandler->getIncludeSubcategoriesChoice());
 }