/**
  * {@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();
     }
 }
Ejemplo n.º 2
0
 public function testGetLabelByLocaleId()
 {
     $defaultLabel = new AttributeLabel();
     $defaultLabel->setValue('default');
     $firstLocale = $this->createLocale(1);
     $firstLocaleLabel = new AttributeLabel();
     $firstLocaleLabel->setValue('first')->setLocale($firstLocale);
     $secondLocale = $this->createLocale(2);
     $secondLocaleLabel = new AttributeLabel();
     $secondLocaleLabel->setValue('second')->setLocale($secondLocale);
     $attribute = new Attribute();
     $attribute->resetLabels([$defaultLabel, $firstLocaleLabel, $secondLocaleLabel]);
     $this->assertEquals($defaultLabel, $attribute->getLabelByLocaleId(null));
     $this->assertEquals($firstLocaleLabel, $attribute->getLabelByLocaleId($firstLocale->getId()));
     $this->assertEquals($secondLocaleLabel, $attribute->getLabelByLocaleId($secondLocale->getId()));
     $this->assertNull($attribute->getLabelByLocaleId(42));
 }