Skip to content

Commit 398d685

Browse files
author
Ievgen Sentiabov
committed
MAGETWO-44113: Creating Ratings in the Frontend (not available after Magento installation)
- Added cache skipping after rating entity saving
1 parent 24abff1 commit 398d685

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

app/code/Magento/Review/Model/Rating.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Review\Model;
77

8+
use Magento\Framework\DataObject\IdentityInterface;
9+
use Magento\Store\Model\Store;
10+
811
/**
912
* Rating model
1013
*
@@ -18,7 +21,7 @@
1821
*
1922
* @author Magento Core Team <core@magentocommerce.com>
2023
*/
21-
class Rating extends \Magento\Framework\Model\AbstractModel
24+
class Rating extends \Magento\Framework\Model\AbstractModel implements IdentityInterface
2225
{
2326
/**
2427
* rating entity codes
@@ -161,4 +164,15 @@ public function getEntityIdByCode($entityCode)
161164
{
162165
return $this->getResource()->getEntityIdByCode($entityCode);
163166
}
167+
168+
/**
169+
* Return unique ID(s) for each object in system
170+
*
171+
* @return array
172+
*/
173+
public function getIdentities()
174+
{
175+
// skip cache for all store
176+
return [Store::CACHE_TAG];
177+
}
164178
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Review\Model;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
use Magento\Store\Model\Store;
10+
use Magento\Review\Model\Rating;
11+
12+
class RatingTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var \Magento\Review\Model\Rating
16+
*/
17+
private $rating;
18+
19+
/**
20+
* Init objects needed by tests
21+
*/
22+
protected function setUp()
23+
{
24+
$helper = new ObjectManager($this);
25+
$this->rating = $helper->getObject(Rating::class);
26+
}
27+
28+
/**
29+
* @covers \Magento\Review\Model\Rating::getIdentities()
30+
* @return void
31+
*/
32+
public function testGetIdentities()
33+
{
34+
static::assertEquals([Store::CACHE_TAG], $this->rating->getIdentities());
35+
}
36+
}

0 commit comments

Comments
 (0)