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()
323323 */
324324 public function getIdentities ()
325325 {
326- $ identities = $ this ->getProduct ()-> getIdentities ();
326+ $ product = $ this ->getProduct ();
327327
328- return $ identities ;
328+ return $ product ? $ product -> getIdentities () : [] ;
329329 }
330330
331331 /**
Original file line number Diff line number Diff line change @@ -82,13 +82,20 @@ public function __construct(
8282 */
8383 protected function _toHtml ()
8484 {
85- $ this ->getProduct ()->setShortDescription (null );
85+ $ product = $ this ->getProduct ();
86+
87+ if (!$ product ) {
88+ return '' ;
89+ }
90+
91+ $ product ->setShortDescription (null );
8692
8793 return parent ::_toHtml ();
8894 }
8995
9096 /**
9197 * Replace review summary html with more detailed review summary
98+ *
9299 * Reviews collection count will be jerked here
93100 *
94101 * @param \Magento\Catalog\Model\Product $product
Original file line number Diff line number Diff line change @@ -55,7 +55,10 @@ protected function _prepareLayout()
5555 */
5656 protected function _beforeToHtml ()
5757 {
58- $ this ->getReviewsCollection ()->load ()->addRateVotes ();
58+ if ($ this ->getProductId ()) {
59+ $ this ->getReviewsCollection ()->load ()->addRateVotes ();
60+ }
61+
5962 return parent ::_beforeToHtml ();
6063 }
6164
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