I'm looking for a way to get all products that belong to a certain attribute set, say 'Gloves'. I have look around online to see if I could find a way but could only find the code below which I believe is for Magento 1 because I'm getting a 500 error code. Also it is a .phtml template where I'm trying to get this data.

This is the code I have tried:

//Fetch attribute set id by attribute set name
$attrSetName = 'Gloves';
$attributeSetId = Mage::getModel('eav/entity_attribute_set')
    ->load($attrSetName, 'Helmets')

//Load product model collecttion filtered by attribute set id
$products = Mage::getModel('catalog/product')
    ->addFieldToFilter('attribute_set_id', $attributeSetId);

//process your product collection as per your bussiness logic
$productsName = array();
foreach($products as $p){
    $productsName[] = $p->getData('name');

Any help or pointers would be greatly appreciated.


Please check this quick code, and try to optimize it as you wish,

$objectManager=   \Magento\Framework\App\ObjectManager::getInstance();

$attrSetName = 'Default';
$attribute_set_factoryCollection = $objectManager->get('\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory');

$attribute_set_collection = $attribute_set_factoryCollection->create();


$att_set = current($attribute_set_collection->getData());
$attribute_set_id = $att_set["attribute_set_id"];

$factoryCollection = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $factoryCollection->create();

$productsName = array();
foreach ($collection as $item) {
    $productsName[] =  $item->getName();
| improve this answer | |
  • This worked like a charm, thank you soo much :) – Daniel Black Apr 27 '18 at 19:32
  • I am glad to hear this, you are welcome – WISAM HAKIM Apr 27 '18 at 20:35
  • its working perfectly – Bhagyashri Pawar Dec 18 '19 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.