0

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.

1

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

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.