Commit 1e8180e7 by lmf

删除插件onepagecheckout 和 评论插件

parent 7f70cfff
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api;
/**
* @api
*/
interface CommentRepositoryInterface
{
/**
* Save
*
* @param \Amasty\AdvancedReview\Api\Data\CommentInterface $comment
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function save(\Amasty\AdvancedReview\Api\Data\CommentInterface $comment);
/**
* Get by id
*
* @param int $id
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById($id);
/**
* Delete
*
* @param \Amasty\AdvancedReview\Api\Data\CommentInterface $comment
*
* @return bool true on success
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(\Amasty\AdvancedReview\Api\Data\CommentInterface $comment);
/**
* Delete by id
*
* @param int $id
*
* @return bool true on success
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function deleteById($id);
/**
* Lists
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
*
* @return \Magento\Framework\Api\SearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
/**
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function getComment();
/**
* @param int $reviewId
*
* @return \Magento\Framework\Api\SearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getListByReviewId($reviewId);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api\Data;
interface CommentInterface
{
const TABLE = 'amasty_advanced_review_comments';
/**#@+
* Constants defined for keys of data array
*/
const ID = 'id';
const REVIEW_ID = 'review_id';
const STORE_ID = 'store_id';
const STATUS = 'status';
const CUSTOMER_ID = 'customer_id';
const MESSAGE = 'message';
const NICKNAME = 'nickname';
const EMAIL = 'email';
const SESSION_ID = 'session_id';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
/**#@-*/
/**
* @return int
*/
public function getId();
/**
* @param int $id
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setId($id);
/**
* @return int
*/
public function getReviewId();
/**
* @param int $reviewId
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setReviewId($reviewId);
/**
* @return int
*/
public function getStoreId();
/**
* @param int $storeId
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setStoreId($storeId);
/**
* @return int
*/
public function getStatus();
/**
* @param int $status
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setStatus($status);
/**
* @return int|null
*/
public function getCustomerId();
/**
* @param int|null $customerId
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setCustomerId($customerId);
/**
* @return string|null
*/
public function getMessage();
/**
* @param string|null $message
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setMessage($message);
/**
* @return string|null
*/
public function getNickname();
/**
* @param string|null $nickname
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setNickname($nickname);
/**
* @return string|null
*/
public function getEmail();
/**
* @param string|null $email
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setEmail($email);
/**
* @return string|null
*/
public function getSessionId();
/**
* @param string|null $sessionId
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setSessionId($sessionId);
/**
* @return string
*/
public function getCreatedAt();
/**
* @param string $createdAt
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setCreatedAt($createdAt);
/**
* @return string
*/
public function getUpdatedAt();
/**
* @param string $updatedAt
*
* @return \Amasty\AdvancedReview\Api\Data\CommentInterface
*/
public function setUpdatedAt($updatedAt);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api\Data;
interface ImagesInterface
{
const IMAGE_ID = 'image_id';
const REVIEW_ID = 'review_id';
const PATH = 'path';
/**
* Returns image id field
*
* @return int|null
*/
public function getImageId();
/**
* @param int $imageId
*
* @return $this
*/
public function setImageId($imageId);
/**
* Returns review id field
*
* @return int|null
*/
public function getReviewId();
/**
* @param int $reviewId
*
* @return $this
*/
public function setReviewId($reviewId);
/**
* Returns image path
*
* @return string|null
*/
public function getPath();
/**
* @param string $path
*
* @return $this
*/
public function setPath($path);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api\Data;
interface ReminderInterface
{
/**#@+
* Constants defined for keys of data array
*/
const ENTITY_ID = 'entity_id';
const ORDER_ID = 'order_id';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
const STATUS = 'status';
const SEND_DATE = 'send_date';
/**#@-*/
/**
* @return int
*/
public function getEntityId();
/**
* @param int $entityId
*
* @return \Amasty\AdvancedReview\Api\Data\ReminderInterface
*/
public function setEntityId($entityId);
/**
* @return int
*/
public function getOrderId();
/**
* @param int $orderId
*
* @return \Amasty\AdvancedReview\Api\Data\ReminderInterface
*/
public function setOrderId($orderId);
/**
* @return string
*/
public function getCreatedAt();
/**
* @param string $createdAt
*
* @return \Amasty\AdvancedReview\Api\Data\ReminderInterface
*/
public function setCreatedAt($createdAt);
/**
* @return string
*/
public function getUpdatedAt();
/**
* @param string $updatedAt
*
* @return \Amasty\AdvancedReview\Api\Data\ReminderInterface
*/
public function setUpdatedAt($updatedAt);
/**
* @return string
*/
public function getSendDate();
/**
* @param string $sendDate
*
* @return \Amasty\AdvancedReview\Api\Data\ReminderInterface
*/
public function setSendDate($sendDate);
/**
* @return int
*/
public function getStatus();
/**
* @param int $status
*
* @return \Amasty\AdvancedReview\Api\Data\ReminderInterface
*/
public function setStatus($status);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api\Data;
interface UnsubscribeInterface
{
/**#@+
* Constants defined for keys of data array
*/
const ENTITY_ID = 'entity_id';
const UNSUBSCRIBED_AT = 'unsubscribed_at';
const EMAIL = 'email';
const IS_COMMENT = 'isComment';
/**#@-*/
/**
* @return int
*/
public function getEntityId();
/**
* @param int $entityId
*
* @return \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface
*/
public function setEntityId($entityId);
/**
* @return string
*/
public function getUnsubscribedAt();
/**
* @param string $unsubscribedAt
*
* @return \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface
*/
public function setUnsubscribedAt($unsubscribedAt);
/**
* @return string
*/
public function getEmail();
/**
* @param string $email
*
* @return \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface
*/
public function setEmail($email);
/**
* @return boolean
*/
public function getIsComment();
/**
* @param boolean $isComment
*
* @return \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface
*/
public function setIsComment($isComment);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api\Data;
interface VoteInterface
{
const VOTE_ID = 'vote_id';
const REVIEW_ID = 'review_id';
const TYPE = 'type';
const IP = 'ip';
/**
* Returns vote id field
*
* @return int|null
*/
public function getVoteId();
/**
* @param int $voteId
*
* @return $this
*/
public function setVoteId($voteId);
/**
* Returns review id field
*
* @return int|null
*/
public function getReviewId();
/**
* @param int $reviewId
*
* @return $this
*/
public function setReviewId($reviewId);
/**
* Returns vote path
*
* @return int|null
*/
public function getType();
/**
* @param string $type
*
* @return $this
*/
public function setType($type);
/**
* Returns vote path
*
* @return string|null
*/
public function getIp();
/**
* @param string $ip
*
* @return $this
*/
public function setIp($ip);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api;
/**
* Interface ImagesRepositoryInterface
* @api
*/
interface ImagesRepositoryInterface
{
/**
* @param \Amasty\AdvancedReview\Api\Data\ImagesInterface $image
* @return \Amasty\AdvancedReview\Api\Data\ImagesInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(\Amasty\AdvancedReview\Api\Data\ImagesInterface $image);
/**
* @param int $imageId
* @return \Amasty\AdvancedReview\Api\Data\ImagesInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function get($imageId);
/**
* @param Data\ImagesInterface $image
* @return mixed
*/
public function delete(\Amasty\AdvancedReview\Api\Data\ImagesInterface $image);
/**
* @param int $imageId
* @return bool
*/
public function deleteById($imageId);
/**
* Lists
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\Framework\Api\SearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
/**
* @param $reviewId
* @return bool
*/
public function deleteByReviewId($reviewId);
/**
* @return \Amasty\AdvancedReview\Model\Images
*/
public function getImageModel();
/**
* @return array
*/
public function getImageKeys();
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api;
use Amasty\AdvancedReview\Api\Data\ReminderInterface;
/**
* @api
*/
interface ReminderRepositoryInterface
{
/**
* Save
*
* @param ReminderInterface $reminder
* @return ReminderInterface
*/
public function save(ReminderInterface $reminder);
/**
* Get by id
*
* @param int $entityId
* @return ReminderInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById($entityId);
/**
* Delete
*
* @param ReminderInterface $reminder
* @return bool true on success
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(ReminderInterface $reminder);
/**
* Delete by id
*
* @param int $entityId
* @return bool true on success
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function deleteById($entityId);
/**
* Lists
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\Framework\Api\SearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api;
/**
* @api
*/
interface UnsubscribeRepositoryInterface
{
/**
* Save
*
* @param \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface $unsubscribe
* @return \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface
*/
public function save(\Amasty\AdvancedReview\Api\Data\UnsubscribeInterface $unsubscribe);
/**
* Get by id
*
* @param int $entityId
* @return \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getById($entityId);
/**
* Delete
*
* @param \Amasty\AdvancedReview\Api\Data\UnsubscribeInterface $unsubscribe
* @return bool true on success
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function delete(\Amasty\AdvancedReview\Api\Data\UnsubscribeInterface $unsubscribe);
/**
* Delete by id
*
* @param int $entityId
* @return bool true on success
* @throws \Magento\Framework\Exception\CouldNotDeleteException
*/
public function deleteById($entityId);
/**
* Lists
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\Framework\Api\SearchResultsInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria);
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Api;
/**
* Interface VoteRepositoryInterface
* @api
*/
interface VoteRepositoryInterface
{
/**
* @param \Amasty\AdvancedReview\Api\Data\VoteInterface $vote
* @return \Amasty\AdvancedReview\Api\Data\VoteInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(\Amasty\AdvancedReview\Api\Data\VoteInterface $vote);
/**
* @param int $voteId
* @return \Amasty\AdvancedReview\Api\Data\VoteInterface
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function get($voteId);
/**
* @param $reviewId
* @param $ip
* @return \Amasty\AdvancedReview\Model\Vote|\Magento\Framework\DataObject
*/
public function getByIdAndIp($reviewId, $ip);
/**
* @param Data\VoteInterface $vote
* @return mixed
*/
public function delete(\Amasty\AdvancedReview\Api\Data\VoteInterface $vote);
/**
* @param int $voteId
*
* @return boolean
*/
public function deleteById($voteId);
/**
* @return \Amasty\AdvancedReview\Model\Vote
*/
public function getVoteModel();
/**
* @return array
*/
public function getVoteIpKeys();
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Adminhtml\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class DeleteButton implements ButtonProviderInterface
{
/**
* Url Builder
*
* @var \Magento\Framework\UrlInterface
*/
private $urlBuilder;
/**
* @var \Magento\Framework\App\RequestInterface
*/
private $request;
public function __construct(
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\App\RequestInterface $request
) {
$this->urlBuilder = $urlBuilder;
$this->request = $request;
}
/**
* @return array
*/
public function getButtonData()
{
$data = [];
$id = $this->request->getParam('id');
if ($id) {
$deleteUrl = $this->urlBuilder->getUrl('*/*/delete', ['id' => $id]);
$data = [
'label' => __('Delete'),
'class' => 'delete',
'on_click' => 'deleteConfirm(\'' . $this->getConfirmText()
. '\', \'' . $deleteUrl . '\')',
'sort_order' => 20,
];
}
return $data;
}
/**
* @return \Magento\Framework\Phrase
*/
public function getConfirmText()
{
return __('Are you sure you want to delete this?');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Adminhtml\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
/**
* Class
*/
class SaveAndContinueButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save and Continue Edit'),
'class' => 'save',
'on_click' => '',
'sort_order' => 90,
];
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Adminhtml\Buttons;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class SaveButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Save'),
'class' => 'save primary',
'on_click' => '',
];
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Adminhtml\System\Config\Field;
use Magento\Framework\Data\Form\Element\AbstractElement as AbstractElement;
class Multiselect extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @param AbstractElement $element
*
* @return string
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$element->setData('size', count($element->getValues()) ?: 10);
return $element->getElementHtml();
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Adminhtml\System\Config\Field;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Amasty\AdvancedReview\Helper\Config as ReviewConfig;
use Amasty\AdvancedReview\Model\Sources\Sort;
class Position extends Field
{
/**
* @var ReviewConfig
*/
private $helper;
/**
* @var Sort
*/
private $sort;
public function __construct(
ReviewConfig $helper,
Context $context,
Sort $sort
) {
parent::__construct($context);
$this->helper = $helper;
$this->sort = $sort;
}
protected function _construct()
{
$this->setTemplate('Amasty_AdvancedReview::position.phtml');
}
/**
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
$this->setElement($element);
return $this->_toHtml();
}
/**
* @return array
*/
public function getPositions()
{
$positions = (array)$this->helper->getSortOrder();
if ($positions === []) {
$positions = $this->getOptionalArray();
} else {
$availableOptions = $this->getOptionalArray();
// delete disabled options
$positions = array_intersect($positions, $availableOptions);
$newOptions = array_diff($availableOptions, $positions);
$positions = array_merge($positions, $newOptions);
}
return $positions;
}
/**
* @param $index
* @return string
*/
public function getNamePrefix($index)
{
return $this->getElement()->getName() . '[' . $index . ']';
}
/**
* @return array
*/
private function getOptionalArray()
{
$positions = [];
$methods = $this->sort->toOptionArray();
foreach ($methods as $methodObject) {
$positions[$methodObject['value']] = $methodObject['label'];
}
return $positions;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Adminhtml\System\Config;
use Magento\Framework\Data\Form\Element\AbstractElement;
/**
* Class Information
* @package Amasty\AdvancedReview\Block\Adminhtml\System\Config
*/
class Information extends \Magento\Config\Block\System\Config\Form\Fieldset
{
/**
* @var string
*/
private $userGuide = 'https://amasty.com/docs/doku.php?id=magento_2:advanced_product_reviews';
/**
* @var string
*/
private $content;
/**
* @var \Magento\Framework\Module\Manager
*/
private $moduleManager;
public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Backend\Model\Auth\Session $authSession,
\Magento\Framework\View\Helper\Js $jsHelper,
\Magento\Framework\Module\Manager $moduleManager,
array $data = []
) {
parent::__construct($context, $authSession, $jsHelper, $data);
$this->moduleManager = $moduleManager;
}
/**
* Render fieldset html
*
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
$html = $this->_getHeaderHtml($element);
$this->setContent(__('Please update Amasty Base module. Re-upload it and replace all the files.'));
$this->_eventManager->dispatch(
'amasty_base_add_information_content',
['block' => $this]
);
$html .= $this->getContent();
$html .= $this->_getFooterHtml($element);
$html = str_replace(
'amasty_information]" type="hidden" value="0"',
'amasty_information]" type="hidden" value="1"',
$html
);
$html = preg_replace('(onclick=\"Fieldset.toggleCollapse.*?\")', '', $html);
return $html;
}
/**
* @return array|string
*/
public function getAdditionalModuleContent()
{
if ($this->moduleManager->isEnabled('Magento_PageBuilder')
&& !$this->moduleManager->isEnabled('Amasty_ReviewPageBuilder')
) {
$result[] = [
'type' => 'message-notice',
'text' => __(
'Enable reviewpagebuilder module to activate PageBuilder and Advanced Reviews integration.'
. ' Please, run the following command in the '
. 'SSH: composer require amasty/advanced-reviews-page-builder'
)
];
}
if ($this->moduleManager->isEnabled('Magento_GraphQl')
&& !$this->moduleManager->isEnabled('Amasty_AdvancedReviewGraphQl')
) {
$result[] = [
'type' => 'message-notice',
'text' => __('Enable advanced-review-graphql module to '
. 'activate GraphQl and Advanced Review. '
. 'Please, run the following command in the SSH: '
. 'composer require amasty/advanced-review-graphql')
];
}
return $result ?? '';
}
/**
* @return string
*/
public function getUserGuide()
{
return $this->userGuide;
}
/**
* @param string $userGuide
*/
public function setUserGuide($userGuide)
{
$this->userGuide = $userGuide;
}
/**
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* @param string $content
*/
public function setContent($content)
{
$this->content = $content;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Magento\Framework\Intl\DateTimeFactory;
use Magento\Framework\View\Element\Template;
class Comment extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::comments/comment.phtml';
/**
* @var CommentInterface
*/
private $comment;
/**
* @var DateTimeFactory
*/
private $dateTimeFactory;
public function __construct(
DateTimeFactory $dateTimeFactory,
Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
$this->dateTimeFactory = $dateTimeFactory;
}
/**
* @return CommentInterface
*/
public function getComment()
{
return $this->comment;
}
/**
* @param CommentInterface $comment
* @return $this
*/
public function setComment(CommentInterface $comment)
{
$this->comment = $comment;
return $this;
}
/**
* @param string $message
*/
public function setMessage($message) {
$this->setTemplate('Amasty_AdvancedReview::comments/message.phtml');
$this->setData('message', $message);
}
/**
* @return string
*/
public function getDateInterval()
{
$commentCreatedDate = $this->dateTimeFactory->create(
$this->getComment()->getCreatedAt(),
new \DateTimeZone('UTC')
);
$currentDate = $this->dateTimeFactory->create('now', new \DateTimeZone('UTC'));
$interval = $commentCreatedDate->diff($currentDate);
switch (true) {
case $interval->y > 0:
$intervalMessage = __('%1 year(s) ago', $interval->y);
break;
case $interval->m > 0:
$intervalMessage = __('%1 month(s) ago', $interval->m);
break;
case $interval->d > 0:
$intervalMessage = __('%1 day(s) ago', $interval->d);
break;
case $interval->h > 0:
$intervalMessage = __('%1 hour(s) ago', $interval->h);
break;
case $interval->i > 0:
$intervalMessage = __('%1 minute(s) ago', $interval->i);
break;
case $interval->s > 0:
$intervalMessage = __('%1 second(s) ago', $interval->s);
break;
default:
$intervalMessage = __('recently');
}
return $intervalMessage;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Magento\Framework\View\Element\Template;
class CommentsList extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::comments/list.phtml';
public function __construct(
Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
}
/**
* @return CommentInterface[]
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getComments()
{
return $this->getParentBlock()->getComments();
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Comment;
use Amasty\AdvancedReview\Api\CommentRepositoryInterface;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Amasty\AdvancedReview\Model\Comment;
use Magento\Framework\View\Element\Template;
class Container extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::comments/container.phtml';
/**
* @var null|int
*/
private $reviewId = null;
/**
* @var CommentRepositoryInterface
*/
private $commentRepository;
/**
* @var Comment[]
*/
private $comments;
public function __construct(
CommentRepositoryInterface $commentRepository,
Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
$this->commentRepository = $commentRepository;
}
/**
* @return int|null
*/
public function getReviewId()
{
return $this->reviewId;
}
/**
* @param int $review
* @return $this
*/
public function setReviewId($reviewId)
{
$this->reviewId = $reviewId;
return $this;
}
/**
* @return CommentInterface[]
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getComments()
{
$this->comments = $this->commentRepository->getListByReviewId($this->getReviewId())
->getItems();
return $this->comments;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Comment;
use Amasty\AdvancedReview\Helper\Config;
use Magento\Customer\Model\Session;
use Magento\Customer\Model\SessionFactory;
use Magento\Framework\View\Element\Template;
class Form extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::comments/form.phtml';
/**
* @var SessionFactory
*/
private $sessionFactory;
/**
* @var null|Session
*/
private $session;
/**
* @var Config
*/
private $config;
public function __construct(
SessionFactory $sessionFactory,
Config $config,
Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
$this->sessionFactory = $sessionFactory;
$this->config = $config;
}
/**
* @return int
*/
public function getReviewId()
{
return $this->getParentBlock()->getReviewId();
}
/**
* @inheritdoc
*/
public function _toHtml()
{
$html = '';
if ($this->canUserComment()) {
$html = parent::_toHtml();
}
return $html;
}
/**
* @return bool
*/
public function canUserComment()
{
return $this->isLoggedIn() || $this->config->isGuestCanComment();
}
/**
* @return Session
*/
public function getSession()
{
if ($this->session === null) {
$this->session = $this->sessionFactory->create();
}
return $this->session;
}
/**
* @return bool
*/
public function isLoggedIn()
{
return $this->getSession()->isLoggedIn();
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Comment;
use Magento\Framework\View\Element\Template;
class JsInit extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::comments/js.phtml';
/**
* @return string
*/
public function getUpdateUrl()
{
return $this->getUrl('amasty_advancedreview/ajax_comment/update');
}
/**
* @return string
*/
public function getSubmitUrl()
{
return $this->getUrl('amasty_advancedreview/ajax_comment/add');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Customer\Review;
class View extends \Magento\Review\Block\Customer\View
{
/**
* Customer view template name
*
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::customer/view.phtml';
/**
* @return string
*/
public function getReviewAnswerHtml()
{
$review = $this->getReviewData();
if ($this->getData('config')->isAllowAnswer() && $review->getAnswer()) {
$html = $review->getAnswer();
}
return $html ?? '';
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Email;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product as ProductModel;
use Magento\Framework\Exception\NoSuchEntityException as NoSuchEntityException;
use Magento\Framework\View\Element\Template;
use Magento\Review\Model\Review as MagentoReview;
class Grid extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::email/reviews.phtml';
/**
* @var []
*/
protected $reviews;
/**
* @var \Magento\Backend\Model\UrlInterface
*/
private $backendUrl;
/**
* @var \Magento\Customer\Api\CustomerRepositoryInterface
*/
private $customerRepository;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
public function __construct(
Template\Context $context,
\Magento\Backend\Model\UrlInterface $backendUrl,
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
ProductRepositoryInterface $productRepository,
array $data = []
) {
parent::__construct($context, $data);
$this->backendUrl = $backendUrl;
$this->customerRepository = $customerRepository;
$this->productRepository = $productRepository;
}
/**
* @param MagentoReview|ProductModel $review
*
* @return string
*/
public function getProductName($review)
{
if ($review->getSku() && $review->getName()) {
$name = $review->getName() . ' (' . $review->getSku() . ')';
} else {
$productId = $review->getEntityPkValue();
$name = 'N/A';
if ($productId) {
try {
$product = $this->productRepository->getById($productId, false, $review->getStoreId());
$name = $product->getName() . ' (' . $product->getSku() . ')';
} catch (NoSuchEntityException $ex) {
$name = 'N/A';
}
}
}
return $name;
}
/**
* @param MagentoReview|ProductModel $review
*
* @return string
*/
public function getCustomerEmail($review)
{
if ($customerId = $review->getCustomerId()) {
try {
$customer = $this->customerRepository->getById($customerId);
$email = $customer->getEmail();
} catch (NoSuchEntityException $ex) {
$email = '';
}
} else {
$email = $review->getData('guest_email');
}
$email = $email ? '(' . $email . ')' : '';
return $email;
}
/**
* @param MagentoReview|ProductModel $review
*
* @return string
*/
public function getReviewUrl($review)
{
return $this->backendUrl->getUrl(
'review/product/edit',
[
'id' => $review->getReviewId(),
'_secure' => true,
'_nosecret' => true
]
);
}
/**
* @return array
*/
public function getReviews()
{
return $this->reviews;
}
/**
* @param array $reviews
*/
public function setReviews($reviews)
{
$this->reviews = $reviews;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Email;
use Magento\Framework\View\Element\Template;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\UrlRewrite\Model\UrlFinderInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
/**
* Class ReminderEmailContent
* @package Amasty\AdvancedReview\Block
*/
class ReminderEmailContent extends \Magento\Framework\View\Element\Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::email/products.phtml';
/**
* @var int
*/
private $storeId;
/**
* @var array
*/
private $productIds;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;
/**
* @var UrlFinderInterface
*/
private $urlFinder;
/**
* @var \Magento\Framework\Url
*/
private $url;
public function __construct(
Template\Context $context,
ProductRepositoryInterface $productRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
UrlFinderInterface $urlFinder,
\Magento\Framework\Url $url,
array $data = []
) {
parent::__construct($context, $data);
$this->productRepository = $productRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->urlFinder = $urlFinder;
$this->url = $url;
}
/**
* @return array
*/
public function getProducts()
{
$ids = $this->getProductIds();
$ids = array_unique($ids);
$this->searchCriteriaBuilder->addFilter('entity_id', $ids, 'in');
$searchCriteria = $this->searchCriteriaBuilder->create();
$products = $this->productRepository->getList($searchCriteria)->getItems();
return $products;
}
/**
* Create function for getting only front url in email
*
* @param \Magento\Catalog\Model\Product $product
*
* @return string
*/
public function getProductUrl(\Magento\Catalog\Model\Product $product)
{
$params = [];
$params['_nosid'] = true;
$routePath = '';
$routeParams = $params;
$storeId = $product->getStoreId();
$categoryId = null;
if ($product->hasUrlDataObject()) {
$requestPath = $product->getUrlDataObject()->getUrlRewrite();
$routeParams['_scope'] = $product->getUrlDataObject()->getStoreId();
} else {
$requestPath = $product->getRequestPath();
if (empty($requestPath) && $requestPath !== false) {
$filterData = [
UrlRewrite::ENTITY_ID => $product->getId(),
UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE,
UrlRewrite::STORE_ID => $storeId,
];
if ($categoryId) {
$filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;
}
$rewrite = $this->urlFinder->findOneByData($filterData);
if ($rewrite) {
$requestPath = $rewrite->getRequestPath();
$product->setRequestPath($requestPath);
} else {
$product->setRequestPath(false);
}
}
}
if (!empty($requestPath)) {
$routeParams['_direct'] = $requestPath;
} else {
$routePath = 'catalog/product/view';
$routeParams['id'] = $product->getId();
$routeParams['s'] = $product->getUrlKey();
if ($categoryId) {
$routeParams['category'] = $categoryId;
}
}
// reset cached URL instance GET query params
if (!isset($routeParams['_query'])) {
$routeParams['_query'] = [];
}
return $this->url->setScope($storeId)->getUrl($routePath, $routeParams);
}
/**
* @return int
*/
public function getStoreId()
{
return $this->storeId;
}
/**
* @param $storeId
*
* @return $this
*/
public function setStoreId($storeId)
{
$this->storeId = $storeId;
return $this;
}
/**
* @return array
*/
public function getProductIds()
{
return $this->productIds;
}
/**
* @param $productIds
*
* @return $this
*/
public function setProductIds($productIds)
{
$this->productIds = $productIds;
return $this;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block;
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
use Magento\Framework\View\Element\Template;
/**
* Class Helpful
*
* @package Amasty\AdvancedReview\Block
*/
class Helpful extends \Magento\Framework\View\Element\Template
{
const VOTED_CLASS_NAME = '-voted';
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::helpful.phtml';
/**
* @var array
*/
private $vote;
/**
* @var array
*/
private $voteByCurrentIp;
/**
* @var \Magento\Framework\Data\Form\FormKey
*/
private $formKey;
/**
* @var \Amasty\AdvancedReview\Model\Repository\VoteRepository
*/
private $voteRepository;
/**
* @var RemoteAddress
*/
private $remoteAddress;
/**
* @var \Magento\Framework\Json\EncoderInterface
*/
private $jsonEncoder;
public function __construct(
Template\Context $context,
\Magento\Framework\Data\Form\FormKey $formKey,
\Amasty\AdvancedReview\Model\Repository\VoteRepository $voteRepository,
RemoteAddress $remoteAddress,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
array $data = []
) {
parent::__construct($context, $data);
$this->formKey = $formKey;
$this->voteRepository = $voteRepository;
$this->remoteAddress = $remoteAddress;
$this->jsonEncoder = $jsonEncoder;
}
/**
* @return string
*/
public function getFormKey()
{
return $this->formKey->getFormKey();
}
/**
* @return array
*/
private function getVotedByIp()
{
if (!$this->voteByCurrentIp) {
$this->voteByCurrentIp = $this->voteRepository->getVotesCount(
$this->getReview()->getId(),
$this->remoteAddress->getRemoteAddress()
);
}
return $this->voteByCurrentIp;
}
/**
* @return mixed
*/
public function getReview()
{
return $this->getData('review');
}
/**
* @return int
*/
public function getPlusReview()
{
$vote = $this->getVote();
return $vote['plus'];
}
/**
* @return int
*/
public function getMinusReview()
{
$vote = $this->getVote();
return $vote['minus'];
}
/**
* @return array
*/
private function getVote()
{
if (!$this->vote) {
$this->vote = $this->voteRepository->getVotesCount($this->getReview()->getId());
}
return $this->vote;
}
/**
* @return bool
*/
public function isPlusVoted()
{
$voted = $this->getVotedByIp();
return $voted['plus'] > 0;
}
/**
* @return bool
*/
public function isMinusVoted()
{
$voted = $this->getVotedByIp();
return $voted['minus'] > 0;
}
/**
* @return string
*/
public function getJsonConfig()
{
return $this->jsonEncoder->encode(
[
'url' => $this->getUrl('amasty_advancedreview/ajax/vote')
]
);
}
/**
* @return string
*/
public function getPlusVotedClass()
{
$result = '';
if ($this->isPlusVoted()) {
$result = self::VOTED_CLASS_NAME;
}
return $result;
}
/**
* @return string
*/
public function getMinusVotedClass()
{
$result = '';
if ($this->isMinusVoted()) {
$result = self::VOTED_CLASS_NAME;
}
return $result;
}
public function useShortTemplate()
{
$this->setTemplate('Amasty_AdvancedReview::helpful_short.phtml');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block;
use Amasty\AdvancedReview\Model\ResourceModel\Images\Collection;
use Magento\Framework\View\Element\Template;
use Amasty\AdvancedReview\Model\ResourceModel\Images\CollectionFactory;
/**
* Class Images
* @package Amasty\AdvancedReview\Block
*/
class Images extends \Magento\Framework\View\Element\Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::images.phtml';
/**
* @var int
*/
private $reviewId;
/**
* @var \Magento\Framework\Json\EncoderInterface
*/
private $jsonEncoder;
/**
* @var CollectionFactory
*/
private $collectionFactory;
/**
* @var \Amasty\AdvancedReview\Helper\Config
*/
private $configHelper;
/**
* @var \Amasty\AdvancedReview\Helper\ImageHelper
*/
private $imageHelper;
public function __construct(
Template\Context $context,
CollectionFactory $collectionFactory,
\Amasty\AdvancedReview\Helper\Config $configHelper,
\Amasty\AdvancedReview\Helper\ImageHelper $imageHelper,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
array $data = []
) {
parent::__construct($context, $data);
$this->jsonEncoder = $jsonEncoder;
$this->collectionFactory = $collectionFactory;
$this->configHelper = $configHelper;
$this->imageHelper = $imageHelper;
}
/**
* @return Collection
*/
public function getCollection()
{
/** @var Collection $collection */
$collection = $this->collectionFactory->create()
->addFieldToSelect('*')
->addFieldToFilter('review_id', $this->getReviewId());
return $collection;
}
/**
* @param $item
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getFullImagePath($item)
{
return $this->imageHelper->getFullPath($item->getPath());
}
/**
* @param $item
* @return string
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getResizedImagePath($item)
{
return $this->imageHelper->resize($item->getPath(), $this->configHelper->getReviewImageWidth() * 2);
}
/**
* @return string
*/
public function getMaxHeight()
{
return $this->configHelper->getReviewImageWidth();
}
/**
* @return int
*/
public function getReviewId()
{
return $this->reviewId;
}
/**
* @param $reviewId
*
* @return $this
*/
public function setReviewId($reviewId)
{
$this->reviewId = $reviewId;
return $this;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Review\Product\View;
class ListView extends \Magento\Review\Block\Product\View\ListView
{
/**
* Prepare product review list toolbar
*
* @return \Amasty\AdvancedReview\Block\Review\Product\View\ListView
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareLayout()
{
$toolbar = $this->getLayout()->getBlock('product_review_list.toolbar');
if ($toolbar) {
$toolbar->setCollection($this->getReviewsCollection());
$this->setChild('toolbar', $toolbar);
}
return $this;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Review;
use Amasty\AdvancedReview\Model\Toolbar\Applier;
use Amasty\AdvancedReview\Model\Toolbar\UrlBuilder;
use Magento\Framework\View\Element\Template;
use Amasty\AdvancedReview\Model\ResourceModel\Review\Collection as ReviewCollection;
use Zend_Db_Select;
class Toolbar extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::review/toolbar.phtml';
/**
* Review collection
*
* @var ReviewCollection
*/
private $collection;
/**
* @var \Amasty\AdvancedReview\Model\Sources\Sort
*/
private $sortModel;
/**
* @var \Amasty\AdvancedReview\Helper\Config
*/
private $config;
/**
* @var \Magento\Framework\App\Request\Http
*/
private $request;
/**
* @var UrlBuilder
*/
private $urlBuilder;
/**
* @var Applier
*/
private $applier;
/**
* @var \Amasty\AdvancedReview\Model\Sources\Filter
*/
private $filterModel;
public function __construct(
Template\Context $context,
\Amasty\AdvancedReview\Model\Sources\Sort $sortModel,
\Amasty\AdvancedReview\Model\Sources\Filter $filterModel,
\Amasty\AdvancedReview\Helper\Config $config,
\Magento\Framework\App\Request\Http $request,
UrlBuilder $urlBuilder,
Applier $applier,
array $data = []
) {
parent::__construct($context, $data);
$this->sortModel = $sortModel;
$this->config = $config;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
$this->applier = $applier;
$this->filterModel = $filterModel;
}
/**
* @param $type
* @param $value
*
* @return string
*/
public function generateUrl($type, $value)
{
return $this->urlBuilder->generateUrl($type, $value);
}
/**
* @return bool
*/
public function isToolbarDisplayed()
{
return $this->isSortingEnabled() || $this->isFilteringEnabled();
}
/**
* @return bool
*/
public function isSortingEnabled()
{
return (bool)count($this->config->getSortingOptions());
}
/**
* @return bool
*/
public function isFilteringEnabled()
{
return (bool)count($this->config->getFilteringOptions());
}
/**
* @return array
*/
public function getAvailableOrders()
{
$available = $this->config->getSortingOptions();
$data = $this->sortModel->toOptionArray();
$result = [];
foreach ($data as $key => $order) {
if (in_array($order['value'], $available)) {
$result[$order['value']] = $order['label'];
}
}
return $this->config->sortOptions($result);
}
/**
* @return array
*/
public function getAvailableFilters()
{
$available = $this->config->getFilteringOptions();
$data = $this->filterModel->toOptionArray();
$result = [];
foreach ($data as $key => $order) {
if (in_array($order['value'], $available)) {
$result[$order['value']] = $order['label'];
}
}
return $result;
}
/**
* @param string $key
*
* @return bool
*/
public function isOrderCurrent($key)
{
return $this->applier->isOrderCurrent($key, $this->getCollection());
}
/**
* @param string $key
*
* @return bool
*/
public function isFilterSelected($key)
{
return $this->applier->isFilterSelected($key, $this->getCollection());
}
/**
* @return string
*/
public function getCurrentDirection()
{
$direction = $this->getRequest()->getParam(UrlBuilder::DIRECTION_PARAM_NAME, 'DESC');
$direction = in_array($direction, ['asc', 'desc']) ? $direction : 'DESC';
$direction = strtoupper($direction);
return $direction;
}
/**
* @return ReviewCollection
*/
public function getCollection()
{
return $this->collection;
}
/**
* @param ReviewCollection $collection
*
* @return $this
*/
public function setCollection(ReviewCollection $collection)
{
$collection->getSelect()->reset(Zend_Db_Select::ORDER);
$this->collection = $collection;
return $this;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block;
use Amasty\AdvancedReview\Model\Toolbar\UrlBuilder as UrlBuilder;
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
use Magento\Framework\View\Element\Template;
use Amasty\AdvancedReview\Model\Sources\Recommend;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\Product;
/**
* Class Summary
* @package Amasty\AdvancedReview\Block
*/
class Sizefits extends \Magento\Framework\View\Element\Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::sizefits.phtml';
/**
* @var null|int
*/
private $votedRecommendCount = null;
/**
* @var \Magento\Catalog\Model\Product
*/
private $product;
/**
* Review collection
*
* @var ReviewCollection
*/
private $reviewsCollection;
/**
* @var \Magento\Review\Model\Review\SummaryFactory
*/
private $summaryModFactory;
/**
* @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory
*/
private $reviewsColFactory;
/**
* @var \Magento\Review\Model\RatingFactory
*/
private $ratingFactory;
/**
* @var \Amasty\AdvancedReview\Helper\Config
*/
private $configHelper;
/**
* @var \Amasty\AdvancedReview\Helper\BlockHelper
*/
private $advancedHelper;
/**
* @var \Magento\Framework\DataObjectFactory
*/
private $dataObjectFactory;
/**
* @var UrlBuilder
*/
private $urlBuilder;
public function __construct(
Template\Context $context,
\Magento\Review\Model\Review\SummaryFactory $summaryModFactory,
\Magento\Review\Model\RatingFactory $ratingFactory,
\Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory,
\Amasty\AdvancedReview\Helper\Config $configHelper,
\Amasty\AdvancedReview\Helper\BlockHelper $advancedHelper,
\Magento\Framework\DataObjectFactory $dataObjectFactory,
UrlBuilder $urlBuilder,
array $data = []
) {
parent::__construct($context, $data);
$this->summaryModFactory = $summaryModFactory;
$this->reviewsColFactory = $collectionFactory;
$this->ratingFactory = $ratingFactory;
$this->configHelper = $configHelper;
$this->advancedHelper = $advancedHelper;
$this->dataObjectFactory = $dataObjectFactory;
$this->urlBuilder = $urlBuilder;
}
/**
* Get collection of reviews
*
* @return ReviewCollection
*/
public function getReviewsCollection()
{
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;
}
/**
* @return bool
*/
public function shouldShowRecommended()
{
$result = $this->configHelper->isRecommendFieldEnabled()
&& $this->getRecommendedVotedCount();
return $result;
}
/**
* Get ratings summary
*
* @return string
*/
public function getRatingSummary()
{
$result = null;
$summary = $this->getProduct()->getRatingSummary();
if ($summary) {
$result = $summary->getRatingSummary();
}
return $result;
}
/**
* Get detail summary
*
* @return array
*/
public function getDetailedSummary()
{
$result = [
'3' => 0,
'2' => 0,
'1' => 0
];
foreach ($this->getReviewsCollection() as $item) {
if($item->getSizeFits() != 0 ){
$key = $item->getSizeFits();
$result[$key] = $result[$key] + 1;
}
}
return $result;
}
/**
* Get ratings summary
*
* @return string
*/
public function getRatingSummaryValue()
{
$value = $this->getRatingSummary();
$value = $value / 100 * 5;
return round($value, 1);
}
/**
* @return int
*/
public function getRecomendedPercent()
{
$collection = $this->getRecommendedCollection()
->addFieldToFilter('is_recommended', Recommend::RECOMMENDED);
$result = 0;
$totalCount = $this->getRecommendedVotedCount();
if ($totalCount) {
$result = round($collection->getSize() / $totalCount * 100);
}
return $result;
}
/**
* @return ReviewCollection
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function getRecommendedCollection()
{
$collection = $this->reviewsColFactory->create()->addStoreFilter(
$this->_storeManager->getStore()->getId()
)->addStatusFilter(
\Magento\Review\Model\Review::STATUS_APPROVED
)->addEntityFilter(
'product',
$this->getProduct()->getId()
)->addFieldToFilter(
'main_table.entity_pk_value',
$this->getProduct()->getId()
);
return $collection;
}
/**
* @return int|null
*/
private function getRecommendedVotedCount()
{
if ($this->votedRecommendCount == null) {
$collection = $this->getRecommendedCollection()
->addFieldToFilter(
'is_recommended',
['in' => [Recommend::RECOMMENDED, Recommend::NOT_RECOMMENDED]]
);
$this->votedRecommendCount = $collection->getSize();
}
return $this->votedRecommendCount;
}
/**
* Get count of reviews
*
* @return int
*/
public function getReviewsCount()
{
return $this->getReviewsCollection()->getSize();
}
/**
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
return $this->product;
}
/**
* @param Product $product
*
* @return $this
*/
public function setProduct(\Magento\Catalog\Model\Product $product)
{
$this->product = $product;
$this->applySummary($this->product, $this->_storeManager->getStore()->getId());
return $this;
}
/**
* @param $product
* @param int $storeId
*/
private function applySummary($product, $storeId = Store::DEFAULT_STORE_ID)
{
$summaryData = $this->summaryModFactory->create()
->setStoreId($storeId)
->load($product->getId());
$summary = $this->dataObjectFactory->create();
$summary->setData($summaryData->getData());
$product->setRatingSummary($summary);
}
/**
* Get URL for ajax filtering call
*
* @param $countStars
*
* @return string
*/
public function getProductReviewUrl($countStars)
{
return $this->urlBuilder->generateUrl(UrlBuilder::STARS_PARAM_NAME, $countStars);
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block;
use Amasty\AdvancedReview\Model\Toolbar\UrlBuilder as UrlBuilder;
use Magento\Review\Model\ResourceModel\Review\Collection as ReviewCollection;
use Magento\Framework\View\Element\Template;
use Amasty\AdvancedReview\Model\Sources\Recommend;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\Product;
/**
* Class Summary
* @package Amasty\AdvancedReview\Block
*/
class Summary extends \Magento\Framework\View\Element\Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::summary.phtml';
/**
* @var null|int
*/
private $votedRecommendCount = null;
/**
* @var \Magento\Catalog\Model\Product
*/
private $product;
/**
* Review collection
*
* @var ReviewCollection
*/
private $reviewsCollection;
/**
* @var \Magento\Review\Model\Review\SummaryFactory
*/
private $summaryModFactory;
/**
* @var \Magento\Review\Model\ResourceModel\Review\CollectionFactory
*/
private $reviewsColFactory;
/**
* @var \Magento\Review\Model\RatingFactory
*/
private $ratingFactory;
/**
* @var \Amasty\AdvancedReview\Helper\Config
*/
private $configHelper;
/**
* @var \Amasty\AdvancedReview\Helper\BlockHelper
*/
private $advancedHelper;
/**
* @var \Magento\Framework\DataObjectFactory
*/
private $dataObjectFactory;
/**
* @var UrlBuilder
*/
private $urlBuilder;
public function __construct(
Template\Context $context,
\Magento\Review\Model\Review\SummaryFactory $summaryModFactory,
\Magento\Review\Model\RatingFactory $ratingFactory,
\Magento\Review\Model\ResourceModel\Review\CollectionFactory $collectionFactory,
\Amasty\AdvancedReview\Helper\Config $configHelper,
\Amasty\AdvancedReview\Helper\BlockHelper $advancedHelper,
\Magento\Framework\DataObjectFactory $dataObjectFactory,
UrlBuilder $urlBuilder,
array $data = []
) {
parent::__construct($context, $data);
$this->summaryModFactory = $summaryModFactory;
$this->reviewsColFactory = $collectionFactory;
$this->ratingFactory = $ratingFactory;
$this->configHelper = $configHelper;
$this->advancedHelper = $advancedHelper;
$this->dataObjectFactory = $dataObjectFactory;
$this->urlBuilder = $urlBuilder;
}
/**
* Get collection of reviews
*
* @return ReviewCollection
*/
public function getReviewsCollection()
{
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;
}
/**
* @return bool
*/
public function shouldShowRecommended()
{
$result = $this->configHelper->isRecommendFieldEnabled()
&& $this->getRecommendedVotedCount();
return $result;
}
/**
* Get ratings summary
*
* @return string
*/
public function getRatingSummary()
{
$result = null;
$summary = $this->getProduct()->getRatingSummary();
if ($summary) {
$result = $summary->getRatingSummary();
}
return $result;
}
/**
* Get detail summary
*
* @return array
*/
public function getDetailedSummary()
{
$result = [
'5' => 0,
'4' => 0,
'3' => 0,
'2' => 0,
'1' => 0
];
foreach ($this->getReviewsCollection() as $item) {
$summary = $this->ratingFactory->create()->getReviewSummary($item->getReviewId(), true);
$count = $summary->getData('count') ?: 1;
$key = floor($summary->getData('sum') / $count / 100 * 5);
if (array_key_exists((string)$key, $result)) {
$result[$key] = $result[$key] + 1;
}
}
if ($filterStars = $this->getDisplayedCollection()->getFlag('filter_by_stars')) {
$this->getDisplayedCollection()->setFlag('items_count', $result[$filterStars]);
}
return $result;
}
/**
* Get ratings summary
*
* @return string
*/
public function getRatingSummaryValue()
{
$value = $this->getRatingSummary();
$value = $value / 100 * 5;
return round($value, 1);
}
/**
* @return int
*/
public function getRecomendedPercent()
{
$collection = $this->getRecommendedCollection()
->addFieldToFilter('is_recommended', Recommend::RECOMMENDED);
$result = 0;
$totalCount = $this->getRecommendedVotedCount();
if ($totalCount) {
$result = round($collection->getSize() / $totalCount * 100);
}
return $result;
}
/**
* @return ReviewCollection
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function getRecommendedCollection()
{
$collection = $this->reviewsColFactory->create()->addStoreFilter(
$this->_storeManager->getStore()->getId()
)->addStatusFilter(
\Magento\Review\Model\Review::STATUS_APPROVED
)->addEntityFilter(
'product',
$this->getProduct()->getId()
)->addFieldToFilter(
'main_table.entity_pk_value',
$this->getProduct()->getId()
);
return $collection;
}
/**
* @return int|null
*/
private function getRecommendedVotedCount()
{
if ($this->votedRecommendCount == null) {
$collection = $this->getRecommendedCollection()
->addFieldToFilter(
'is_recommended',
['in' => [Recommend::RECOMMENDED, Recommend::NOT_RECOMMENDED]]
);
$this->votedRecommendCount = $collection->getSize();
}
return $this->votedRecommendCount;
}
/**
* Get count of reviews
*
* @return int
*/
public function getReviewsCount()
{
return $this->getReviewsCollection()->getSize();
}
/**
* @return \Magento\Catalog\Model\Product
*/
public function getProduct()
{
return $this->product;
}
/**
* @param Product $product
*
* @return $this
*/
public function setProduct(\Magento\Catalog\Model\Product $product)
{
$this->product = $product;
$this->applySummary($this->product, $this->_storeManager->getStore()->getId());
return $this;
}
/**
* @param $product
* @param int $storeId
*/
private function applySummary($product, $storeId = Store::DEFAULT_STORE_ID)
{
$summaryData = $this->summaryModFactory->create()
->setStoreId($storeId)
->load($product->getId());
$summary = $this->dataObjectFactory->create();
$summary->setData($summaryData->getData());
$product->setRatingSummary($summary);
}
/**
* Get URL for ajax filtering call
*
* @param $countStars
*
* @return string
*/
public function getProductReviewUrl($countStars)
{
return $this->urlBuilder->generateUrl(UrlBuilder::STARS_PARAM_NAME, $countStars);
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget;
use Amasty\AdvancedReview\Block\Widget\ProductReviews\ReviewsList;
use Amasty\AdvancedReview\Model\ResourceModel\Review\Collection as ReviewCollection;
use Amasty\AdvancedReview\Model\Widget\ProductReviewsWidgetFactory;
use Magento\Framework\View\Element\Template;
use Amasty\AdvancedReview\Block\Widget\ProductReviews\ProductInfo;
use Amasty\AdvancedReview\Block\Widget\ProductReviews\Form;
class ProductReviews extends \Magento\Framework\View\Element\Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::widget/product_reviews/container.phtml';
/**
* @var \Magento\Catalog\Model\Product
*/
private $product;
/**
* @var ProductReviewsWidgetFactory
*/
private $productReviewsWidget;
public function __construct(
Template\Context $context,
ProductReviewsWidgetFactory $productReviewsWidgetFactory,
array $data = []
) {
parent::__construct($context, $data);
$this->productReviewsWidget = $productReviewsWidgetFactory->create();
}
private function initProduct()
{
$rewriteData = explode('/', $this->getData('id_path'));
$this->product = $this->productReviewsWidget->getProduct($rewriteData[1] ?? 0);
}
/**
* @return string
*/
public function toHtml()
{
$html = '';
$this->initProduct();
if ($this->product) {
$html = parent::toHtml();
}
return $html;
}
/**
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getReviewsList()
{
return $this->getLayout()->createBlock(ReviewsList::class)
->setData($this->getData())
->setProductId($this->product->getId())
->toHtml();
}
/**
* @return ReviewCollection|\Magento\Review\Model\ResourceModel\Review\Collection
*/
public function getReviewCollection()
{
return $this->productReviewsWidget->getReviewsCollection($this->product->getId());
}
/**
* @return string
*/
public function getAddReviewForm()
{
$component = ['components' => ['review-form' => ['component' => 'Magento_Review/js/view/review']]];
return $this->getLayout()->createBlock(Form::class)
->setTemplate('Magento_Review::form.phtml')
->setData('jsLayout', $component)
->setProduct($this->product)
->toHtml();
}
/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getProductView()
{
return $this->getLayout()->createBlock(ProductInfo::class)
->setProduct($this->product)
->setReviewsCollection($this->getReviewCollection())
->toHtml();
}
/**
* @return int
*/
public function getProductId()
{
return $this->product->getId();
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget\ProductReviews;
class Form extends \Magento\Review\Block\Form
{
/**
* @return int
*/
protected function getProductId()
{
return $this->getProduct()->getId();
}
/**
* @return string
*/
public function getJsLayout()
{
$this->jsLayout = $this->getData('jsLayout');
return parent::getJsLayout();
}
/**
* @return string|string[]|null
*/
public function toHtml()
{
$html = parent::toHtml();
$id = $this->getProduct()->getId();
$html = preg_replace('/(id=\")(.*?)\"/', '$1$2-' . $id . '"', $html);
$html = preg_replace('/(for=\")(.*?)\"/', '$1$2-' . $id . '"', $html);
$html = str_replace('#review-form', '#review-form-' . $id, $html);
return $html;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget\ProductReviews;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Template;
class Pager extends \Magento\Theme\Block\Html\Pager
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::widget/product_reviews/components/pager.phtml';
/**
* @var Json
*/
private $json;
public function __construct(
Template\Context $context,
Json $json,
array $data = []
) {
parent::__construct($context, $data);
$this->json = $json;
}
/**
* @param string $page
* @return string
*/
public function getPageUrl($page)
{
return $this->_urlBuilder ->getUrl('amasty_advancedreview/widget/paging', ['p' => $page]);
}
/**
* @return string
*/
public function getJsonData()
{
return $this->json->serialize($this->getData());
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget\ProductReviews;
use Amasty\AdvancedReview\Block\Summary;
use Amasty\AdvancedReview\Helper\BlockHelper;
use Magento\Catalog\Block\Product\ImageBuilder;
use Magento\Framework\View\Element\Template;
use Psr\Log\LoggerInterface;
class ProductInfo extends Template
{
/**
* @var string
*/
protected $_template = 'Amasty_AdvancedReview::widget/product_reviews/components/product_info.phtml';
/**
* @var BlockHelper
*/
private $blockHelper;
/**
* @var \Zend_Http_UserAgent
*/
private $userAgent;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var ImageBuilder
*/
private $imageBuilder;
public function __construct(
Template\Context $context,
ImageBuilder $imageBuilder,
BlockHelper $blockHelper,
\Zend_Http_UserAgent $userAgent,
LoggerInterface $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->blockHelper = $blockHelper;
$this->userAgent = $userAgent;
$this->logger = $logger;
$this->imageBuilder = $imageBuilder;
}
/**
* @return string
*/
public function getProductName()
{
return $this->getProduct()->getName();
}
/**
* @return string
*/
public function getProductImage()
{
return $this->imageBuilder->setProduct($this->getProduct())
->setImageId('advanced_review_product_reviews_widget_image')
->setAttributes([])
->create()
->toHtml();
}
/**
* @return string
*/
public function getProductUrl()
{
return $this->getProduct()->getProductUrl();
}
/**
* @param $product
* @param $displayedCollection
* @return string
*/
public function getReviewsSummaryHtml($product, $displayedCollection)
{
try {
$html = $this->getLayout()->createBlock(Summary::class)
->setProduct($product)
->setDisplayedCollection($displayedCollection)
->setTemplate('Amasty_AdvancedReview::widget/product_reviews/components/summary.phtml')
->toHtml();
} catch (\Exception $e) {
$html = '';
$this->logger->error($e->getMessage());
}
return $html;
}
/**
* @return BlockHelper
*/
public function getAdvancedHelper()
{
return $this->blockHelper;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget\ProductReviews;
use Amasty\AdvancedReview\Helper\BlockHelper;
use Amasty\AdvancedReview\Model\ResourceModel\Review\Collection as ReviewCollection;
use Amasty\AdvancedReview\Model\Widget\ProductReviewsWidgetFactory;
use Magento\Framework\View\Element\Template;
class ReviewsList extends \Magento\Framework\View\Element\Template
{
const MAX_DESCRIPTION_SIZE = 130;
const TEMPLATE = 'Amasty_AdvancedReview::widget/product_reviews/components/review_list.phtml';
/**
* @var BlockHelper
*/
private $blockHelper;
/**
* @var \Magento\Review\Model\ResourceModel\Review\Collection
*/
private $reviewCollection = null;
/**
* @var ProductReviewsWidgetFactory
*/
private $productReviewsWidget;
public function __construct(
Template\Context $context,
BlockHelper $blockHelper,
ProductReviewsWidgetFactory $productReviewsWidgetFactory,
array $data = []
) {
parent::__construct($context, $data);
$this->blockHelper = $blockHelper;
$this->productReviewsWidget = $productReviewsWidgetFactory->create();
}
/**
* @return \Magento\Catalog\Api\Data\ProductInterface
*/
private function getProduct()
{
return $this->productReviewsWidget->getProduct($this->getProductId());
}
/**
* @return string
*/
public function toHtml()
{
$html = '';
if ($this->getProduct()) {
$this->setTemplate(self::TEMPLATE);
$html = parent::toHtml();
}
return $html;
}
/**
* @return ReviewCollection|\Magento\Review\Model\ResourceModel\Review\Collection
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getReviewsCollection()
{
if ($this->reviewCollection === null) {
$this->reviewCollection =
$this->productReviewsWidget->getReviewsCollection($this->getProductId(), $this->getReviewsCount());
}
return $this->reviewCollection;
}
/**
* @return ReviewCollection
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getLimitedReviewsCollection()
{
return $this->getReviewsCollection()
->setPageSize($this->getProductsPerPage())
->setCurPage((int)$this->getData('p'))
->load()->addRateVotes();
}
/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getPager()
{
return $this->getLayout()->createBlock(\Amasty\AdvancedReview\Block\Widget\ProductReviews\Pager::class)
->setLimit($this->getProductsPerPage())
->setData($this->getData())
->setProductId($this->getProductId())
->setCollection($this->getReviewsCollection())
->toHtml();
}
/**
* @return BlockHelper
*/
public function getAdvancedHelper()
{
return $this->blockHelper;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget;
use Amasty\AdvancedReview\Model\OptionSource\Widget\Type;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Template;
use Amasty\AdvancedReview\Model\ResourceModel\Review\Collection as ReviewCollection;
use Amasty\AdvancedReview\Model\ResourceModel\Review\CollectionFactory as ReviewCollectionFactory;
use Magento\Framework\Registry;
use Amasty\AdvancedReview\Model\Indexer\Catalog\Category\Product\TableResolver;
use Magento\Catalog\Block\Product\ImageBuilder;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
class Reviews extends Template implements \Magento\Widget\Block\BlockInterface
{
const COMMON_TEMPLATE = 'Amasty_AdvancedReview::widget/review/reviews.phtml';
const LAYOUT_CONTENT_TEMPLATE = 'Amasty_AdvancedReview::widget/review/content/main.phtml';
const LAYOUT_SIDEBAR_TEMPLATE = 'Amasty_AdvancedReview::widget/review/sidebar/sidebar.phtml';
const TITLE = 'title';
const LIMIT = 'reviews_count';
const CURRENT_CATEGORY = 'current_category';
const CURRENT_PRODUCT_CATEGORY = 'current_product_category';
const TYPE = 'review_type';
const HIGHER_THAN = 'higher_than';
const DEFAULT_LIMIT = 10;
const REVIEW_MESSAGE_MAX_LENGTH = 75;
/**
* @var null|ReviewCollection
*/
private $reviewsCollection = null;
/**
* @var ReviewCollectionFactory
*/
private $reviewCollectionFactory;
/**
* @var Registry
*/
private $registry;
/**
* @var TableResolver
*/
private $tableResolver;
/**
* @var ImageBuilder
*/
private $imageBuilder;
/**
* @var ProductCollectionFactory
*/
private $productCollectionFactory;
/**
* @var ProductCollection
*/
private $productCollection;
/**
* @var \Amasty\AdvancedReview\Helper\BlockHelper
*/
private $blockHelper;
/**
* @var int|null
*/
private $categoryId;
/**
* @var int|null
*/
private $productId;
/**
* @var ProductRepositoryInterface
*/
private $productRepository;
public function __construct(
ReviewCollectionFactory $reviewCollectionFactory,
Registry $registry,
TableResolver $tableResolver,
ImageBuilder $imageBuilder,
ProductCollectionFactory $productCollectionFactory,
\Amasty\AdvancedReview\Helper\BlockHelper $blockHelper,
ProductRepositoryInterface $productRepository,
Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
$this->reviewCollectionFactory = $reviewCollectionFactory;
$this->registry = $registry;
$this->tableResolver = $tableResolver;
$this->imageBuilder = $imageBuilder;
$this->productCollectionFactory = $productCollectionFactory;
$this->blockHelper = $blockHelper;
$this->productRepository = $productRepository;
}
/**
* @return $this
*/
protected function _beforeToHtml()
{
$this->getReviewsCollection()->load()->addRateVotes();
$this->createProductCollection();
return parent::_beforeToHtml();
}
/**
* @return ReviewCollection
*/
public function getReviewsCollection()
{
if ($this->reviewsCollection === null) {
$this->createCollection();
}
return $this->reviewsCollection;
}
/**
* @param string $template
* @return Template
*/
public function setTemplate($template)
{
if ($template == self::LAYOUT_CONTENT_TEMPLATE) {
$this->setContainerPosition('grid');
} elseif ($template == self::LAYOUT_SIDEBAR_TEMPLATE) {
$this->setContainerPosition('sidebar');
}
$template = self::COMMON_TEMPLATE;
return parent::setTemplate($template);
}
/**
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function createCollection()
{
/** @var ReviewCollection $reviewsCollection */
$reviewsCollection = $this->reviewCollectionFactory->create()->addStoreFilter(
$this->_storeManager->getStore()->getId()
)->addStatusFilter(
\Magento\Review\Model\Review::STATUS_APPROVED
)->setPageSize(
$this->getLimit()
);
if ($higherThan = $this->getHigherThan()) {
$reviewsCollection->setFlag('filter_by_stars', true);
$reviewsCollection->getSelect()->having(
'rating_summary >= ?',
$higherThan
);
}
$entityFilter = $this->getEntityFilter();
if ($entityFilter !== null) {
$reviewsCollection->addEntityFilter('product', $entityFilter);
}
if ($this->isCurrentProductCategoryOnly() && $this->getProductId()) {
try {
$entity = $this->productRepository->getById($this->getProductId());
$categories = $entity->getCategoryIds();
} catch (NoSuchEntityException $e) {
$categories = [];
}
$reviewsCollection->addCategoriesFilter(['in' => $categories]);
}
switch ($this->getReviewType()) {
case Type::RANDOM:
$reviewsCollection->setOrder('RAND()');
break;
case Type::RECENT:
$reviewsCollection->setDateOrder();
break;
}
$this->reviewsCollection = $reviewsCollection;
}
/**
* {@inheritDoc}
*/
public function createProductCollection()
{
$this->productCollection = $this->productCollectionFactory->create()
->addAttributeToSelect('name')
->addAttributeToSelect('image')
->addAttributeToSelect('small_image')
->addIdFilter($this->reviewsCollection->getProductIds())
->setFlag('has_stock_status_filter', true);
}
/**
* @return array|int
*/
private function getEntityFilter()
{
$entityFilter = null;
if ($this->getCategoryId() && $this->isCurrentCategoryOnly()) {
$entityFilter = $this->tableResolver->getProductIds($this->getCategoryId());
}
return $entityFilter;
}
/**
* @param $product
*
* @return \Magento\Catalog\Block\Product\Image
*/
public function getImage($product)
{
return $this->imageBuilder->setProduct($product)
->setImageId('advanced_review_widget_image')
->setAttributes([])
->create();
}
/**
* @param $review
*
* @return \Magento\Catalog\Model\Product
*/
public function getProduct($review)
{
if (!$this->productCollection) {
$this->getReviewsCollection()->load()->addRateVotes();
$this->createProductCollection();
}
return $this->productCollection->getItemById($review->getEntityPkValue());
}
/**
* @return \Amasty\AdvancedReview\Helper\BlockHelper
*/
public function getAdvancedHelper()
{
return $this->blockHelper;
}
/**
* @return string
*/
public function getTitle()
{
return $this->getData(self::TITLE);
}
public function getLimit(): int
{
return (int)$this->getData(self::LIMIT) ?: self::DEFAULT_LIMIT;
}
/**
* @return bool
*/
public function isCurrentCategoryOnly()
{
return (bool)$this->getData(self::CURRENT_CATEGORY);
}
/**
* @return bool
*/
public function isCurrentProductCategoryOnly()
{
return (bool)$this->getData(self::CURRENT_PRODUCT_CATEGORY);
}
/**
* @return string
*/
public function getReviewType()
{
return $this->getData(self::TYPE);
}
/**
* @return int
*/
public function getHigherThan()
{
return (int)$this->getData(self::HIGHER_THAN);
}
/**
* @param $message
*
* @return string
*/
public function getReviewMessage($message)
{
return (strlen($message) > self::REVIEW_MESSAGE_MAX_LENGTH)
? substr($message, 0, self::REVIEW_MESSAGE_MAX_LENGTH) . '...'
: $message;
}
public function getCategoryId(): ?int
{
if ($this->categoryId === null && $this->_request->getFullActionName() === 'catalog_category_view') {
/** @var \Magento\Catalog\Model\Category $entity */
$entity = $this->registry->registry('current_category');
$this->categoryId = (int) $entity->getId();
}
return $this->categoryId;
}
public function setCategoryId(?int $categoryId): void
{
$this->categoryId = $categoryId;
}
public function getProductId(): ?int
{
if ($this->productId === null && $this->_request->getFullActionName() == 'catalog_product_view') {
/** @var \Magento\Catalog\Model\Product $entity */
$entity = $this->registry->registry('current_product');
$this->productId = (int) $entity->getId();
}
return $this->productId;
}
public function setProductId(?int $productId): void
{
$this->productId = $productId;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget;
class Wrapper extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
{
/**
* @var \Magento\Framework\Module\Manager
*/
private $moduleManager;
public function __construct(
\Magento\Framework\Module\Manager $moduleManager,
\Magento\Framework\View\Element\Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
$this->moduleManager = $moduleManager;
}
/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function toHtml()
{
$html = '';
if ($this->moduleManager->isEnabled('Amasty_AdvancedReview')) {
$widget = $this->getLayout()->createBlock($this->getInstance())->setData($this->getData());
$html = $widget->toHtml();
}
return $html;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Block\Widget\Wrappers;
class ProductReviewsWrapper extends \Amasty\AdvancedReview\Block\Widget\Wrapper
{
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml;
use Magento\Backend\App\Action;
use Magento\Ui\Component\MassAction\Filter;
use Psr\Log\LoggerInterface;
use Amasty\AdvancedReview\Model\ResourceModel\Reminder\CollectionFactory;
use Amasty\AdvancedReview\Api\Data\ReminderInterface;
use Amasty\AdvancedReview\Model\SendReminderEmails;
use Amasty\AdvancedReview\Api\ReminderRepositoryInterface;
/**
* Class AbstractMassAction
* @package Amasty\AdvancedReview\Controller\Adminhtml
*/
abstract class AbstractMassAction extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Amasty_AdvancedReview::reminder';
/**
* @var Filter
*/
protected $filter;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* @var CollectionFactory
*/
protected $reminderCollectionFactory;
/**
* @var \Amasty\AdvancedReview\Helper\Config
*/
protected $config;
/**
* @var SendReminderEmails
*/
private $sendReminderEmails;
/**
* @var ReminderRepositoryInterface
*/
protected $repository;
public function __construct(
Action\Context $context,
Filter $filter,
LoggerInterface $logger,
CollectionFactory $reminderCollectionFactory,
\Amasty\AdvancedReview\Helper\Config $config,
SendReminderEmails $sendReminderEmails,
ReminderRepositoryInterface $repository
) {
parent::__construct($context);
$this->filter = $filter;
$this->logger = $logger;
$this->reminderCollectionFactory = $reminderCollectionFactory;
$this->config = $config;
$this->sendReminderEmails = $sendReminderEmails;
$this->repository = $repository;
}
/**
* Execute action for reminder
*
* @param ReminderInterface $reminder
*/
abstract protected function itemAction(ReminderInterface $reminder);
/**
* @param ReminderInterface $reminder
* @param bool $isTestEmail
* @param bool $force
*/
public function send(ReminderInterface $reminder, $isTestEmail = false, $force = false)
{
$this->sendReminderEmails->send($reminder, $isTestEmail);
}
/**
* Mass action execution
*/
public function execute()
{
$this->filter->applySelectionOnTargetProvider(); // compatibility with Mass Actions on Magento 2.1.0
/** @var \Amasty\AdvancedReview\Model\ResourceModel\Reminder\Collection $collection */
$collection = $this->filter->getCollection($this->reminderCollectionFactory->create());
$collectionSize = $collection->getSize();
if ($collectionSize) {
try {
foreach ($collection->getItems() as $reminder) {
$this->itemAction($reminder);
}
$this->messageManager->addSuccessMessage($this->getSuccessMessage($collectionSize));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Magento\Framework\Exception\CouldNotSaveException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($this->getErrorMessage());
$this->logger->critical($e);
}
}
$this->_redirect($this->_redirect->getRefererUrl());
}
/**
* @return \Magento\Framework\Phrase
*/
protected function getErrorMessage()
{
return __('We can\'t change item right now. Please review the log and try again.');
}
/**
* @param int $collectionSize
*
* @return \Magento\Framework\Phrase
*/
protected function getSuccessMessage($collectionSize = 0)
{
if ($collectionSize) {
return __('A total of %1 record(s) have been changed.', $collectionSize);
}
return __('No records have been changed.');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml;
use Magento\Backend\App\Action;
/**
* Class AbstractReminder
* @package Amasty\AdvancedReview\Controller\Adminhtml
*/
abstract class AbstractReminder extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Amasty_AdvancedReview::reminder';
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml;
use Magento\Backend\App\Action;
use Magento\Framework\App\Request\DataPersistorInterface;
abstract class Comment extends Action
{
const ADMIN_RESOURCE = 'Amasty_AdvancedReview::comments';
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
private $resultPageFactory;
/**
* @var \Amasty\AdvancedReview\Api\CommentRepositoryInterface
*/
private $commentRepository;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @var DataPersistorInterface
*/
private $dataPersistor;
/**
* @var \Amasty\AdvancedReview\Model\Email\CommentNotification
*/
private $commentNotification;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Amasty\AdvancedReview\Api\CommentRepositoryInterface $commentRepository,
\Psr\Log\LoggerInterface $logger,
DataPersistorInterface $dataPersistor,
\Amasty\AdvancedReview\Model\Email\CommentNotification $commentNotification
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
$this->commentRepository = $commentRepository;
$this->logger = $logger;
$this->dataPersistor = $dataPersistor;
$this->commentNotification = $commentNotification;
}
/**
* @return \Psr\Log\LoggerInterface
*/
public function getLogger()
{
return $this->logger;
}
/**
* @return DataPersistorInterface
*/
public function getDataPersistor()
{
return $this->dataPersistor;
}
/**
* @return \Amasty\AdvancedReview\Api\CommentRepositoryInterface
*/
public function getCommentRepository()
{
return $this->commentRepository;
}
/**
* @return \Magento\Framework\View\Result\PageFactory
*/
public function getPageFactory()
{
return $this->resultPageFactory;
}
/**
* @return \Amasty\AdvancedReview\Model\Email\CommentNotification
*/
public function getCommentNotification()
{
return $this->commentNotification;
}
/**
* @param \Amasty\AdvancedReview\Model\Email\CommentNotification $commentNotification
*/
public function setCommentNotification($commentNotification)
{
$this->commentNotification = $commentNotification;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Magento\Backend\App\Action;
use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\Component\MassAction\Filter;
use Psr\Log\LoggerInterface;
abstract class AbstractMassAction extends Action
{
/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Amasty_AdvancedReview::comments';
/**
* @var \Amasty\AdvancedReview\Model\Repository\CommentRepository
*/
private $repository;
/**
* @var \Amasty\AdvancedReview\Model\ResourceModel\Comment\CollectionFactory
*/
private $collectionFactory;
/**
* @var Filter
*/
private $filter;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var \Amasty\AdvancedReview\Model\Email\CommentNotification
*/
private $commentNotification;
public function __construct(
Action\Context $context,
Filter $filter,
LoggerInterface $logger,
\Amasty\AdvancedReview\Model\Repository\CommentRepository $repository,
\Amasty\AdvancedReview\Model\ResourceModel\Comment\CollectionFactory $collectionFactory,
\Amasty\AdvancedReview\Model\Email\CommentNotification $commentNotification
) {
parent::__construct($context);
$this->repository = $repository;
$this->collectionFactory = $collectionFactory;
$this->filter = $filter;
$this->logger = $logger;
$this->commentNotification = $commentNotification;
}
/**
* Execute action for category
*
* @param $category
*/
abstract protected function itemAction($category);
/**
* @return \Amasty\AdvancedReview\Model\Repository\CommentRepository
*/
public function getRepository()
{
return $this->repository;
}
/**
* Mass action execution
*/
public function execute()
{
$this->filter->applySelectionOnTargetProvider(); // compatibility with Mass Actions on Magento 2.1.0
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
if ($collectionSize) {
try {
foreach ($collection->getItems() as $model) {
$this->itemAction($model);
}
$this->messageManager->addSuccessMessage($this->getSuccessMessage($collectionSize));
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($this->getErrorMessage());
$this->logger->critical($e);
}
}
$this->_redirect($this->_redirect->getRefererUrl());
}
/**
* @return \Magento\Framework\Phrase
*/
protected function getErrorMessage()
{
return __('We can\'t change item right now. Please review the log and try again.');
}
/**
* @param int $collectionSize
*
* @return \Magento\Framework\Phrase
*/
protected function getSuccessMessage($collectionSize = 0)
{
return $collectionSize
? __('A total of %1 record(s) have been changed.', $collectionSize)
: __('No records have been changed.');
}
/**
* @return \Amasty\AdvancedReview\Model\Email\CommentNotification
*/
public function getCommentNotification()
{
return $this->commentNotification;
}
/**
* @param \Amasty\AdvancedReview\Model\Email\CommentNotification $commentNotification
*/
public function setCommentNotification($commentNotification)
{
$this->commentNotification = $commentNotification;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Amasty\AdvancedReview\Controller\Adminhtml\Comment as CommentController;
use Amasty\AdvancedReview\Model\Sources\CommentStatus;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Exception\LocalizedException;
class Approve extends CommentController
{
/**
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$id = (int) $this->getRequest()->getParam('id');
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
try {
/** @var CommentInterface $model */
$model = $this->getCommentRepository()->getById($id);
$model->setStatus(CommentStatus::STATUS_APPROVED);
$this->getCommentRepository()->save($model);
} catch (LocalizedException $e) {
$this->getMessageManager()->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->getLogger()->error($e->getMessage());
$this->getMessageManager()->addErrorMessage(__('Something went wrong'));
}
$this->getCommentNotification()->sendMessage($model);
return $resultRedirect->setPath('*/*/');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Controller\Adminhtml\Comment as CommentController;
class Delete extends CommentController
{
/**
* Index action
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$id = (int) $this->getRequest()->getParam('id');
if ($id) {
try {
$this->getCommentRepository()->deleteById($id);
$this->getMessageManager()->addSuccessMessage(__('You deleted the comment.'));
return $resultRedirect->setPath('*/*/');
} catch (\Exception $e) {
$this->getMessageManager()->addErrorMessage($e->getMessage());
return $resultRedirect->setPath('*/*/edit', ['id' => $id]);
}
}
$this->getMessageManager()->addErrorMessage(__('We can\'t find a comment to delete.'));
return $resultRedirect->setPath('*/*/');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Amasty\AdvancedReview\Controller\Adminhtml\Comment as CommentController;
use Magento\Framework\Controller\ResultFactory;
class Edit extends CommentController
{
/**
* Index action
*
* @return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
if ($commentId = (int) $this->getRequest()->getParam(CommentInterface::ID)) {
try {
$comment = $this->getCommentRepository()->getById($commentId);
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->getConfig()->getTitle()->prepend(__(
'Edit Comment #%1 by %2',
$comment->getId(),
$comment->getNickname()
));
} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
$this->messageManager->addErrorMessage(__('This comment no longer exists.'));
return $this->_redirect('*/*/index');
}
} else {
return $this->_redirect('*/*/index');
}
return $resultPage;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Controller\Adminhtml\Comment as CommentController;
class Index extends CommentController
{
/**
* @return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->getPageFactory()->create();
$resultPage->setActiveMenu('Amasty_AdvancedReview::comments');
$resultPage->getConfig()->getTitle()->prepend(__('Comments'));
$resultPage->addBreadcrumb(__('Comments'), __('Comments'));
return $resultPage;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Amasty\AdvancedReview\Model\Sources\CommentStatus;
use Magento\Ui\Component\MassAction\Filter;
class MassActivate extends AbstractMassAction
{
/**
* @param CommentInterface $comment
* @return \Magento\Framework\Controller\Result\Redirect
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
protected function itemAction($comment)
{
$comment->setStatus(CommentStatus::STATUS_APPROVED);
$this->getRepository()->save($comment);
$this->getCommentNotification()->sendMessage($comment);
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
class MassDelete extends AbstractMassAction
{
/**
* @param CommentInterface $comment
* @return \Magento\Framework\Controller\Result\Redirect
*/
protected function itemAction($comment)
{
try {
$this->getRepository()->deleteById($comment->getId());
} catch (\Exception $e) {
$this->getMessageManager()->addErrorMessage($e->getMessage());
}
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
/**
* @return \Magento\Framework\Phrase
*/
protected function getErrorMessage()
{
return __('We can\'t delete item right now. Please review the log and try again.');
}
/**
* @param int $collectionSize
*
* @return \Magento\Framework\Phrase
*/
protected function getSuccessMessage($collectionSize = 0)
{
return $collectionSize
? __('A total of %1 record(s) have been deleted.', $collectionSize)
: __('No records have been deleted.');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Amasty\AdvancedReview\Model\Sources\CommentStatus;
class MassInactivate extends AbstractMassAction
{
/**
* @param CommentInterface $comment
* @return \Magento\Framework\Controller\Result\Redirect
*/
protected function itemAction($comment)
{
try {
$comment->setStatus(CommentStatus::STATUS_REJECTED);
$this->getRepository()->save($comment);
} catch (\Exception $e) {
$this->getMessageManager()->addErrorMessage($e->getMessage());
}
return $this->resultRedirectFactory->create()->setPath('*/*/');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Amasty\AdvancedReview\Controller\Adminhtml\Comment as CommentController;
use Amasty\AdvancedReview\Model\Sources\CommentStatus;
use Magento\Framework\Exception\LocalizedException;
class Reject extends CommentController
{
/**
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$id = $this->getRequest()->getParam(CommentInterface::ID);
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
try {
/** @var CommentInterface $model */
$model = $this->getCommentRepository()->getById($id);
$model->setStatus(CommentStatus::STATUS_REJECTED);
$this->getCommentRepository()->save($model);
} catch (LocalizedException $e) {
$this->getMessageManager()->addErrorMessage($e->getMessage());
} catch (\Exception $e) {
$this->getLogger()->error($e->getMessage());
$this->getMessageManager()->addErrorMessage(__('Something went wrong'));
}
return $resultRedirect->setPath('*/*/');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Comment;
use Amasty\AdvancedReview\Api\Data\CommentInterface;
use Amasty\AdvancedReview\Controller\Adminhtml\Comment as CommentController;
use Amasty\AdvancedReview\Model\Comment;
use Amasty\AdvancedReview\Model\RegistryConstants;
use Magento\Framework\Exception\LocalizedException;
class Save extends CommentController
{
public function execute()
{
if ($data = $this->getRequest()->getPostValue()) {
try {
$model = $this->getCommentModel();
$model->addData($data);
$this->getCommentRepository()->save($model);
$this->messageManager->addSuccessMessage(__('Comment has been saved.'));
if ($this->getRequest()->getParam('back')) {
$this->_redirect(
'*/*/edit',
[CommentInterface::ID => $model->getId(), '_current' => true]
);
return;
}
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->getDataPersistor()->set(RegistryConstants::COMMENT_DATA, $data);
if ($commentId = (int) $this->getRequest()->getParam(CommentInterface::ID)) {
$this->_redirect('*/*/edit', [CommentInterface::ID => $commentId]);
} else {
$this->_redirect('*/*/');
}
return;
}
}
$this->_redirect('*/*/');
}
/**
* @return CommentInterface|Comment
* @throws LocalizedException
*/
protected function getCommentModel()
{
/** @var CommentInterface $model */
$model = $this->getCommentRepository()->getComment();
if ($commentId = (int) $this->getRequest()->getParam(CommentInterface::ID)) {
$model = $this->getCommentRepository()->getById($commentId);
if ($commentId != $model->getId()) {
throw new LocalizedException(__('The wrong item is specified.'));
}
}
return $model;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Reminder;
use Magento\Framework\Controller\ResultFactory;
/**
* Class Index
* @package Amasty\AdvancedReview\Controller\Adminhtml\Reminder
*/
class Index extends \Amasty\AdvancedReview\Controller\Adminhtml\AbstractReminder
{
/**
* Index action
*
* @return \Magento\Backend\Model\View\Result\Page
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Amasty_AdvancedReview::reminder');
$resultPage->getConfig()->getTitle()->prepend(__('Review Reminder'));
$resultPage->addBreadcrumb(__('Reminder'), __('Reminder'));
return $resultPage;
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Reminder;
use Amasty\AdvancedReview\Api\Data\ReminderInterface;
use Amasty\AdvancedReview\Model\OptionSource\Reminder\Status;
/**
* Class MassCancel
* @package Amasty\AdvancedReview\Controller\Adminhtml\Reminder
*/
class MassCancel extends \Amasty\AdvancedReview\Controller\Adminhtml\AbstractMassAction
{
/**
* @param ReminderInterface $reminder
*/
protected function itemAction(ReminderInterface $reminder)
{
$reminder->setStatus(Status::CANCELED);
$this->repository->save($reminder);
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Reminder;
use Amasty\AdvancedReview\Api\Data\ReminderInterface;
/**
* Class MassDelete
* @package Amasty\AdvancedReview\Controller\Adminhtml\Reminder
*/
class MassDelete extends \Amasty\AdvancedReview\Controller\Adminhtml\AbstractMassAction
{
/**
* @param ReminderInterface $reminder
*/
protected function itemAction(ReminderInterface $reminder)
{
$this->repository->deleteById($reminder->getEntityId());
}
/**
* @return \Magento\Framework\Phrase
*/
protected function getErrorMessage()
{
return __('We can\'t delete item right now. Please review the log and try again.');
}
/**
* @param int $collectionSize
*
* @return \Magento\Framework\Phrase
*/
protected function getSuccessMessage($collectionSize = 0)
{
if ($collectionSize) {
return __('A total of %1 record(s) have been deleted.', $collectionSize);
}
return __('No records have been deleted.');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Reminder;
use Amasty\AdvancedReview\Api\Data\ReminderInterface;
use Amasty\AdvancedReview\Api\ReminderRepositoryInterface;
use Amasty\AdvancedReview\Model\EmailSender;
use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Backend\App\Action;
use Amasty\AdvancedReview\Model\ResourceModel\Reminder\CollectionFactory;
use Amasty\AdvancedReview\Model\ReminderFactory;
/**
* Class MassSend
* @package Amasty\AdvancedReview\Controller\Adminhtml\Reminder
*/
class MassSend extends \Amasty\AdvancedReview\Controller\Adminhtml\AbstractMassAction
{
/**
* @param ReminderInterface $reminder
*
* @throws LocalizedException
*/
protected function itemAction(ReminderInterface $reminder)
{
$this->send($reminder, false, true);
}
/**
* @param int $collectionSize
*
* @return \Magento\Framework\Phrase
*/
protected function getSuccessMessage($collectionSize = 0)
{
if ($collectionSize) {
return __('A total of %1 email(s) have been sent.', $collectionSize);
}
return __('No records have been sent.');
}
}
<?php
/**
* @author Amasty Team
* @copyright Copyright (c) 2021 Amasty (https://www.amasty.com)
* @package Amasty_AdvancedReview
*/
namespace Amasty\AdvancedReview\Controller\Adminhtml\Reminder;
use Amasty\AdvancedReview\Api\Data\ReminderInterface;
use Amasty\AdvancedReview\Api\ReminderRepositoryInterface;
use Amasty\AdvancedReview\Model\EmailSender;
use Magento\Framework\Exception\LocalizedException;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Backend\App\Action;
use Amasty\AdvancedReview\Model\ResourceModel\Reminder\CollectionFactory;
use Amasty\AdvancedReview\Model\ReminderFactory;
/**
* Class MassSendTest
* @package Amasty\AdvancedReview\Controller\Adminhtml\Reminder
*/
class MassSendTest extends \Amasty\AdvancedReview\Controller\Adminhtml\AbstractMassAction
{
/**
* @param ReminderInterface $reminder
*
* @throws LocalizedException
*/
protected function itemAction(ReminderInterface $reminder)
{
if (!$this->config->getTestEmail()) {
throw new LocalizedException(__('Please fill test email in module configuration'));
}
$this->send($reminder, true);
}
/**
* @param int $collectionSize
*
* @return \Magento\Framework\Phrase
*/
protected function getSuccessMessage($collectionSize = 0)
{
if ($collectionSize) {
return __(
'A total of %1 email(s) have been sent to %2.',
$collectionSize,
$this->config->getTestEmail()
);
}
return __('No records have been sent.');
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment