示例#1
0
 /**
  * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
  * @param array|\Magento\Eav\Model\Resource\Entity\Attribute\Option\Collection $optionCollection
  * @return array
  */
 protected function _prepareOptionValues(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute, $optionCollection)
 {
     $type = $attribute->getFrontendInput();
     if ($type === 'select' || $type === 'multiselect') {
         $defaultValues = explode(',', $attribute->getDefaultValue());
         $inputType = $type === 'select' ? 'radio' : 'checkbox';
     } else {
         $defaultValues = [];
         $inputType = '';
     }
     $values = [];
     $isSystemAttribute = is_array($optionCollection);
     foreach ($optionCollection as $option) {
         $bunch = $isSystemAttribute ? $this->_prepareSystemAttributeOptionValues($option, $inputType, $defaultValues) : $this->_prepareUserDefinedAttributeOptionValues($option, $inputType, $defaultValues);
         foreach ($bunch as $value) {
             $values[] = new \Magento\Framework\Object($value);
         }
     }
     return $values;
 }