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_a_group($groupTypeRepository, GroupInterface $group, GroupTypeInterface $type, GroupTranslation $translatable) { $groupTypeRepository->findOneByIdentifier('RELATED')->willReturn($type); $group->getTranslation()->willReturn($translatable); $translatable->setLabel('T-shirt super beau')->shouldBeCalled(); $group->setCode('mycode')->shouldBeCalled(); $group->setLocale('fr_FR')->shouldBeCalled(); $group->setType($type)->shouldBeCalled(); $group->getId()->willReturn(null); $values = ['code' => 'mycode', 'type' => 'RELATED', 'labels' => ['fr_FR' => 'T-shirt super beau']]; $this->update($group, $values, []); }
/** * @param GroupInterface $variantGroup * @param array $labels * * @throws \InvalidArgumentException */ protected function setLabels(GroupInterface $variantGroup, array $labels) { foreach ($labels as $localeCode => $label) { $variantGroup->setLocale($localeCode); $translation = $variantGroup->getTranslation(); $translation->setLabel($label); } }
/** * @param GroupInterface $group * @param array $data */ protected function setLabels(GroupInterface $group, $data) { foreach ($data as $field => $value) { $isLabel = false !== strpos($field, 'label-', 0); if ($isLabel) { $labelTokens = explode('-', $field); $localeCode = $labelTokens[1]; $translation = $group->getTranslation($localeCode); $translation->setLabel($value); $group->addTranslation($translation); } } }