Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function addOption($id, EavOption $option)
 {
     $model = $this->eavConfig->getAttribute(ProductMetadataServiceInterface::ENTITY_TYPE, $id);
     if (!$model || !$model->getId()) {
         throw NoSuchEntityException::singleField(AttributeMetadata::ATTRIBUTE_ID, $id);
     }
     if (!$model->usesSource()) {
         throw new StateException('Attribute doesn\'t have any option');
     }
     $key = 'new_option';
     $options = [];
     $options['value'][$key][0] = $option->getLabel();
     $options['order'][$key] = $option->getOrder();
     if (is_array($option->getStoreLabels())) {
         foreach ($option->getStoreLabels() as $label) {
             $options['value'][$key][$label->getStoreId()] = $label->getLabel();
         }
     }
     if ($option->isDefault()) {
         $model->setDefault([$key]);
     }
     $model->setOption($options);
     $model->save();
     return true;
 }