/**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     foreach ($this->attributes as $item) {
         // Create attribute label
         $label = new AttributeLabel();
         $label->setValue($item['label']);
         // Create attribute
         $attribute = new Attribute();
         $attribute->setCode($item['code']);
         $attribute->setType($item['type']);
         $attribute->setSharingType(SharingType::GENERAL);
         $attribute->setLocalized($item['localized']);
         $attribute->setSystem($item['system']);
         $attribute->setRequired($item['required']);
         $attribute->setUnique($item['unique']);
         $attribute->addLabel($label);
         if (isset($item['options'])) {
             foreach ($item['options'] as $optionItem) {
                 $masterOption = new AttributeOption();
                 $masterOption->setValue($optionItem['value']);
                 $masterOption->setOrder($optionItem['order']);
                 $attribute->addOption($masterOption);
             }
         }
         $manager->persist($attribute);
     }
     if (!empty($this->attributes)) {
         $manager->flush();
         $manager->clear();
     }
 }
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $attribute = new Attribute();
     $attribute->setCode(self::ATTRIBUTE_CODE)->setType(Select::NAME)->setSharingType(SharingType::GENERAL);
     foreach (self::$options as $localeCode => $options) {
         $locale = $localeCode ? $this->getLocaleByCode($manager, $localeCode) : null;
         foreach ($options as $order => $value) {
             $option = new AttributeOption();
             $option->setLocale($locale)->setValue($value)->setOrder($order);
             $attribute->addOption($option);
         }
     }
     $manager->persist($attribute);
     $manager->flush($attribute);
     $manager->clear();
 }
 /**
  * @param array $normalizers
  */
 public function assertNormalizers(array $normalizers)
 {
     $this->assertArrayHasKey('query_builder', $normalizers);
     /** @var \Closure $normalizerCallback */
     $normalizerCallback = $normalizers['query_builder'];
     $this->assertInstanceOf('\\Closure', $normalizerCallback);
     $attribute = new Attribute();
     $attribute->setCode('select_attribute')->setType(Select::NAME);
     $options = new Options();
     $options->set('attribute', $attribute);
     /** @var \Closure $queryBuilderCallback */
     $queryBuilderCallback = $normalizerCallback($options);
     $this->assertInstanceOf('\\Closure', $queryBuilderCallback);
     $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $repository = $this->getMockBuilder('OroB2B\\Bundle\\AttributeBundle\\Entity\\Repository\\AttributeOptionRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('createAttributeOptionsQueryBuilder')->with($attribute)->willReturn($queryBuilder);
     $this->assertEquals($queryBuilder, $queryBuilderCallback($repository));
 }
 /**
  * @Route("/init", name="orob2b_attribute_init")
  * @Template("OroB2BAttributeBundle:Attribute:update.html.twig")
  * @AclAncestor("orob2b_attribute_create")
  *
  * @return array|RedirectResponse
  */
 public function initAction()
 {
     $request = $this->getRequest();
     if ($request->getMethod() != 'POST') {
         return $this->redirect($this->generateUrl('orob2b_attribute_init'));
     }
     if ($request->request->has(CreateAttributeType::NAME)) {
         // processing of create form
         $form = $this->createForm(CreateAttributeType::NAME);
         $form->submit($request);
         if (!$form->isValid()) {
             return $this->forward('OroB2BAttributeBundle:Attribute:create');
         }
         $attribute = $form->getData();
     } elseif ($request->request->has(UpdateAttributeType::NAME)) {
         // processing of init form
         $formData = $request->request->get(UpdateAttributeType::NAME);
         $attribute = new Attribute();
         $attribute->setCode($formData['code'])->setType($formData['type'])->setLocalized(!empty($formData['localized']));
     } else {
         throw new BadRequestHttpException('Request does not contain attribute data');
     }
     return $this->update($attribute);
 }
 /**
  * @return Attribute
  */
 protected function getOptionAttribute()
 {
     $firstGroupDefaultOption = $this->createOption(1, null)->setOrder(1)->setValue('default_1');
     $firstGroupFirstOption = $this->createOption(2, 1)->setOrder(1)->setFallback(FallbackType::SYSTEM);
     $firstGroupSecondOption = $this->createOption(3, 2)->setOrder(1)->setValue('second_1');
     $firstGroupDefaultOption->addRelatedOption($firstGroupFirstOption)->addRelatedOption($firstGroupSecondOption);
     $secondGroupDefaultOption = $this->createOption(4, null)->setOrder(2)->setValue('default_2');
     $secondGroupFirstOption = $this->createOption(5, 1)->setOrder(2)->setValue('first_2');
     $secondGroupSecondOption = $this->createOption(6, 2)->setOrder(2)->setValue('second_2');
     $secondGroupDefaultOption->addRelatedOption($secondGroupFirstOption)->addRelatedOption($secondGroupSecondOption);
     $thirdGroupDefaultOption = $this->createOption(null, null)->setOrder(2)->setValue('default_3');
     $thirdGroupFirstOption = $this->createOption(null, 1)->setOrder(2)->setValue('first_3');
     $thirdGroupSecondOption = $this->createOption(null, 2)->setOrder(2)->setFallback(FallbackType::PARENT_LOCALE);
     $thirdGroupDefaultOption->addRelatedOption($thirdGroupFirstOption)->addRelatedOption($thirdGroupSecondOption);
     $optionAttribute = new Attribute();
     $optionAttribute->setCode('select')->setType(Select::NAME)->resetOptions([$firstGroupDefaultOption, $firstGroupFirstOption, $firstGroupSecondOption, $secondGroupDefaultOption, $secondGroupFirstOption, $secondGroupSecondOption, $thirdGroupDefaultOption, $thirdGroupFirstOption, $thirdGroupSecondOption])->addDefaultValue($this->createDefaultValue(null)->setOption($firstGroupDefaultOption))->addDefaultValue($this->createDefaultValue(2)->setOption($firstGroupSecondOption))->addDefaultValue($this->createDefaultValue(1)->setOption($secondGroupFirstOption));
     $this->addTestProperties($optionAttribute);
     return $optionAttribute;
 }