/** * @param GroupInterface $group * @param array $data */ protected function setGroupType(GroupInterface $group, $data) { if (isset($data['type'])) { $typeCode = $data['type']; /** @var GroupType|null $type */ $type = $this->groupTypeRepository->findOneByIdentifier($typeCode); if (!$type) { throw new \LogicException(sprintf('Group Type with identifier "%s" not found', $typeCode)); } $group->setType($type); } }
/** * Create and configure a group instance * * @param string $groupTypeCode * * @return GroupInterface */ public function createGroup($groupTypeCode = null) { $group = $this->create(); if (null !== $groupTypeCode) { $groupType = $this->groupTypeRepository->findOneByIdentifier($groupTypeCode); if (null === $groupType) { throw new \InvalidArgumentException(sprintf('Group type with code "%s" was not found', $groupTypeCode)); } $group->setType($groupType); if ($group->getType()->isVariant()) { $group->setProductTemplate($this->productTemplateFactory->create()); } } return $group; }
/** * @param GroupInterface $variantGroup * @param string $type * * @throws \InvalidArgumentException */ protected function setType(GroupInterface $variantGroup, $type) { $groupType = $this->groupTypeRepository->findOneByIdentifier($type); if (null !== $groupType) { $variantGroup->setType($groupType); } else { throw new \InvalidArgumentException(sprintf('Type "%s" does not exist', $type)); } }
/** * @param GroupInterface $group * @param string $type * * @throws \InvalidArgumentException */ protected function setType(GroupInterface $group, $type) { $groupType = $this->groupTypeRepository->findOneByIdentifier($type); if (null === $groupType) { throw new \InvalidArgumentException(sprintf('Type "%s" does not exist', $type)); } if ($groupType->isVariant()) { throw new \InvalidArgumentException(sprintf('Cannot process variant group "%s", only groups are accepted', $group->getCode())); } $group->setType($groupType); }