function it_updates_normalized_product_template_values_if_media_values_have_been_handled($normalizer, ProductTemplateInterface $imageTemplate, ProductTemplateInterface $textTemplate, ProductValueInterface $imageValue, ProductValueInterface $textValue, ProductMediaInterface $imageMedia) { $normalizer->normalize(Argument::cetera())->willReturn([]); $imageTemplate->getValues()->willReturn([$imageValue]); $imageValue->getMedia()->willReturn($imageMedia); $imageTemplate->setValuesData([])->shouldBeCalled(); $textTemplate->getValues()->willReturn([$textValue]); $textTemplate->setValuesData([])->shouldNotBeCalled(); $this->handleProductTemplateMedia($imageTemplate); $this->handleProductTemplateMedia($textTemplate); }
function it_skips_a_variant_group_when_object_is_invalid($variantConverter, $repository, $variantUpdater, $validator, GroupInterface $variantGroup, ProductTemplateInterface $productTemplate, ConstraintViolationListInterface $violationList) { $repository->getIdentifierProperties()->willReturn(['code']); $repository->findOneByIdentifier(Argument::any())->willReturn($variantGroup); $groupType = new GroupType(); $groupType->setVariant(true); $productTemplate->getValues()->willReturn(new ArrayCollection()); $variantGroup->getType()->willReturn($groupType); $variantGroup->getId()->willReturn(42); $variantGroup->getProductTemplate()->willReturn($productTemplate); $values = $this->getValues(); $variantConverter->convert($values['original_values'])->willReturn($values['converted_values']); $variantUpdater->update($variantGroup, $values['converted_values'])->shouldBeCalled(); $validator->validate($variantGroup)->willReturn($violationList); $this->process($values['original_values'])->shouldReturn($variantGroup); $variantUpdater->update($variantGroup, $values['converted_values'])->willThrow(new \InvalidArgumentException('Attributes: This property cannot be changed.')); $violation = new ConstraintViolation('Error', 'foo', [], 'bar', 'code', 'mycode'); $violations = new ConstraintViolationList([$violation]); $validator->validate($variantGroup)->willReturn($violations); $this->shouldThrow('Akeneo\\Bundle\\BatchBundle\\Item\\InvalidItemException')->during('process', [$values['original_values']]); }
/** * Updates normalized product template values (required after handling new media added to a template) * * @param ProductTemplateInterface $template */ protected function updateNormalizedValues(ProductTemplateInterface $template) { $valuesData = $this->normalizer->normalize($template->getValues(), 'json', ['entity' => 'product']); $template->setValuesData($valuesData); }