/**
  * @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 ($attribute->getAttributeType() === 'pim_catalog_identifier') {
         $identifier = $this->attributeRepository->getIdentifier();
         if ($identifier && $identifier->getId() !== $attribute->getId()) {
             $this->context->addViolationAt('attributeType', $constraint->message);
         }
     }
 }
 /**
  * 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('attributeType')->addViolation();
         }
     }
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 /**
  * {@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;
 }
Exemplo n.º 6
0
 /**
  * @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 it_provides_the_identifier_attribute(AttributeRepositoryInterface $attributeRepository, AttributeInterface $sku)
 {
     $attributeRepository->getIdentifier()->shouldBeCalled();
     $this->getIdentifierAttribute();
 }
Exemplo n.º 8
0
 /**
  * Return the identifier attribute
  *
  * @return AttributeInterface|null
  *
  * @deprecated will be removed in 1.5, please use AttributeRepositoryInterface::getIdentifier();
  */
 public function getIdentifierAttribute()
 {
     return $this->attributeRepository->getIdentifier();
 }
 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]);
     $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, []);
 }