public function let(ObjectManager $objectManager, EntityRepository $entityRepository, Family $family, AttributeGroup $group)
 {
     $this->beConstructedWith($objectManager, 'Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping');
     $objectManager->getRepository('Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping')->willReturn($entityRepository);
     $group->getCode()->willReturn(12);
     $family->getCode()->willReturn(5);
 }
 /**
  * {@inheritdoc}
  *
  * @return AttributeInterface
  */
 protected function createEntity(array $data)
 {
     $attribute = new Attribute();
     $attribute->setAttributeType($data['type']);
     $this->addLabels($attribute, $data);
     if ($data['group'] !== '') {
         $group = new AttributeGroup();
         $group->setCode($data['group']);
         $attribute->setGroup($group);
     }
     $attribute->setCode($data['code']);
     $attribute->setSortOrder($data['sort_order']);
     $attribute->setRequired($data['required']);
     $attribute->setUnique($data['unique']);
     $attribute->setLocalizable($data['localizable']);
     $attribute->setScopable(strtolower($data['scope']) !== 'global');
     $attribute->setUseableAsGridFilter((bool) $data['useable_as_grid_filter']);
     $attribute->setMetricFamily($data['metric_family']);
     $attribute->setDefaultMetricUnit($data['default_metric_unit']);
     $this->addAvailableLocales($attribute, $data);
     $this->addOptions($attribute, $data);
     foreach ($this->getOptionalProperties() as $property) {
         if (isset($data[$property]) && $data[$property] !== '') {
             $method = 'set' . implode('', array_map(function ($item) {
                 return ucfirst($item);
             }, explode('_', $property)));
             $attribute->{$method}($data[$property]);
         }
     }
     return $attribute;
 }
 /**
  * Normalize the attributes
  *
  * @param AttributeGroup $group
  *
  * @return array
  */
 protected function normalizeAttributes(AttributeGroup $group)
 {
     $attributes = array();
     foreach ($group->getAttributes() as $attribute) {
         $attributes[] = $attribute->getCode();
     }
     return $attributes;
 }
 /**
  * Return the generated attribute groups as AttributeGroup object.
  *
  * @return array
  */
 public function getAttributeGroupObjects()
 {
     $attrGroupObjects = [];
     foreach ($this->attributeGroups as $code => $attributeGroup) {
         $attrGroupObject = new AttributeGroup();
         $attrGroupObject->setCode($code);
         $attrGroupObjects[$code] = $attrGroupObject;
     }
     return $attrGroupObjects;
 }
 function it_removes_an_attribute_group($repository, $objectManager, AttributeGroup $default, AttributeGroup $group, AbstractAttribute $attribute)
 {
     $repository->findDefaultAttributeGroup()->willReturn($default);
     $group->removeAttribute($attribute)->shouldBeCalled();
     $attribute->setGroup($default)->shouldBeCalled();
     $objectManager->persist($group)->shouldBeCalled();
     $objectManager->persist($attribute)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->removeAttribute($group, $attribute);
 }
 /**
  * @param AttributeGroup $group
  *
  * @return array
  */
 public function getAllSources(AttributeGroup $group = null)
 {
     $sources = [];
     if ($this->isValid()) {
         $groups = $this->attributeGroupManager->getAllGroups();
         foreach ($groups as $group) {
             $sources[] = ['id' => $group->getCode(), 'name' => $group->getCode()];
         }
     }
     return $sources;
 }
 /**
  * Remove an attribute from a group and link it to the default group
  *
  * @param AttributeGroup    $group
  * @param AbstractAttribute $attribute
  *
  * @throws \LogicException
  *
  * @return AbstractAttribute
  */
 public function removeAttribute(AttributeGroup $group, AbstractAttribute $attribute)
 {
     if (null === ($default = $this->repository->findDefaultAttributeGroup())) {
         throw new \LogicException('The default attribute group should exist.');
     }
     $group->removeAttribute($attribute);
     $attribute->setGroup($default);
     $this->objectManager->persist($group);
     $this->objectManager->persist($attribute);
     $this->objectManager->flush();
 }
 /**
  * Register a new group mapping.
  *
  * @param AttributeGroup $pimGroup
  * @param Family         $pimFamily
  * @param integer        $magentoGroupId
  * @param string         $magentoUrl
  */
 public function registerGroupMapping(AttributeGroup $pimGroup, Family $pimFamily, $magentoGroupId, $magentoUrl)
 {
     $groupMapping = $this->getEntityRepository()->findOneBy(['pimGroupCode' => $pimGroup->getCode(), 'pimFamilyCode' => $pimFamily->getCode(), 'magentoUrl' => $magentoUrl]);
     $magentoGroupMapping = new $this->className();
     if ($groupMapping) {
         $magentoGroupMapping = $groupMapping;
     }
     $magentoGroupMapping->setPimGroupCode($pimGroup->getCode());
     $magentoGroupMapping->setPimFamilyCode($pimFamily->getCode());
     $magentoGroupMapping->setMagentoGroupId($magentoGroupId);
     $magentoGroupMapping->setMagentoUrl($magentoUrl);
     $this->objectManager->persist($magentoGroupMapping);
     $this->objectManager->flush();
 }
 /**
  * {@inheritdoc}
  * @return AttributeGroupInterface
  */
 protected function createEntity(array $data)
 {
     $group = new AttributeGroup();
     $group->setCode($data['code']);
     foreach ($this->getLabels($data) as $locale => $label) {
         $translation = $group->getTranslation($locale);
         $translation->setLabel($label);
         $group->addTranslation($translation);
     }
     $group->setSortOrder($data['sortOrder']);
     foreach ($this->getAttributes($data) as $attribute) {
         $group->addAttribute($attribute);
     }
     return $group;
 }
 /**
  * Remove attribute group
  *
  * @param Request        $request
  * @param AttributeGroup $group
  *
  * @throws DeleteException
  *
  * @AclAncestor("pim_enrich_attributegroup_remove")
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeAction(Request $request, AttributeGroup $group)
 {
     if ($group === $this->getDefaultGroup()) {
         throw new DeleteException($this->translator->trans('flash.attribute group.not removed default'));
     }
     if (0 !== $group->getAttributes()->count()) {
         $this->request->getSession()->getFlashBag()->add('error', new Message('flash.attribute group.not removed attributes'));
         throw new DeleteException($this->translator->trans('flash.attribute group.not removed attributes'));
     }
     $this->attrGroupRemover->remove($group);
     if ($request->get('_redirectBack')) {
         $referer = $request->headers->get('referer');
         if ($referer) {
             return new RedirectResponse($referer);
         }
     }
     if ($request->isXmlHttpRequest()) {
         return new Response('', 204);
     } else {
         return new RedirectResponse($this->router->generate('pim_enrich_attributegroup_create'));
     }
 }
 /**
  * @param AttributeGroup $group
  *
  * @Given /^I should be on the ("([^"]*)" attribute group) page$/
  */
 public function iShouldBeOnTheAttributeGroupPage(AttributeGroup $group)
 {
     $expectedAddress = $this->getPage('AttributeGroup edit')->getUrl(array('id' => $group->getId()));
     $this->assertAddress($expectedAddress);
 }
 /**
  * {@inheritDoc}
  */
 public function getReference()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getReference', array());
     return parent::getReference();
 }
 /**
  * Test related method
  * Just a call to prevent fatal errors (no way to verify value is set)
  */
 public function testSetLocale()
 {
     $this->group->setLocale('en_US');
 }
 /**
  * @param AttributeGroup $group
  */
 protected function initializeGroup(AttributeGroup $group)
 {
     $this->view[$group->getId()] = array('label' => $group->getLabel(), 'attributes' => array());
 }