112 lines
3.5 KiB
PHP
112 lines
3.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\Customer\Block\Order;
|
|
|
|
use Esun\Oceanpayment\Model\Config as OceanpaymentConfig;
|
|
use Magento\Catalog\Helper\Image;
|
|
use Magento\Framework\Registry;
|
|
use Magento\Framework\View\Element\Template\Context;
|
|
use Magento\Payment\Helper\Data as PaymentHelper;
|
|
use Magento\Sales\Model\Order;
|
|
use Magento\Sales\Model\Order\Address\Renderer as AddressRenderer;
|
|
use Magento\Sales\Model\Order\Item;
|
|
|
|
class Detail extends \Magento\Sales\Block\Order\Info
|
|
{
|
|
private const STEP_INDEXES = [
|
|
'pending' => 0,
|
|
'payment_review' => 0,
|
|
'processing' => 1,
|
|
'shipped' => 2,
|
|
'received' => 3,
|
|
'complete' => 3,
|
|
];
|
|
|
|
public function __construct(
|
|
Context $context,
|
|
Registry $registry,
|
|
PaymentHelper $paymentHelper,
|
|
AddressRenderer $addressRenderer,
|
|
private readonly Image $imageHelper,
|
|
array $data = []
|
|
) {
|
|
parent::__construct($context, $registry, $paymentHelper, $addressRenderer, $data);
|
|
}
|
|
|
|
public function getSteps(): array
|
|
{
|
|
return [
|
|
['status' => 'pending', 'label' => __('Awaiting Payment'), 'icon' => 'icon-order_payment1'],
|
|
['status' => 'processing', 'label' => __('Awaiting Shipping'), 'icon' => 'icon-order_shipped1'],
|
|
['status' => 'shipped', 'label' => __('Shipped'), 'icon' => 'icon-order_shipped3'],
|
|
['status' => 'received', 'label' => __('Received'), 'icon' => 'icon-order_review1'],
|
|
];
|
|
}
|
|
|
|
public function getCurrentStepIndex(): int
|
|
{
|
|
return self::STEP_INDEXES[(string)$this->getOrder()->getStatus()] ?? -1;
|
|
}
|
|
|
|
public function getCurrentStepDate(): string
|
|
{
|
|
$order = $this->getOrder();
|
|
if ($this->getCurrentStepIndex() === 0) {
|
|
return (string)$order->getCreatedAt();
|
|
}
|
|
|
|
$currentStatus = (string)$order->getStatus();
|
|
foreach ($order->getStatusHistories() as $history) {
|
|
if ((string)$history->getStatus() === $currentStatus) {
|
|
return (string)$history->getCreatedAt();
|
|
}
|
|
}
|
|
|
|
return (string)$order->getUpdatedAt();
|
|
}
|
|
|
|
public function getPaymentMethodTitle(): string
|
|
{
|
|
try {
|
|
$payment = $this->getOrder()->getPayment();
|
|
return $payment ? (string)$payment->getMethodInstance()->getTitle() : '';
|
|
} catch (\Throwable) {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
public function getItemImageUrl(Item $item): string
|
|
{
|
|
$product = $item->getProduct();
|
|
return $product
|
|
? $this->imageHelper->init($product, 'wishlist_thumbnail')->getUrl()
|
|
: $this->imageHelper->getDefaultPlaceholderUrl('thumbnail');
|
|
}
|
|
|
|
public function canRepay(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(Order $order): string
|
|
{
|
|
return $this->getUrl('esun_customer/order/repay', ['order_id' => (int)$order->getId()]);
|
|
}
|
|
|
|
public function canConfirmReceipt(Order $order): bool
|
|
{
|
|
return (string)$order->getStatus() === 'shipped';
|
|
}
|
|
|
|
public function getReceiveUrl(): string
|
|
{
|
|
return $this->getUrl('esun_customer/order/receive');
|
|
}
|
|
}
|