-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
base: 2.4-develop
Are you sure you want to change the base?
Remove short description reset from product review block #35148
Conversation
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.
Hi @aapokiiso. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
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. 🕙 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 |
@magento run all tests |
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. |
The failing functional tests seem unrelated to this change. |
@@ -88,8 +88,6 @@ protected function _toHtml() | |||
return ''; | |||
} | |||
|
|||
$product->setShortDescription(null); | |||
|
|||
return parent::_toHtml(); | |||
} | |||
|
There was a problem hiding this comment.
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;
}
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @aapokiiso any update?
There was a problem hiding this comment.
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.
@magento run all tests |
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. |
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 (*)
reviews.tab
block to the beginning of thecontent
container for thecatalog_product_view
handle. This is done to create a testing scenario where the product reviews block is rendered before the short description blockproduct.info.overview
on the product page.\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 (*)