Hello i have to add extension attributes to Magento\Catalog\Api\Data\ProductInterface

So i added this one to extension_attrributes.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="Magento\Catalog\Api\Data\ProductInterface">
        <attribute code="custom_attribute" type="int"/>

And to di.xml added:

<type name="Magento\Framework\EntityManager\Operation\ExtensionPool">
            <argument name="extensionActions" xsi:type="array">
                <item name="Magento\Catalog\Api\Data\ProductInterface" xsi:type="array">
                    <item name="read" xsi:type="array">
                        <item name="customAttributeReader" xsi:type="string">Vendor\Custom\Model\Product\CustomAttribute\ReadHandler</item>
                    <item name="create" xsi:type="array">
                        <item name="customAttributeCreator" xsi:type="string">Vendor\Custom\Model\Product\CustomAttribute\SaveHandler</item>

                    <item name="update" xsi:type="array">
                        <item name="customAttributeSaver" xsi:type="string">Vendor\Custom\Model\Product\CustomAttribute\SaveHandler</item>

So it`s work fine. When i get product entity using ProductRepository or load() function in Product model, all my extension attributes loads successful. But i have some issue when i work with Collection:

When i do something like:

$productCollection->addFieldToFilter('custom_attribute', 2);

My code don't wok and it's expected because my model not contains this attribute.

So i have a question. How i can filter by my extension attribute using collection ?

Also if i do:


I get empty array.

So i need your help. I'll be very grateful!!!

1 Answer 1


I added extension attributes with repository plugin. And works fine. But only with repository, so I'm also looking for solution.

Your Answer

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

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