init
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Customer\Block\Order;
|
||||
|
||||
use Esun\Customer\Model\Order\AccountOrderProvider;
|
||||
use Esun\Review\Model\Order\AwaitingReviewProvider;
|
||||
use Esun\Oceanpayment\Model\Config as OceanpaymentConfig;
|
||||
use Magento\Catalog\Helper\Image;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Magento\Framework\Data\Helper\PostHelper;
|
||||
use Magento\Sales\Model\Order\Config;
|
||||
use Magento\Sales\Helper\Reorder;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Collection;
|
||||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
|
||||
|
||||
class History extends \Magento\Sales\Block\Order\History
|
||||
{
|
||||
private ?Collection $esunOrders = null;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
CollectionFactory $orderCollectionFactory,
|
||||
Session $customerSession,
|
||||
Config $orderConfig,
|
||||
private readonly AccountOrderProvider $provider,
|
||||
private readonly AwaitingReviewProvider $awaitingReviews,
|
||||
private readonly Image $imageHelper,
|
||||
private readonly Reorder $reorderHelper,
|
||||
private readonly PostHelper $postHelper,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $orderCollectionFactory, $customerSession, $orderConfig, $data);
|
||||
}
|
||||
|
||||
public function getOrders(): Collection|false
|
||||
{
|
||||
$customerId = (int)$this->_customerSession->getCustomerId();
|
||||
if (!$customerId) {
|
||||
return false;
|
||||
}
|
||||
if ($this->esunOrders === null) {
|
||||
$status = (string)$this->getRequest()->getParam('status');
|
||||
$search = mb_substr(trim((string)$this->getRequest()->getParam('q')), 0, 100);
|
||||
$this->esunOrders = $this->provider->getHistory($customerId, $status ?: null, $search);
|
||||
}
|
||||
return $this->esunOrders;
|
||||
}
|
||||
|
||||
public function getCounts(): array
|
||||
{
|
||||
$counts = $this->provider->getStatusCounts((int)$this->_customerSession->getCustomerId());
|
||||
$counts['awaiting_review'] = $this->awaitingReviews->getCount((int)$this->_customerSession->getCustomerId());
|
||||
return $counts;
|
||||
}
|
||||
|
||||
public function getCurrentStatus(): string
|
||||
{
|
||||
return (string)$this->getRequest()->getParam('status');
|
||||
}
|
||||
public function getSearchQuery(): string
|
||||
{
|
||||
return trim((string)$this->getRequest()->getParam('q'));
|
||||
}
|
||||
|
||||
public function getItemImageUrl(\Magento\Sales\Model\Order\Item $item): string
|
||||
{
|
||||
$product = $item->getProduct();
|
||||
return $product ? $this->imageHelper->init($product, 'wishlist_thumbnail')->getUrl()
|
||||
: $this->imageHelper->getDefaultPlaceholderUrl('thumbnail');
|
||||
}
|
||||
|
||||
public function canRepay(\Magento\Sales\Model\Order $order): bool
|
||||
{
|
||||
$payment = $order->getPayment();
|
||||
$method = $payment ? (string)$payment->getMethod() : '';
|
||||
|
||||
return (string)$order->getStatus() === 'pending'
|
||||
&& (float)$order->getTotalPaid() <= 0.0
|
||||
&& in_array($method, [OceanpaymentConfig::METHOD_CODE, OceanpaymentConfig::LEGACY_METHOD_CODE], true);
|
||||
}
|
||||
|
||||
public function getRepayUrl(\Magento\Sales\Model\Order $order): string
|
||||
{
|
||||
return $this->getUrl('esun_customer/order/repay', ['order_id' => (int)$order->getId()]);
|
||||
}
|
||||
|
||||
public function canBuyAgain(\Magento\Sales\Model\Order $order): bool
|
||||
{
|
||||
return $this->reorderHelper->canReorder((int)$order->getId());
|
||||
}
|
||||
|
||||
public function getBuyAgainPostData(\Magento\Sales\Model\Order $order): string
|
||||
{
|
||||
return $this->postHelper->getPostData($this->getReorderUrl($order));
|
||||
}
|
||||
|
||||
public function canCancel(\Magento\Sales\Model\Order $order): bool
|
||||
{
|
||||
return (string)$order->getStatus() === 'pending' && $order->canCancel();
|
||||
}
|
||||
|
||||
public function getCancelUrl(\Magento\Sales\Model\Order $order): string
|
||||
{
|
||||
return $this->getUrl('esun_customer/order/cancel', ['order_id' => (int)$order->getId()]);
|
||||
}
|
||||
|
||||
protected function _prepareLayout()
|
||||
{
|
||||
parent::_prepareLayout();
|
||||
$pager = $this->getChildBlock('pager');
|
||||
if ($pager instanceof \Magento\Theme\Block\Html\Pager) {
|
||||
$pager->setShowPerPage(false);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user