/**
  * @param Attribute $attribute
  * @param array $options
  */
 public function setDefaultOptions(Attribute $attribute, array $options)
 {
     $attributeOptions = [];
     $attributeDefaultValues = [];
     foreach ($options as $optionData) {
         $order = $this->getOption($optionData, 'order', 0);
         $data = $this->getOption($optionData, 'data', []);
         $masterOptionId = $this->getOption($optionData, 'master_option_id');
         $masterOption = $attribute->getOptionById($masterOptionId);
         if (!$masterOption) {
             $masterOption = new AttributeOption();
             $attribute->addOption($masterOption);
         }
         foreach ($data as $localeId => $localeData) {
             $localeValue = $this->getOption($localeData, 'value', '');
             $option = $this->generateOption($masterOption, $localeId, $localeValue, $order);
             $attributeOptions[] = $option;
             if (!empty($localeData['is_default'])) {
                 $attributeDefaultValues[] = $this->generateOptionDefaultValue($attribute, $option, $localeId);
             }
         }
     }
     $this->propertyAccessor->setValue($attribute, 'options', $attributeOptions);
     $this->propertyAccessor->setValue($attribute, 'defaultValues', $attributeDefaultValues);
 }
Example #2
0
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Several attribute options found by the same option ID.
  */
 public function testGetOptionByIdException()
 {
     $firstOption = $this->createAttributeOption(1);
     $secondOption = $this->createAttributeOption(1);
     $attribute = new Attribute();
     $attribute->resetOptions([$firstOption, $secondOption]);
     $attribute->getOptionById(1);
 }