/** * @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 testGetCategoryIdWithoutRequest() { $this->requestProductHandler->setRequest(null); $this->assertFalse($this->requestProductHandler->getCategoryId()); }