function it_denormalizes_an_existing_group_with_properties($groupRepository, Group $group, GroupType $type, AttributeInterface $size, AttributeInterface $color, GroupTranslation $translationUS) { $groupRepository->findOneByIdentifier('tshirt')->willReturn(null); $group->getId()->willReturn(42); $group->setCode('tshirt')->shouldBeCalled(); $group->setType(Argument::any())->shouldNotBeCalled(); $group->setAttributes(Argument::any())->shouldNotBeCalled(); $group->getTranslation('en_US')->willReturn($translationUS); $translationUS->setLabel('My T-shirt')->shouldBeCalled(); $group->addTranslation($translationUS)->shouldBeCalled(); $this->denormalize(['code' => 'tshirt', 'label-en_US' => 'My T-shirt'], self::ENTITY_CLASS, self::FORMAT_CSV, ['entity' => $group])->shouldReturn($group); }
/** * {@inheritdoc} * * @Template * @AclAncestor("pim_enrich_group_create") */ public function createAction(Request $request) { if (!$request->isXmlHttpRequest()) { return $this->redirectToRoute('pim_enrich_variant_group_index'); } $groupType = $this->groupManager->getGroupTypeRepository()->findOneBy(array('code' => 'VARIANT')); $group = new Group(); $group->setType($groupType); if ($this->groupHandler->process($group)) { $this->addFlash('success', 'flash.variant group.created'); $url = $this->generateUrl('pim_enrich_variant_group_edit', array('id' => $group->getId())); $response = array('status' => 1, 'url' => $url); return new Response(json_encode($response)); } return array('form' => $this->groupForm->createView()); }
/** * {@inheritdoc} * * @return Group */ protected function createEntity(array $data) { $group = new Group(); $group->setCode($data['code']); $type = new GroupType(); $type->setCode($data['type']); $type->setVariant($data['type'] === 'VARIANT'); $group->setType($type); foreach ($this->getLabels($data) as $locale => $label) { $translation = $group->getTranslation($locale); $translation->setLabel($label); $group->addTranslation($translation); } foreach ($this->getAttributes($data) as $attribute) { $group->addAttribute($attribute); } return $group; }
/** * @param string $code * @param string $label * @param string $type * @param array $attributes * @param array $products */ protected function createProductGroup($code, $label, $type, array $attributes, array $products = []) { $group = new Group(); $group->setCode($code); $group->setLocale('en_US')->setLabel($label); // TODO translation refactoring $type = $this->getGroupType($type); $group->setType($type); foreach ($attributes as $attributeCode) { $attribute = $this->getAttribute($attributeCode); $group->addAttribute($attribute); } // TODO replace by call to a saver $this->validate($group); $this->persist($group); $this->flush($group); foreach ($products as $sku) { if (!empty($sku)) { $product = $this->getProduct($sku); $product->addGroup($group); $this->validate($product); $this->getProductSaver()->save($product); } } }
/** * {@inheritDoc} */ public function setType(\Pim\Bundle\CatalogBundle\Model\GroupTypeInterface $type) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setType', array($type)); return parent::setType($type); }