1

I am using a source model for fields of the configuration. I want to get all product attributes (no matter the product or the attribute set) in this source model.

1
  • Can you describe your requirement in detail, what actual you want to do? Feb 18 '17 at 9:57
1

Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;

Magento\Eav\Model\Entity\Attribute;

pass the AttributeCollectionFactory to your constructor.

ex :

    public function __construct(
        \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributecollectionFactory

              .
              .
              .
     //other arguments
    ) {
        $this->attributeCollectionFactory = $attributecollectionFactory;
    }

and add this function.

 protected function getAllAttributes()
    {
        $attributeCollection = $this->attributecollectionFactory->create();

        /**
         * If you want only filterable attributes.
         * and add filters as per your requirement.
         */
        $attributeCollection->addIsFilterableFilter();

        return $attributeCollection->getItems();
    }
1
  • Perfect! Exactly what I was looking for! Just needed to modify the di.xml file to pass the AttributeCollectionFactory to the constructor (what I was missing).
    – Thomas F
    Feb 20 '17 at 9:14

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.