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

Conversation

aapokiiso
Copy link
Contributor

@aapokiiso aapokiiso commented Feb 28, 2022

Description (*)

For unknown reasons, the product review block resets the short description in product data. This PR removes the code that causes the product short description to be reset whenever reviews are rendered.

Manual testing scenarios (*)

  1. Create a product that has a short description.
  2. Via layout XML, move the reviews.tab block to the beginning of the content container for the catalog_product_view handle. This is done to create a testing scenario where the product reviews block is rendered before the short description block product.info.overview on the product page.
  3. Go to the product page. Observe that that the short description is not displayed, even though it should. This is because \Magento\Review\Block\Product\View::_toHtml resets the product's short description.

Questions or comments

I could not find any reason why this code exists. It seems to have been an issue all the way in Magento 1.9 (example issue from StackOverflow). The code in question has been present in the Magento 2 code base for a long time, having been migrated from Magento 1 (link to commit).

This seems to be a legacy workaround all the way from Magento 1, hopefully no longer necessary. I would love to know if anyone has any additional information.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

For unknown reasons, the product review block removes resets
the short description in product data. This seems to be a legacy
workaround all the way from Magento 1.
@m2-assistant
Copy link

m2-assistant bot commented Feb 28, 2022

Hi @aapokiiso. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@aapokiiso
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@aapokiiso
Copy link
Contributor Author

The failing functional tests seem unrelated to this change.

@sdzhepa sdzhepa added the Priority: P3 May be fixed according to the position in the backlog. label Mar 10, 2022
@@ -88,8 +88,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 <[email protected]>
 * @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.

@manavluhar
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Review Priority: P3 May be fixed according to the position in the backlog. Progress: review Release Line: 2.4
Projects
Status: Review in Progress
Development

Successfully merging this pull request may close these issues.

4 participants