function it_updates_a_family($attrRequiFactory, $channelRepository, FamilyTranslation $translation, FamilyInterface $family, AttributeRepositoryInterface $attributeRepository, AttributeInterface $attribute1, AttributeInterface $attribute2, AttributeInterface $attribute3, AttributeInterface $attribute4, AttributeRequirementInterface $attributeRequirement1, AttributeRequirementInterface $attributeRequirement2, AttributeRequirementInterface $attributeRequirement3, AttributeRequirementInterface $attributeRequirement4, AttributeRequirementInterface $attributeRequirement5, ChannelInterface $channel1, ChannelInterface $channel2, FamilyInterface $family) { $values = ['code' => 'mycode', 'attributes' => ['sku', 'name', 'description', 'price'], 'attribute_as_label' => 'name', 'requirements' => ['mobile' => ['sku', 'name'], 'print' => ['sku', 'name', 'description']], 'labels' => ['fr_FR' => 'Moniteurs', 'en_US' => 'PC Monitors']]; $attributeRepository->findOneByIdentifier('sku')->willReturn($attribute1); $attributeRepository->findOneByIdentifier('name')->willReturn($attribute2); $attributeRepository->findOneByIdentifier('description')->willReturn($attribute3); $attributeRepository->findOneByIdentifier('price')->willReturn($attribute4); $channelRepository->findOneByIdentifier('mobile')->willReturn($channel1); $channelRepository->findOneByIdentifier('print')->willReturn($channel2); $attrRequiFactory->createAttributeRequirement($attribute1, $channel1, true)->willReturn($attributeRequirement1); $attrRequiFactory->createAttributeRequirement($attribute2, $channel1, true)->willReturn($attributeRequirement2); $attrRequiFactory->createAttributeRequirement($attribute1, $channel2, true)->willReturn($attributeRequirement3); $attrRequiFactory->createAttributeRequirement($attribute2, $channel2, true)->willReturn($attributeRequirement4); $attrRequiFactory->createAttributeRequirement($attribute3, $channel2, true)->willReturn($attributeRequirement5); $family->setAttributeRequirements([$attributeRequirement1, $attributeRequirement2, $attributeRequirement3, $attributeRequirement4, $attributeRequirement5])->shouldBeCalled(); $family->setCode('mycode')->shouldBeCalled(); $family->addAttribute($attribute1)->shouldBeCalled(); $family->addAttribute($attribute2)->shouldBeCalled(); $family->addAttribute($attribute1)->shouldBeCalled(); $family->addAttribute($attribute1)->shouldBeCalled(); $family->setLocale('en_US')->shouldBeCalled(); $family->setLocale('fr_FR')->shouldBeCalled(); $family->getTranslation()->willReturn($translation); $translation->setLabel('label en us'); $translation->setLabel('label fr fr'); $family->addAttribute($attribute1)->shouldBeCalled(); $family->addAttribute($attribute2)->shouldBeCalled(); $family->addAttribute($attribute3)->shouldBeCalled(); $family->addAttribute($attribute4)->shouldBeCalled(); $family->setAttributeAsLabel($attribute2)->shouldBeCalled(); $this->update($family, $values, []); }
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, []); }
/** * @param FamilyInterface $family * @param array $data */ protected function setAttributeRequirements(FamilyInterface $family, array $data) { $requirements = []; foreach ($data as $channelCode => $attributeCodes) { foreach ($attributeCodes as $attributeCode) { if (null !== ($attribute = $this->attributeRepository->findOneByIdentifier($attributeCode))) { if (null !== ($channel = $this->channelRepository->findOneByIdentifier($channelCode))) { $requirements[] = $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true); } else { throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode)); } } else { throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode)); } } } $family->setAttributeRequirements($requirements); }