File tree Expand file tree Collapse file tree 4 files changed +63
-4
lines changed Expand file tree Collapse file tree 4 files changed +63
-4
lines changed Original file line number Diff line number Diff line change @@ -323,9 +323,9 @@ public function getQuantityValidators()
323
323
*/
324
324
public function getIdentities ()
325
325
{
326
- $ identities = $ this ->getProduct ()-> getIdentities ();
326
+ $ product = $ this ->getProduct ();
327
327
328
- return $ identities ;
328
+ return $ product ? $ product -> getIdentities () : [] ;
329
329
}
330
330
331
331
/**
Original file line number Diff line number Diff line change @@ -82,13 +82,20 @@ public function __construct(
82
82
*/
83
83
protected function _toHtml ()
84
84
{
85
- $ this ->getProduct ()->setShortDescription (null );
85
+ $ product = $ this ->getProduct ();
86
+
87
+ if (!$ product ) {
88
+ return '' ;
89
+ }
90
+
91
+ $ product ->setShortDescription (null );
86
92
87
93
return parent ::_toHtml ();
88
94
}
89
95
90
96
/**
91
97
* Replace review summary html with more detailed review summary
98
+ *
92
99
* Reviews collection count will be jerked here
93
100
*
94
101
* @param \Magento\Catalog\Model\Product $product
Original file line number Diff line number Diff line change @@ -55,7 +55,10 @@ protected function _prepareLayout()
55
55
*/
56
56
protected function _beforeToHtml ()
57
57
{
58
- $ this ->getReviewsCollection ()->load ()->addRateVotes ();
58
+ if ($ this ->getProductId ()) {
59
+ $ this ->getReviewsCollection ()->load ()->addRateVotes ();
60
+ }
61
+
59
62
return parent ::_beforeToHtml ();
60
63
}
61
64
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Test class for \Magento\Review\Block\Product\View\ListView
4
+ *
5
+ * Copyright © Magento, Inc. All rights reserved.
6
+ * See COPYING.txt for license details.
7
+ */
8
+
9
+ namespace Magento \Review \Test \Unit \Block \Product ;
10
+
11
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
+ use Magento \Review \Block \Product \View \ListView ;
13
+ use PHPUnit \Framework \TestCase ;
14
+
15
+ /**
16
+ * Class ViewTest
17
+ */
18
+ class ListViewTest extends TestCase
19
+ {
20
+ /**
21
+ * @var ListView
22
+ */
23
+ private $ listView ;
24
+
25
+ /**
26
+ * @var ObjectManager
27
+ */
28
+ private $ objectManager ;
29
+
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ protected function setUp ()
34
+ {
35
+ $ this ->objectManager = new ObjectManager ($ this );
36
+ $ this ->listView = $ this ->objectManager ->getObject (
37
+ ListView::class
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Validate that ListView->toHtml() would not crush if provided product is null
43
+ */
44
+ public function testBlockShouldNotFailWithNullProduct ()
45
+ {
46
+ $ output = $ this ->listView ->toHtml ();
47
+ $ this ->assertEquals ('' , $ output );
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments