![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-review/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Review\Model; use Magento\Framework\Model\AbstractModel; use Magento\Review\Model\ResourceModel\Review\Summary\CollectionFactory as SummaryCollectionFactory; /** * Add review summary data to object by its entity code */ class AppendSummaryData { /** * @var SummaryCollectionFactory */ private $summaryCollectionFactory; /** * @param SummaryCollectionFactory $summaryCollectionFactory */ public function __construct( SummaryCollectionFactory $summaryCollectionFactory ) { $this->summaryCollectionFactory = $summaryCollectionFactory; } /** * Append summary data to object filtered by its entity code * * @param AbstractModel $object * @param int $storeId * @param string $entityCode * @retrun void */ public function execute(AbstractModel $object, int $storeId, string $entityCode): void { $summaryCollection = $this->summaryCollectionFactory->create(); $summaryCollection->addStoreFilter($storeId); $summaryCollection->getSelect() ->joinLeft( ['review_entity' => $summaryCollection->getResource()->getTable('review_entity')], 'main_table.entity_type = review_entity.entity_id', 'entity_code' ) ->where('entity_pk_value = ?', $object->getId()) ->where('entity_code = ?', $entityCode); $summaryItem = $summaryCollection->getFirstItem(); $object->addData( [ 'reviews_count' => $summaryItem->getData('reviews_count'), 'rating_summary' => $summaryItem->getData('rating_summary'), ] ); } }