/** * @param GroupInterface $group * @param string $type * * @throws \InvalidArgumentException */ protected function setType(GroupInterface $group, $type) { $groupType = $this->groupTypeRepository->findOneByIdentifier($type); if (null !== $groupType) { $group->setType($groupType); } else { throw new \InvalidArgumentException(sprintf('Type "%s" does not exist', $type)); } }
/** * Get axis as choice list * * @param bool $isVariant * * @deprecated not used anymore except in controller which should use the repo, will be removed in 1.5 * * @return array */ public function getTypeChoices($isVariant) { $types = $this->groupTypeRepository->findBy(['variant' => $isVariant]); $choices = []; foreach ($types as $type) { $choices[$type->getId()] = $type->getLabel(); } asort($choices); return $choices; }
/** * Create and configure a group instance * * @param string $groupTypeCode * * @return GroupInterface */ public function createGroup($groupTypeCode = null) { $group = new $this->groupClass(); 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); } return $group; }
/** * @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); } }
/** * Extract a variant group from column "groups" * * @param string $value * * @return array */ protected function extractVariantGroup($value) { $data = []; $groups = $this->fieldSplitter->splitCollection($value); foreach ($groups as $group) { $isVariant = $this->groupTypeRepository->getTypeByGroup($group); if ('1' === $isVariant) { $data['variant_group'][] = $group; } else { $data['groups'][] = $group; } } if (isset($data['variant_group']) && 1 < count($data['variant_group'])) { throw new \InvalidArgumentException(sprintf('The product cannot belong to many variant groups: %s', implode(', ', $data['variant_group']))); } elseif (isset($data['variant_group'])) { $data['variant_group'] = current($data['variant_group']); } return $data; }