/** * @return ProductInterface */ protected function getCurrentProduct() { $productId = $this->extractor->getDatagridParameter('product'); if (!$productId) { throw new \LogicException('The current product type must be configured'); } $product = $this->productRepository->findOneByWithValues($productId); return $product; }
/** * {@inheritdoc} */ public function apply(FilterDatasourceAdapterInterface $ds, $data) { $data = $this->parseData($data); if (!$data) { return false; } $groupId = $this->extractor->getDatagridParameter('currentGroup'); if (!$groupId) { throw new \LogicException('The current product group must be configured'); } $value = [$groupId]; $operator = $data['value'] === BooleanFilterType::TYPE_YES ? 'IN' : 'NOT IN'; $this->util->applyFilter($ds, 'groups.id', $operator, $value); return true; }
function it_applies_a_filter_on_product_when_its_in_an_expected_group(FilterDatasourceAdapterInterface $datasource, $utility, RequestParametersExtractorInterface $extractor) { $extractor->getDatagridParameter('currentGroup')->willReturn(12); $utility->applyFilter($datasource, 'groups.id', 'IN', [12])->shouldBeCalled(); $this->apply($datasource, ['type' => null, 'value' => 1]); }