Question

for some reasons I need to alter the $_items array from the class Magento\Framework\Data\Collection

That variable is set as protected, so as,if I try to do something like this $this->_collection->_items = $filteredItems; It won't work because of the protected access.

So now I know, that we are not supposed to modify this variables and the collection should be able to be sorted using her own methods.

But sadly for some reasons, for the attribute I am working on this isn't working at all, so I had to take the items and sort it by myself.

The sort works fine...and now I just need to replace the not sorted items with my sorted items.

Do you see any solution that might allow me to do that ? Considering there isn't any getter provided for this attribute.

If i'm creating a preference for this class, and extend it to add a simple getter, will the attribute be accessible or it won't work still because of the protected access ?

Thanks for the solutions you might provides.

Was it helpful?

Solution

You can extend the class by creating a preference, then you can modify whatever you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top