I am trying to get an a array of attributes by attribute set $id. I need to display a list of attribute names as dropdown. (I am running code in localhost if that matters and magento version 2.0.7)
WHAT I HAVE DONE SO FAR:
- I have read stackexchange.com post and tried to implement it.
- I have deleted var folder content in Magento root folder before page refresh.
- logged $attributeSet and assured it returns 4 what is in DB entity_type_id number i try to get.
Using log i have found out that the $attributes query, what comes back is:
[2016-07-07 23:35:19] main.DEBUG: {"73":{},"97":{},"85":{},"98":{},"75":{},"86":{},"99":{},"128":{},"76":{},"87":{},"100":{},"77":{},"93":{},"101":{},"78":{},"88":{},"103":{},"89":{},"95":{},"117":{},"70":{},"115":{},"118":{},"116":{},"122":{},"104":{},"105":{},"106":{},"107":{},"108":{},"109":{},"71":{},"81":{},"96":{},"110":{},"74":{},"82":{},"91":{},"83":{},"92":{},"129":{},"84":{},"111":{},"112":{},"130":{},"79":{},"102":{},"72":{},"94":{},"119":{},"120":{},"121":{},"123":{},"124":{},"125":{},"126":{},"127":{}} {"is_exception":false} []
Code I am using is:
public function _renderCellTemplate($columnName) {
if (empty($this->_columns[$columnName])) {
throw new Exception('Wrong column name specified.');
}
$column = $this->_columns[$columnName];
$inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
if ($column['renderer']) {
return $column['renderer']->setInputName($inputName)->setColumnName($columnName)->setColumn($column)->toHtml();
}
if($columnName == 'magento_attribute') {
$rendered = '<select name="'.$inputName.'">';
$attributeSet = $this->scopeConfig->getValue('eepohs_erply/product/attribute_set');
$attributes = $this->_productAttributeManagementInterface->getAttributes($attributes);
$this->_logger->debug(json_encode($attributes));
foreach($attributes as $attribute) {
$rendered .= '<option value="'.$attribute["code"].'">'.$attribute["code"].'</option>';
}
$rendered .= '</select>'; return $rendered;
}
return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}"'
. ($column['size'] ? 'size="' . $column['size'] . '"' : '') . ' class="' .
(isset($column['class']) ? $column['class'] : 'input-text') . '"'. (isset($column['style']) ? '
style="'.$column['style'] . '"' : '') . '/>';
}
Why it returns a list of array with attributes numbers but nothing else inside the sub array it contains? From old code in Magento 1.9.2 i get in log:
[0] => Array (
[attribute_id] => 71
[code] => name
[type] => text
[required] => 1
[scope] => store )
Duplicate from stackexchange.com (not solved).