/** * @return string */ public function resolveIdentifierField() { if (empty($this->identifierField)) { $attribute = $this->attributeRepository->getIdentifier(); $this->identifierField = $attribute->getCode(); } return $this->identifierField; }
/** * Don't allow creating an identifier attribute if one already exists * * @param AttributeInterface $attribute * @param Constraint $constraint */ public function validate($attribute, Constraint $constraint) { if (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) { $identifier = $this->attributeRepository->getIdentifier(); if ($identifier && $identifier->getId() !== $attribute->getId()) { $this->context->buildViolation($constraint->message)->atPath('attribute_type')->addViolation(); } } }
/** * @return FamilyInterface */ public function createFamily() { $family = new $this->familyClass(); $identifier = $this->attributeRepository->getIdentifier(); $family->addAttribute($identifier); $family->setAttributeAsLabel($identifier); foreach ($this->getChannels() as $channel) { $requirement = $this->factory->createAttributeRequirement($identifier, $channel, true); $family->addAttributeRequirement($requirement); } return $family; }
/** * {@inheritdoc} */ public function createProduct($identifier = null, $familyCode = null) { $product = new $this->productClass(); $identifierAttribute = $this->attributeRepository->getIdentifier(); $productValue = $this->createProductValue($identifierAttribute); $product->addValue($productValue); if (null !== $identifier) { $productValue->setData($identifier); } if (null !== $familyCode) { $family = $this->familyRepository->findOneByIdentifier($familyCode); $product->setFamily($family); } $event = new GenericEvent($product); $this->eventDispatcher->dispatch(ProductEvents::CREATE, $event); return $product; }
/** * @param FamilyInterface $family * @param array $requirements * * @return array */ protected function addMissingIdentifierRequirements(FamilyInterface $family, array $requirements) { $channelCodes = $this->channelRepository->getChannelCodes(); $existingChannelCode = []; foreach ($requirements as $requirement) { if (AttributeTypes::IDENTIFIER === $requirement->getAttribute()->getAttributeType()) { $existingChannelCode[] = $requirement->getChannelCode(); } } $missingChannelCodes = array_diff($channelCodes, $existingChannelCode); $identifier = $this->attributeRepository->getIdentifier(); foreach ($missingChannelCodes as $channelCode) { $requirements[] = $this->createAttributeRequirement($identifier, $family, $channelCode); } return $requirements; }
function let(ProductValueConverter $valueConverter, AttributeRepositoryInterface $attributeRepository, AttributeInterface $identifierAttribute) { $attributeRepository->getIdentifier()->willReturn($identifierAttribute); $identifierAttribute->getCode()->willReturn('sku'); $this->beConstructedWith($valueConverter, $attributeRepository); }
public function it_should_not_remove_identifier_requirements_when_other_requirements_are_provided($attrRequiFactory, $channelRepository, FamilyInterface $family, AttributeRepositoryInterface $attributeRepository, AttributeInterface $skuAttribute, AttributeInterface $nameAttribute, AttributeInterface $descAttribute, AttributeRequirementInterface $skuMobileRqrmt, AttributeRequirementInterface $skuPrintRqrmt, AttributeRequirementInterface $namePrintRqrmt, AttributeRequirementInterface $descPrintRqrmt, ChannelInterface $mobileChannel, ChannelInterface $printChannel) { $values = ['code' => 'mycode', 'requirements' => ['print' => ['name', 'description']]]; $family->getAttributeRequirements()->willReturn([$skuMobileRqrmt, $skuPrintRqrmt]); $family->getId()->willReturn(42); $skuMobileRqrmt->getAttribute()->willReturn($skuAttribute); $skuPrintRqrmt->getAttribute()->willReturn($skuAttribute); $skuMobileRqrmt->getChannelCode()->willReturn('mobile'); $skuPrintRqrmt->getChannelCode()->willReturn('print'); $skuAttribute->getAttributeType()->willReturn(AttributeTypes::IDENTIFIER); $channelRepository->findOneByIdentifier('print')->willReturn($printChannel); $attributeRepository->findOneByIdentifier('name')->willReturn($nameAttribute); $attributeRepository->findOneByIdentifier('description')->willReturn($descAttribute); $attrRequiFactory->createAttributeRequirement($nameAttribute, $printChannel, true)->willReturn($namePrintRqrmt); $attrRequiFactory->createAttributeRequirement($descAttribute, $printChannel, true)->willReturn($descPrintRqrmt); $namePrintRqrmt->getAttribute()->willReturn($nameAttribute); $descPrintRqrmt->getAttribute()->willReturn($descAttribute); $channelRepository->getChannelCodes()->willReturn(['mobile', 'print']); $channelRepository->findOneByIdentifier('mobile')->willReturn($mobileChannel); $channelRepository->findOneByIdentifier('print')->willReturn($printChannel); $attributeRepository->getIdentifier()->willReturn($skuAttribute); $family->setCode('mycode')->shouldBeCalled(); $family->setAttributeRequirements([$skuMobileRqrmt, $skuPrintRqrmt, $namePrintRqrmt, $descPrintRqrmt])->shouldBeCalled(); $this->update($family, $values, []); }