I'm trying to save review programmatically. This seems to be working but not totally and as it's using object manager; I would like to find the good proper way to handle this in Magento 2.
So basically my question is: How to replace this piece of code to make it "clean"
$stores=array(
$this->block->getStoreId($this->block::STORE_CODE_PARTICULIER),
$this->block->getStoreId($this->block::STORE_CODE_PRO)
);
$objectManager = ObjectManager::getInstance();
$_review = $objectManager->get("Magento\Review\Model\Review")
->setEntityPkValue($productId)
->setStatusId($statusReview)
->setTitle($reviewTitle)
->setDetail($reviewDetail)
->setEntityId(1)
->setStoreId($store_id)
->setStores($stores)
->setCustomerId($customerId)
->setNickname($customerNickName)
->save();
I wanted to find a repository for this review but seems like it doesn't exist?
Currently, this code works, but the behavior is odd (it's an import script...if I try to import one by one, my reviews are well created...but if I try to create more than 1, it will still only create one of them. That's why I suspect an unexpected behavior due to object manager being used.
Is there a better way to handle this?
Maybe I have to load the product and in fact, save the product more than the review itself?
Please let me know how you would handle this!