Skip to content

Remove short description reset from product review block #35148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app/code/Magento/Review/Block/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Review\Block\Product;

use Magento\Catalog\Api\ProductRepositoryInterface;
Expand All @@ -21,14 +24,14 @@ class View extends \Magento\Catalog\Block\Product\View
*
* @var ReviewCollection
*/
protected $_reviewsCollection;
protected ReviewCollection $_reviewsCollection;

/**
* Review resource model
*
* @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory
*/
protected $_reviewsColFactory;
protected \Magento\Review\Model\ResourceModel\Review\CollectionFactory $_reviewsColFactory;

/**
* @param \Magento\Catalog\Block\Product\Context $context
Expand Down Expand Up @@ -88,8 +91,6 @@ protected function _toHtml()
return '';
}

$product->setShortDescription(null);

return parent::_toHtml();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update this file according to this file?

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

declare(strict_types=1);

namespace Magento\Review\Block\Product;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;

/**
 * Product Reviews Page
 *
 * @author     Magento Core Team <core@magentocommerce.com>
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class View extends \Magento\Catalog\Block\Product\View
{
    /**
     * Review collection
     *
     * @var ReviewCollection
     */
    protected ReviewCollection $_reviewsCollection;

    /**
     * Review resource model
     *
     * @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory
     */
    protected \Magento\Review\Model\ResourceModel\Review\CollectionFactory $_reviewsColFactory;

    /**
     * @param \Magento\Catalog\Block\Product\Context $context
     * @param \Magento\Framework\Url\EncoderInterface $urlEncoder
     * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
     * @param \Magento\Framework\Stdlib\StringUtils $string
     * @param \Magento\Catalog\Helper\Product $productHelper
     * @param \Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig
     * @param \Magento\Framework\Locale\FormatInterface $localeFormat
     * @param \Magento\Customer\Model\Session $customerSession
     * @param ProductRepositoryInterface $productRepository
     * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
     * @param \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory
     * @param array $data
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
     */
    public function __construct(
        \Magento\Catalog\Block\Product\Context                       $context,
        \Magento\Framework\Url\EncoderInterface                      $urlEncoder,
        \Magento\Framework\Json\EncoderInterface                     $jsonEncoder,
        \Magento\Framework\Stdlib\StringUtils                        $string,
        \Magento\Catalog\Helper\Product                              $productHelper,
        \Magento\Catalog\Model\ProductTypes\ConfigInterface          $productTypeConfig,
        \Magento\Framework\Locale\FormatInterface                    $localeFormat,
        \Magento\Customer\Model\Session                              $customerSession,
        ProductRepositoryInterface                                   $productRepository,
        \Magento\Framework\Pricing\PriceCurrencyInterface            $priceCurrency,
        \Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory,
        array                                                        $data = []
    ) {
        $this->_reviewsColFactory = $collectionFactory;
        parent::__construct(
            $context,
            $urlEncoder,
            $jsonEncoder,
            $string,
            $productHelper,
            $productTypeConfig,
            $localeFormat,
            $customerSession,
            $productRepository,
            $priceCurrency,
            $data
        );
    }

    /**
     * Render block HTML
     *
     * @return string
     */
    protected function _toHtml()
    {
        $product = $this->getProduct();
        if (!$product) {
            return '';
        }
        return parent::_toHtml();
    }

    /**
     * Replace review summary html with more detailed review summary
     *
     * Reviews collection count will be jerked here
     *
     * @param \Magento\Catalog\Model\Product $product
     * @param bool $templateType
     * @param bool $displayIfNoReviews
     * @return string
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function getReviewsSummaryHtml(
        \Magento\Catalog\Model\Product $product,
        $templateType = false,
        $displayIfNoReviews = false
    ): string {
        return $this->getLayout()->createBlock(
            \Magento\Review\Block\Rating\Entity\Detailed::class
        )->setEntityId(
            $this->getProduct()->getId()
        )->toHtml() . $this->getLayout()->getBlock(
            'product_review_list.count'
        )->assign(
            'count',
            $this->getReviewsCollection()->getSize()
        )->toHtml();
    }

    /**
     * Get collection of reviews
     *
     * @return ReviewCollection
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     */
    public function getReviewsCollection(): ReviewCollection
    {
        if (null === $this->_reviewsCollection) {
            $this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter(
                $this->_storeManager->getStore()->getId()
            )->addStatusFilter(
                \Magento\Review\Model\Review::STATUS_APPROVED
            )->addEntityFilter(
                'product',
                $this->getProduct()->getId()
            )->setDateOrder();
        }
        return $this->_reviewsCollection;
    }

    /**
     * Force product view page behave like without options
     *
     * @return bool
     */
    public function hasOptions(): bool
    {
        return false;
    }
}


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Sorry, I'm not sure I follow. Is there some sort of conflict, or what seems to be the issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aapokiiso , this shared code is following coding standards, can you please review it and update your pull request?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aapokiiso any update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manavluhar Hi! I've updated the file now.

Expand All @@ -103,12 +104,13 @@ protected function _toHtml()
* @param bool $displayIfNoReviews
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getReviewsSummaryHtml(
\Magento\Catalog\Model\Product $product,
$templateType = false,
$displayIfNoReviews = false
) {
): string {
return $this->getLayout()->createBlock(
\Magento\Review\Block\Rating\Entity\Detailed::class
)->setEntityId(
Expand All @@ -125,8 +127,9 @@ public function getReviewsSummaryHtml(
* Get collection of reviews
*
* @return ReviewCollection
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getReviewsCollection()
public function getReviewsCollection(): ReviewCollection
{
if (null === $this->_reviewsCollection) {
$this->_reviewsCollection = $this->_reviewsColFactory->create()->addStoreFilter(
Expand All @@ -146,7 +149,7 @@ public function getReviewsCollection()
*
* @return bool
*/
public function hasOptions()
public function hasOptions(): bool
{
return false;
}
Expand Down