I'm trying to make the status of a review be approved
instead of pending
when the user posts it in the frontend in Magento 2.
And I took this approach. Create a before plugin, available only in the frontend area, for the method setStatusId
for the Magento\Review\Model\Review
that looks like this
public function beforeSetStatusId(\Magento\Review\Model\Review $review, $status)
{
return [\Magento\Review\Model\Review::STATUS_APPROVED];
}
It seamed to me like a good idea. And it should work since I'm returning the approved status. The actual method should then pick this up as a parameter.
but to my surprise it didn't work.
Then I dug up and found that the method setStatusId
does not exist in the review model. It is magically called and it actually runs setData('status_id', $status)
.
I took a look then in the generated interceptor, and indeed there is not setStatusId
method.
How can I pluginize the magic getters/setters in magento 2? Is that even possible?
Note: I don't need a solution for making the reviews auto-approved. I know I can take other approaches, like the save_before
events. This is not important for now.