64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\Review\Block\Customer;
|
|
|
|
use Esun\Review\Model\Order\AwaitingReviewProvider;
|
|
use Magento\Catalog\Helper\Image;
|
|
use Magento\Customer\Model\Session;
|
|
use Magento\Framework\View\Element\Template;
|
|
use Magento\Review\Model\RatingFactory;
|
|
use Magento\Sales\Model\ResourceModel\Order\Item\Collection;
|
|
|
|
class Awaiting extends Template
|
|
{
|
|
private ?Collection $items = null;
|
|
|
|
public function __construct(
|
|
Template\Context $context,
|
|
private readonly Session $session,
|
|
private readonly AwaitingReviewProvider $provider,
|
|
private readonly RatingFactory $ratings,
|
|
private readonly Image $imageHelper,
|
|
array $data = []
|
|
) {
|
|
parent::__construct($context, $data);
|
|
}
|
|
|
|
public function getItems(): Collection
|
|
{
|
|
return $this->items ??= $this->provider->getCollection((int)$this->session->getCustomerId());
|
|
}
|
|
|
|
public function getRatings(): \Magento\Review\Model\ResourceModel\Rating\Collection
|
|
{
|
|
return $this->ratings->create()->getResourceCollection()->addEntityFilter('product')
|
|
->setPositionOrder()->addRatingPerStoreName((int)$this->_storeManager->getStore()->getId())
|
|
->setStoreFilter((int)$this->_storeManager->getStore()->getId())->setActiveFilter(true)
|
|
->load()->addOptionToItems();
|
|
}
|
|
|
|
public function getImageUrl(\Magento\Sales\Model\Order\Item $item): string
|
|
{
|
|
return $item->getProduct()
|
|
? $this->imageHelper->init($item->getProduct(), 'wishlist_thumbnail')->getUrl()
|
|
: $this->imageHelper->getDefaultPlaceholderUrl('thumbnail');
|
|
}
|
|
|
|
public function getPostUrl(int $productId): string
|
|
{
|
|
return $this->getUrl('review/product/post', ['id' => $productId, '_secure' => $this->getRequest()->isSecure()]);
|
|
}
|
|
|
|
protected function _prepareLayout(): self
|
|
{
|
|
parent::_prepareLayout();
|
|
$pager = $this->getLayout()->createBlock(\Magento\Theme\Block\Html\Pager::class, 'esun.review.awaiting.pager')
|
|
->setLimit(10)
|
|
->setShowPerPage(false)
|
|
->setCollection($this->getItems());
|
|
$this->setChild('pager', $pager);
|
|
return $this;
|
|
}
|
|
}
|