Skip to content

Instantly share code, notes, and snippets.

@Nav-Appaiya
Created September 6, 2016 08:55
Show Gist options
  • Save Nav-Appaiya/892d759c1749fb9241ce169afe213f68 to your computer and use it in GitHub Desktop.
Save Nav-Appaiya/892d759c1749fb9241ce169afe213f68 to your computer and use it in GitHub Desktop.
Magento 2 get all attributes from the default products attribute set (id: 4)
<?php
/** @var $coll \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection */
$coll = $this->_objectManager->create(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class);
// add filter by entity type to get product attributes only
// '4' is the default type ID for 'catalog_product' entity - see 'eav_entity_type' table)
// or skip the next line to get all attributes for all types of entities
$coll->addFieldToFilter(\Magento\Eav\Model\Entity\Attribute\Set::KEY_ENTITY_TYPE_ID, 4);
$attrAll = $coll->load()->getItems();
@jegacs
Copy link

jegacs commented Jan 28, 2019

What if I need to fetch the attributes that are not included in the default attribute set?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment