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? Commented Feb 18, 2017 at 9:57

1 Answer 1

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). Commented Feb 20, 2017 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.