/**
  * @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);
         }
     }
 }
Ejemplo n.º 2
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);
 }