Find and reference standard attribute types in Akeneo code

All standard attribute types available in Akeneo are listed in “\Akeneo\Pim\Structure\Component\AttributeTypes” (File: src/Akeneo/Pim/Structure/Component/AttributeTypes.php).

In you own code you could (and should) reference these types instead of using strings.  For example lets say you want to delete attributes by an array of attribute codes but you want to skip identifier attributes from deletion.

Get all attribute options

To get all attribute options from a Magento dropdown attribute (select field) you can use the following snippet:

That gives you an array like that:

This can be used as source for a system config field for example. See my blogpost about Category dropdown element. To get a specific value by given label, you can […]

Load product attributes more performant

Recently I had performance issues when importing several ten tausend products. The problem was, that I always used the “normal” product entity model to load attribute values. The following snippet shows, how to load product attributes directly instead. Therefore I use the product resource singleton.

Get product attribute ID in Magento

This is how to get product EAV attribute ID without querying the database directly: