Skip to content

Commit 7bd47cd

Browse files
ENGCOM-5337: Get review entity id by code instead hard-coded. #23353
- Merge Pull Request #23353 from DaniloEmpire/magento2:fix/save-review-from-adminhtml - Merged commits: 1. 78af5b8 2. a3016bc
2 parents acfafe0 + a3016bc commit 7bd47cd

File tree

2 files changed

+13
-2
lines changed
  • app/code/Magento/Review

2 files changed

+13
-2
lines changed

app/code/Magento/Review/Controller/Adminhtml/Product/Post.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
use Magento\Framework\Controller\ResultFactory;
1111
use Magento\Store\Model\Store;
1212
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Review\Model\Review;
1314

15+
/**
16+
* Review admin controller for POST request.
17+
*/
1418
class Post extends ProductController implements HttpPostActionInterface
1519
{
1620
/**
21+
* Create a product review.
22+
*
1723
* @return \Magento\Backend\Model\View\Result\Redirect
1824
*/
1925
public function execute()
@@ -33,7 +39,7 @@ public function execute()
3339
}
3440
$review = $this->reviewFactory->create()->setData($data);
3541
try {
36-
$review->setEntityId(1) // product
42+
$review->setEntityId($review->getEntityIdByCode(Review::ENTITY_PRODUCT_CODE))
3743
->setEntityPkValue($productId)
3844
->setStoreId(Store::DEFAULT_STORE_ID)
3945
->setStatusId($data['status_id'])

app/code/Magento/Review/Test/Unit/Controller/Adminhtml/Product/PostTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Review\Test\Unit\Controller\Adminhtml\Product;
77

88
use Magento\Framework\Controller\ResultFactory;
9+
use Magento\Review\Model\Review;
910

1011
/**
1112
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -109,7 +110,7 @@ protected function _prepareMockObjects()
109110
$this->storeModelMock = $this->createPartialMock(\Magento\Store\Model\Store::class, ['__wakeup', 'getId']);
110111
$this->reviewMock = $this->createPartialMock(
111112
\Magento\Review\Model\Review::class,
112-
['__wakeup', 'create', 'save', 'getId', 'getResource', 'aggregate']
113+
['__wakeup', 'create', 'save', 'getId', 'getResource', 'aggregate', 'getEntityIdByCode']
113114
);
114115
$this->reviewFactoryMock = $this->createPartialMock(\Magento\Review\Model\ReviewFactory::class, ['create']);
115116
$this->ratingMock = $this->createPartialMock(
@@ -174,6 +175,10 @@ public function testPostAction()
174175
$this->reviewMock->expects($this->once())
175176
->method('aggregate')
176177
->willReturn($this->reviewMock);
178+
$this->reviewMock->expects($this->once())
179+
->method('getEntityIdByCode')
180+
->with(Review::ENTITY_PRODUCT_CODE)
181+
->willReturn(1);
177182
$this->ratingMock->expects($this->once())
178183
->method('setRatingId')
179184
->willReturnSelf();

0 commit comments

Comments
 (0)