/** * @return array */ protected function prepareParameters() { $queryParameters = parent::prepareParameters(); $variantGroupId = $queryParameters['currentGroup']; if (null !== $variantGroupId) { $productIds = $this->productRepository->getEligibleProductIdsForVariantGroup($variantGroupId); if (count($productIds) === 0) { $productIds = [0]; } } else { $productIds = [0]; } $queryParameters['productIds'] = $productIds; return $queryParameters; }
/** * Clean the filters to keep only non duplicated. * This method send "skipped" message for every duplicated product for a variant group. * * When all the selected products are skipped, there is no remaining products to mass-edit. The standard behaviour * should return a single filter like "id IN ()", which is equivalent to "nothing", and it's it is very poorly * managed by Doctrine. * Instead of returning this filter, we return a "is IS NULL" filter, which in this case is completely * equivalent to "nothing" (there can not be null ids). * * @param StepExecution $stepExecution * @param array $filters * @param array $actions * * @return array */ public function clean(StepExecution $stepExecution, $filters, $actions) { $variantGroupCode = $actions['value']; $variantGroup = $this->groupRepository->findOneByIdentifier($variantGroupCode); $axisAttributeCodes = $this->getAxisAttributeCodes($variantGroup); $eligibleProductIds = $this->productRepository->getEligibleProductIdsForVariantGroup($variantGroup->getId()); $cursor = $this->getProductsCursor($filters); $paginator = $this->paginatorFactory->createPaginator($cursor); list($productAttributeAxis, $acceptedIds) = $this->filterDuplicateAxisCombinations($stepExecution, $paginator, $eligibleProductIds, $axisAttributeCodes); $excludedIds = $this->addSkippedMessageForDuplicatedProducts($stepExecution, $productAttributeAxis); $acceptedIds = array_diff($acceptedIds, $excludedIds); if (0 === count($acceptedIds)) { return [['field' => 'id', 'operator' => Operators::IN_LIST, 'value' => ['']]]; } return [['field' => 'id', 'operator' => Operators::IN_LIST, 'value' => $acceptedIds]]; }