/**
  * {@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 Attribute $attribute
  * @param array $labels
  */
 public function setLabels(Attribute $attribute, array $labels)
 {
     foreach ($labels as $localeId => $label) {
         $attributeLabel = $attribute->getLabelByLocaleId($localeId);
         if (!$attributeLabel) {
             $attributeLabel = new AttributeLabel();
             if ($localeId) {
                 $attributeLabel->setLocale($this->databaseHelper->findLocale($localeId));
             }
             $attribute->addLabel($attributeLabel);
         }
         if ($label instanceof FallbackType) {
             $attributeLabel->setValue(null)->setFallback($label->getType());
         } else {
             $attributeLabel->setValue($label)->setFallback(null);
         }
     }
 }
 /**
  * @param int|null $localeId
  * @param string $value
  * @param string|null $fallback
  * @return AttributeLabel
  */
 protected function createLabel($localeId, $value, $fallback = null)
 {
     $locale = null;
     if ($localeId) {
         $locale = $this->getLocale($localeId);
     }
     $label = new AttributeLabel();
     $label->setLocale($locale)->setValue($value)->setFallback($fallback);
     return $label;
 }
Esempio n. 4
0
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Several attribute labels found by the same locale ID.
  */
 public function testGetLabelByLocaleIdException()
 {
     $locale = $this->createLocale(1);
     $firstLabel = new AttributeLabel();
     $firstLabel->setLocale($locale);
     $secondLabel = new AttributeLabel();
     $secondLabel->setLocale($locale);
     $attribute = new Attribute();
     $attribute->resetLabels([$firstLabel, $secondLabel]);
     $attribute->getLabelByLocaleId(1);
 }