/** * Get matching products for variant group * * @param GroupInterface $variantGroup the variant group * * @return ProductInterface[] */ protected function getMatchingProductsForVariantGroup(GroupInterface $variantGroup) { if (!$variantGroup->getId()) { return []; } return $this->repository->findAllForVariantGroup($variantGroup); }
/** * {@inheritdoc} */ public function process($group) { $this->form->setData($group); if ($this->request->isMethod('POST')) { // TODO : how to fix this ? Load products when ODM storage is used to enable validation if (null === $group->getProducts()) { $products = $this->productRepository->findAllForGroup($group)->toArray(); $group->setProducts($products); } $this->form->submit($this->request); if ($this->form->isValid()) { $this->onSuccess($group); return true; } elseif ($group->getType()->isVariant() && $group->getId()) { $products = $this->productRepository->findAllForVariantGroup($group); $group->setProducts($products); } } return false; }
/** * Get matching products * * @param GroupInterface $variantGroup the variant group * @param ProductInterface $entity the product * @param array $criteria query criterias * * @return ProductInterface[] */ protected function getMatchingProducts(GroupInterface $variantGroup, ProductInterface $entity = null, array $criteria = []) { if (!$variantGroup->getId()) { return []; } $matchingProducts = $this->repository->findAllForVariantGroup($variantGroup, $criteria); if ($entity) { $matchingProducts = array_filter($matchingProducts, function ($product) use($entity) { return $product->getId() !== $entity->getId(); }); } return $matchingProducts; }