public function testConstructorAndGetters() { $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $optionBuilder = $helper->getObject('\\Magento\\Catalog\\Service\\V1\\Data\\Eav\\OptionBuilder'); $optionBuilder->setLabel(self::LABEL)->setValue(self::VALUE); $option = new Option($optionBuilder); $this->assertSame(self::LABEL, $option->getLabel()); $this->assertSame(self::VALUE, $option->getValue()); }
/** * {@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; }