I am really pulling out my hair. I have a function to return all product attributes in my Magento 2 Module:
public function getAllProductAttributes(): array
{
$attributes = [];
$collection = $this->attributeCollectionFactory->create();
foreach ($collection as $attribute) {
$attributes[$attribute->getAttributeCode()] = $attribute;
}
return $attributes;
}
MagentoCatalogModelResourceModelProductAttributeCollectionFactory is the $attributeCollectionFactory.
I have not been able to 100% determine if an attribute is considered “custom” or “normal”, meaning if I have to set it with setCustomAttribute() or setData().
“is_user_defined
” doesn’t work, since for example the product “description” is set by setCustomAttribute() but is not user defined. I tried multiple combinations of attribute parameters, however nothing worked.
Anyone have a solution?