function it_removes_attributes_from_a_product_template(ProductTemplateInterface $template, AttributeInterface $name) { $name->getCode()->willReturn('name'); $template->getValuesData()->willReturn(['name' => 'foo', 'color' => 'bar']); $template->setValuesData(['color' => 'bar'])->shouldBeCalled(); $this->removeAttribute($template, $name); }
function it_updates_a_variant_group($attributeRepository, $groupTypeRepository, $productBuilder, GroupInterface $variantGroup, AttributeInterface $attribute, GroupTypeInterface $type, GroupTranslation $translatable, ProductInterface $product, ProductTemplateInterface $productTemplate) { $groupTypeRepository->findOneByIdentifier('VARIANT')->willReturn($type); $attributeRepository->findOneByIdentifier('main_color')->willReturn($attribute); $attributeRepository->findOneByIdentifier('secondary_color')->willReturn($attribute); $variantGroup->getTranslation()->willReturn($translatable); $translatable->setLabel('T-shirt super beau')->shouldBeCalled(); $variantGroup->setCode('mycode')->shouldBeCalled(); $variantGroup->setLocale('fr_FR')->shouldBeCalled(); $variantGroup->setType($type)->shouldBeCalled(); $variantGroup->getId()->willReturn(null); $variantGroup->addAxisAttribute(Argument::any())->shouldBeCalled(); $productTemplate->getValuesData()->willReturn([]); $productTemplate->setValues(Argument::any())->shouldBeCalled(); $productTemplate->setValuesData(['main_color' => [['locale' => null, 'scope' => null, 'data' => 'white']]])->shouldBeCalled(); $variantGroup->getProductTemplate()->willReturn($productTemplate); $variantGroup->setProductTemplate($productTemplate)->shouldBeCalled(); $productValue = new ProductValue(); $identifierValue = new ProductValue(); $productBuilder->createProduct()->willReturn($product); $product->getValues()->willReturn(new ArrayCollection([$productValue, $identifierValue])); $product->getIdentifier()->willReturn($identifierValue); $values = ['code' => 'mycode', 'axis' => ['main_color', 'secondary_color'], 'type' => 'VARIANT', 'labels' => ['fr_FR' => 'T-shirt super beau'], 'values' => ['main_color' => [['locale' => null, 'scope' => null, 'data' => 'white']]]]; $this->update($variantGroup, $values, []); }
function it_updates_normalized_product_template_values_if_media_values_have_been_handled($normalizer, ProductTemplateInterface $imageTemplate, ProductTemplateInterface $textTemplate, ProductValueInterface $imageValue, ProductValueInterface $textValue, FileInfoInterface $imageMedia) { $normalizer->normalize(Argument::cetera())->willReturn([]); $imageTemplate->getValues()->willReturn([$imageValue]); $imageValue->getMedia()->willReturn($imageMedia); $imageMedia->isRemoved()->willReturn(true); $imageValue->setMedia(null)->shouldBeCalled(); $imageTemplate->setValuesData([])->shouldBeCalled(); $textTemplate->getValues()->willReturn([$textValue]); $textTemplate->setValuesData([])->shouldNotBeCalled(); $this->handleProductTemplateMedia($imageTemplate); $this->handleProductTemplateMedia($textTemplate); }
/** * {@inheritdoc} */ public function removeAttribute(ProductTemplateInterface $template, AttributeInterface $attribute) { $valuesData = $template->getValuesData(); unset($valuesData[$attribute->getCode()]); $template->setValuesData($valuesData); }
/** * 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); }