Domanda

I have created one custom attribute for Category with Multi select option.I am trying to get dynamic values from source file but first value only printing in multi select please give solution and check my code what i did wrong. `

    $school_model = $this->_modelCreateFactory->create();
    $data = $school_model->getCollection()->getData();
    $value1 = array();
    foreach ($data as $key => $value) {
          if(!empty($value['school_id']))
          {
            if ($this->_options === null) {
                $value1[$key]['school_id'] =  $value['school_id'];
                $value1[$key]['school_name'] = $value['school_name'];

                $this->_options =[  [
                                       'value' => $value1[$key]['school_id'],
                                       'label' => __($value1[$key]['school_name'])
                                    ]
                                 ];
            }
          }
        }

    return $this->_options;
}`
È stato utile?

Soluzione

form an array like this. It will work

// Added brands

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $collection = $objectManager->create('Vendor\Mysize\Model\Brand');
    $option = $collection->getCollection();
    $optionsArray =[];
    foreach($option as $optionValues) { 
          $optionsArray [] = [
            'label' =>  $optionValues,
            'value' => $optionValues
      ];
        }
        return $optionsArray;


}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top