This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Block\Account;
use Esun\Customer\Model\Order\AccountOrderProvider;
use Esun\CustomerCoupon\Model\Coupon\ListProvider;
use Esun\Review\Model\Order\AwaitingReviewProvider;
use Esun\Reward\Model\BalanceManager;
use Magento\Catalog\Helper\Image;
use Magento\Customer\Model\Session;
use Magento\Framework\View\Element\Template;
use Magento\Wishlist\Helper\Data as WishlistHelper;
class Dashboard extends Template
{
public function __construct(
Template\Context $context,
private readonly Session $session,
private readonly AccountOrderProvider $orders,
private readonly AwaitingReviewProvider $awaitingReviews,
private readonly BalanceManager $balances,
private readonly ListProvider $coupons,
private readonly WishlistHelper $wishlist,
private readonly Image $imageHelper,
array $data = []
) {
parent::__construct($context, $data);
}
public function getCustomerName(): string
{
return trim((string)$this->session->getCustomer()->getName());
}
public function getPoints(): int
{
$account = $this->balances->getAccount(
(int)$this->session->getCustomerId(),
(int)$this->_storeManager->getWebsite()->getId()
);
return (int)($account['balance'] ?? 0);
}
public function getCounts(): array
{
$counts = $this->orders->getStatusCounts((int)$this->session->getCustomerId());
$counts['awaiting_review'] = $this->awaitingReviews->getCount((int)$this->session->getCustomerId());
return $counts;
}
public function getLatestPending(): ?\Magento\Sales\Model\Order
{
return $this->orders->getLatestPending((int)$this->session->getCustomerId());
}
public function getAvailableCoupons(): array
{
$items = $this->coupons->getForCustomer(
(int)$this->session->getCustomerId(),
(int)$this->_storeManager->getWebsite()->getId(),
(int)$this->session->getCustomerGroupId()
);
return array_slice(array_values(array_filter($items, static fn(array $item): bool => $item['status'] === 'available')), 0, 2);
}
public function getWishlistItems(): array
{
$collection = $this->wishlist->getWishlistItemCollection();
$collection->setPageSize(4)->setCurPage(1);
return array_values($collection->getItems());
}
public function getProductImageUrl(\Magento\Catalog\Model\Product $product): string
{
return $this->imageHelper->init($product, 'wishlist_thumbnail')->getUrl();
}
public function getOrderItemImageUrl(\Magento\Sales\Model\Order\Item $item): string
{
$product = $item->getProduct();
return $product ? $this->getProductImageUrl($product) : $this->imageHelper->getDefaultPlaceholderUrl('thumbnail');
}
}
@@ -0,0 +1,111 @@
<?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');
}
}
@@ -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;
}
}