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;
}
}
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Controller\Order;
use Magento\Customer\Controller\AbstractAccount;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Psr\Log\LoggerInterface;
class Cancel extends AbstractAccount implements HttpPostActionInterface
{
public function __construct(
Context $context,
private readonly CustomerSession $customerSession,
private readonly OrderRepositoryInterface $orderRepository,
private readonly OrderManagementInterface $orderManagement,
private readonly LoggerInterface $logger
) {
parent::__construct($context);
}
public function execute(): Redirect
{
/** @var Redirect $result */
$result = $this->resultRedirectFactory->create();
$orderId = (int)$this->getRequest()->getParam('order_id');
try {
$order = $this->orderRepository->get($orderId);
if ((int)$order->getCustomerId() !== (int)$this->customerSession->getCustomerId()) {
throw new LocalizedException(__('The requested order is not available.'));
}
if ((string)$order->getStatus() !== 'pending' || !$order->canCancel()) {
throw new LocalizedException(__('This order can no longer be canceled.'));
}
if (!$this->orderManagement->cancel($orderId)) {
throw new LocalizedException(__('The order could not be canceled.'));
}
$this->messageManager->addSuccessMessage(__('The order has been canceled.'));
} catch (LocalizedException $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
} catch (\Throwable $exception) {
$this->logger->error('Customer order cancellation failed', [
'order_id' => $orderId,
'customer_id' => (int)$this->customerSession->getCustomerId(),
'exception' => $exception,
]);
$this->messageManager->addErrorMessage(
__('The order could not be canceled. Please contact customer service.')
);
}
return $result->setPath('sales/order/history', ['status' => 'pending']);
}
}
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Controller\Order;
use Esun\Customer\Model\Order\ReceiveOrderService;
use Magento\Customer\Controller\AbstractAccount;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\Data\Form\FormKey\Validator;
use Magento\Framework\Message\ManagerInterface;
class Receive extends AbstractAccount implements HttpPostActionInterface
{
public function __construct(
Context $context,
private readonly RequestInterface $request,
private readonly RedirectFactory $redirectFactory,
private readonly Validator $formKeyValidator,
private readonly Session $session,
private readonly ReceiveOrderService $service,
private readonly ManagerInterface $messages
) {
parent::__construct($context);
}
public function execute()
{
$result = $this->redirectFactory->create()->setPath('sales/order/history');
if (!$this->formKeyValidator->validate($this->request)) {
$this->messages->addErrorMessage(__('Your session has expired. Please try again.'));
return $result;
}
try {
$this->service->receive((int)$this->request->getParam('order_id'), (int)$this->session->getCustomerId());
$this->messages->addSuccessMessage(__('Receipt confirmed. You can now review the products in this order.'));
} catch (\Throwable $exception) {
$this->messages->addErrorMessage($exception instanceof \Magento\Framework\Exception\LocalizedException
? $exception->getMessage() : __('We could not confirm receipt right now.'));
}
return $result;
}
}
@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Controller\Order;
use Esun\Oceanpayment\Model\Config as OceanpaymentConfig;
use Esun\Oceanpayment\Model\Gateway\Client;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Controller\AbstractAccount;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\OrderRepositoryInterface;
use Psr\Log\LoggerInterface;
class Repay extends AbstractAccount implements HttpPostActionInterface
{
public function __construct(
Context $context,
private readonly CustomerSession $customerSession,
private readonly CheckoutSession $checkoutSession,
private readonly OrderRepositoryInterface $orderRepository,
private readonly Client $client,
private readonly LoggerInterface $logger
) {
parent::__construct($context);
}
public function execute(): Redirect
{
/** @var Redirect $result */
$result = $this->resultRedirectFactory->create();
$orderId = (int)$this->getRequest()->getParam('order_id');
try {
$order = $this->orderRepository->get($orderId);
$payment = $order->getPayment();
$method = $payment ? (string)$payment->getMethod() : '';
if ((int)$order->getCustomerId() !== (int)$this->customerSession->getCustomerId()) {
throw new LocalizedException(__('The requested order is not available.'));
}
if ((string)$order->getStatus() !== 'pending' || (float)$order->getTotalPaid() > 0.0) {
throw new LocalizedException(__('This order is no longer awaiting payment.'));
}
if (!in_array(
$method,
[OceanpaymentConfig::METHOD_CODE, OceanpaymentConfig::LEGACY_METHOD_CODE],
true
)) {
throw new LocalizedException(__('Online repayment is not available for this payment method.'));
}
$this->checkoutSession
->setLastQuoteId((int)$order->getQuoteId())
->setLastSuccessQuoteId((int)$order->getQuoteId())
->setLastOrderId((int)$order->getEntityId())
->setLastRealOrderId((string)$order->getIncrementId());
$cachedUrl = (string)$payment->getAdditionalInformation('qianhai_pay_url');
$paymentUrl = $cachedUrl !== '' && $this->client->isAllowedPaymentUrl($cachedUrl)
? $cachedUrl
: $this->client->createPaymentUrl($order);
return $result->setUrl($paymentUrl);
} catch (LocalizedException $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
} catch (\Throwable $exception) {
$this->logger->error('Customer order repayment initialization failed', [
'order_id' => $orderId,
'customer_id' => (int)$this->customerSession->getCustomerId(),
'exception' => $exception,
]);
$this->messageManager->addErrorMessage(
__('Payment initialization failed. Please try again or contact customer service.')
);
}
return $result->setPath('sales/order/history', ['status' => 'pending']);
}
}
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Model\Order;
use Magento\Sales\Model\ResourceModel\Order\Collection;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Framework\App\ResourceConnection;
class AccountOrderProvider
{
public const FILTER_STATUSES = ['pending', 'processing', 'shipped', 'received'];
public function __construct(private readonly CollectionFactory $collections, private readonly ResourceConnection $resource)
{
}
public function getStatusCounts(int $customerId): array
{
$counts = array_fill_keys(self::FILTER_STATUSES, 0);
$connection = $this->resource->getConnection();
$rows = $connection->fetchAll($connection->select()
->from($this->resource->getTableName('sales_order'), ['status', 'qty' => new \Zend_Db_Expr('COUNT(*)')])
->where('customer_id = ?', $customerId)->where('status IN (?)', self::FILTER_STATUSES)->group('status'));
foreach ($rows as $row) {
$counts[(string)$row['status']] = (int)$row['qty'];
}
return $counts;
}
public function getLatestPending(int $customerId): ?\Magento\Sales\Model\Order
{
$collection = $this->collections->create()->addFieldToSelect('*')
->addFieldToFilter('customer_id', $customerId)
->addFieldToFilter('status', 'pending')->setOrder('created_at', 'desc')->setPageSize(1);
$order = $collection->getFirstItem();
return $order->getId() ? $order : null;
}
public function getHistory(int $customerId, ?string $status, string $search): Collection
{
$collection = $this->collections->create()->addFieldToSelect('*')
->addFieldToFilter('customer_id', $customerId)->setOrder('created_at', 'desc');
if ($status && in_array($status, self::FILTER_STATUSES, true)) {
$collection->addFieldToFilter('status', $status);
}
if ($search !== '') {
$connection = $collection->getConnection();
$like = '%' . addcslashes($search, '%_') . '%';
$itemExists = $connection->select()->from(
['search_item' => $collection->getTable('sales_order_item')],
[new \Zend_Db_Expr('1')]
)->where('search_item.order_id = main_table.entity_id')
->where('search_item.name LIKE ?', $like);
$collection->getSelect()->where(
$connection->quoteInto('main_table.increment_id LIKE ?', $like) . ' OR EXISTS (' . $itemExists . ')'
);
}
return $collection;
}
}
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Model\Order;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Api\OrderRepositoryInterface;
class ReceiveOrderService
{
public function __construct(private readonly OrderRepositoryInterface $orders)
{
}
public function receive(int $orderId, int $customerId): void
{
$order = $this->orders->get($orderId);
if ((int)$order->getCustomerId() !== $customerId) {
throw new LocalizedException(__('The order does not exist.'));
}
if ((string)$order->getStatus() === 'received') {
return;
}
if ((string)$order->getStatus() !== 'shipped') {
throw new LocalizedException(__('Only shipped orders can be confirmed as received.'));
}
$order->setStatus('received');
$order->setData('customer_confirmed_at', gmdate('Y-m-d H:i:s'));
$order->addCommentToStatusHistory(__('The customer confirmed receipt.'), 'received', false);
$this->orders->save($order);
}
}
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Model\Order;
class MarkCompleteOrderShipped implements ObserverInterface
{
public function execute(Observer $observer): void
{
$order = $observer->getEvent()->getOrder();
if (!$order instanceof Order || $order->getState() !== Order::STATE_COMPLETE
|| in_array((string)$order->getStatus(), ['shipped', 'received'], true)) {
return;
}
$ordered = 0.0;
$shipped = 0.0;
foreach ($order->getAllVisibleItems() as $item) {
$ordered += max(0.0, (float)$item->getQtyOrdered() - (float)$item->getQtyCanceled());
$shipped += (float)$item->getQtyShipped();
}
if ($ordered > 0 && $shipped >= $ordered) {
$order->setStatus('shipped');
}
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Plugin\Captcha;
use Magento\Captcha\Helper\Data;
use Magento\Captcha\Model\CaptchaInterface;
use Magento\Captcha\Model\DefaultModel;
class ImproveForgotPasswordCaptchaPlugin
{
private const FORM_ID = 'user_forgotpassword';
/**
* Improve readability only for the storefront forgot-password CAPTCHA.
*
* @param Data $subject
* @param CaptchaInterface $captcha
* @param mixed $formId
* @return CaptchaInterface
*/
public function afterGetCaptcha(
Data $subject,
CaptchaInterface $captcha,
$formId
): CaptchaInterface {
if ($formId === self::FORM_ID && $captcha instanceof DefaultModel) {
$captcha->setWidth(240)
->setHeight(64)
->setFontSize(26)
->setDotNoiseLevel(12)
->setLineNoiseLevel(0);
}
return $captcha;
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Plugin\Checkout\Block\Checkout;
use Magento\Checkout\Block\Checkout\LayoutProcessor;
/**
* Keep checkout address fields aligned with Customer > Add New Address.
*/
class LayoutProcessorPlugin
{
private const SORT_ORDERS = [
'firstname' => 10,
'lastname' => 20,
'company' => 25,
'telephone' => 30,
'street' => 40,
'country_id' => 50,
'region_id' => 60,
'region' => 60,
'city' => 70,
'postcode' => 80,
];
/**
* Apply the customer address-book field sequence to shipping and billing.
*/
public function afterProcess(LayoutProcessor $subject, array $jsLayout): array
{
$this->updateAddressFieldsets($jsLayout);
return $jsLayout;
}
/**
* Find every generated checkout address fieldset, including per-payment billing forms.
*/
private function updateAddressFieldsets(array &$node): void
{
if (isset($node['children']) && is_array($node['children'])) {
$fields = &$node['children'];
if ($this->isAddressFieldset($fields)) {
foreach (self::SORT_ORDERS as $code => $sortOrder) {
if (isset($fields[$code]) && is_array($fields[$code])) {
$fields[$code]['sortOrder'] = $sortOrder;
}
}
// The customer address form keeps Company in the EAV payload but
// does not display it. Checkout should behave the same way.
if (isset($fields['company']) && is_array($fields['company'])) {
$fields['company']['visible'] = false;
}
// The address-book form exposes State/Province for countries
// such as the United States. Amasty's checkout metadata leaves
// the select hidden, so explicitly restore the same field.
if (isset($fields['region_id']) && is_array($fields['region_id'])) {
$fields['region_id']['visible'] = true;
}
}
}
foreach ($node as &$child) {
if (is_array($child)) {
$this->updateAddressFieldsets($child);
}
}
unset($child);
}
private function isAddressFieldset(array $fields): bool
{
return isset(
$fields['firstname'],
$fields['lastname'],
$fields['street'],
$fields['country_id'],
$fields['postcode'],
$fields['telephone']
);
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Setup\Patch\Data;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\StatusFactory;
class AddReceivedOrderStatus implements DataPatchInterface
{
public function __construct(
private readonly ModuleDataSetupInterface $moduleDataSetup,
private readonly StatusFactory $statusFactory
) {
}
public function apply(): self
{
$this->moduleDataSetup->getConnection()->startSetup();
$status = $this->statusFactory->create()->load('received');
if (!$status->getStatus()) {
$status->setData(['status' => 'received', 'label' => 'Received'])->save();
}
$status->assignState(Order::STATE_COMPLETE, false, true);
$this->moduleDataSetup->getConnection()->endSetup();
return $this;
}
public static function getDependencies(): array
{
return [AddShippedOrderStatus::class];
}
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Setup\Patch\Data;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\StatusFactory;
class AddShippedOrderStatus implements DataPatchInterface
{
public function __construct(
private readonly ModuleDataSetupInterface $moduleDataSetup,
private readonly StatusFactory $statusFactory
) {
}
public function apply(): self
{
$this->moduleDataSetup->getConnection()->startSetup();
$status = $this->statusFactory->create()->load('shipped');
if (!$status->getStatus()) {
$status->setData(['status' => 'shipped', 'label' => 'Shipped'])->save();
}
$status->assignState(Order::STATE_COMPLETE, false, true);
$this->moduleDataSetup->getConnection()->endSetup();
return $this;
}
public static function getDependencies(): array
{
return [];
}
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\ViewModel;
use Magento\Customer\Api\Data\AddressInterface;
use Magento\Directory\Api\CountryInformationAcquirerInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\Block\ArgumentInterface;
class AddressBook implements ArgumentInterface
{
public function __construct(
private readonly CountryInformationAcquirerInterface $countryInformationAcquirer
) {
}
public function getName(AddressInterface $address): string
{
return implode(' ', array_filter([
$address->getPrefix(),
$address->getFirstname(),
$address->getMiddlename(),
$address->getLastname(),
$address->getSuffix(),
], static fn ($part): bool => trim((string) $part) !== ''));
}
public function getStreetLines(AddressInterface $address): array
{
return array_values(array_filter(
$address->getStreet() ?? [],
static fn ($line): bool => trim((string) $line) !== ''
));
}
public function getLocalityLine(AddressInterface $address): string
{
$region = $address->getRegion();
return implode(', ', array_filter([
$address->getCity(),
$region ? $region->getRegion() : null,
$address->getPostcode(),
], static fn ($part): bool => trim((string) $part) !== ''));
}
public function getCountryName(AddressInterface $address): string
{
$countryId = (string) $address->getCountryId();
if ($countryId === '') {
return '';
}
try {
$country = $this->countryInformationAcquirer->getCountryInfo($countryId);
return (string) ($country->getFullNameLocale() ?: $country->getFullNameEnglish() ?: $countryId);
} catch (NoSuchEntityException) {
return $countryId;
}
}
}
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Captcha\Helper\Data">
<plugin name="esun_customer_forgot_password_captcha_readability"
type="Esun\Customer\Plugin\Captcha\ImproveForgotPasswordCaptchaPlugin"/>
</type>
</config>
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_save_before">
<observer name="esun_customer_mark_complete_order_shipped" instance="Esun\Customer\Observer\MarkCompleteOrderShipped"/>
</event>
</config>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
<plugin name="esun_customer_checkout_address_fields"
type="Esun\Customer\Plugin\Checkout\Block\Checkout\LayoutProcessorPlugin"/>
</type>
</config>
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="esun_customer" frontName="esun_customer">
<module name="Esun_Customer"/>
</route>
</router>
</config>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Esun_Customer">
<sequence>
<module name="Magento_Captcha"/>
<module name="Magento_Customer"/>
<module name="Magento_Checkout"/>
<module name="Magento_Sales"/>
<module name="Magento_Catalog"/>
<module name="Magento_Wishlist"/>
<module name="Magento_Backend"/>
<module name="Esun_CustomerCoupon"/>
<module name="Esun_Reward"/>
<module name="Esun_Review"/>
<module name="Esun_Oceanpayment"/>
</sequence>
</module>
</config>
+9
View File
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Esun_Customer', __DIR__);
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-login"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="logo">
<arguments>
<argument name="logo_image_src" xsi:type="string">Esun_Customer::images/logo.png</argument>
</arguments>
</referenceBlock>
</body>
</page>
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="header">
<block class="Magento\Backend\Block\Page\Header" name="logo" before="-">
<arguments>
<argument name="show_part" xsi:type="string">logo</argument>
<argument name="edition" translate="true" xsi:type="string">Esun</argument>
<argument name="logo_image_src" xsi:type="string">Esun_Customer::images/esun.png</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

@@ -0,0 +1,65 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Esun_Customer::css/iconfont.css"/>
<css src="Esun_Customer::css/account-dashboard.css"/>
</head>
<body>
<referenceBlock name="customer-account-navigation-downloadable-products-link" remove="true"/>
<referenceBlock name="customer-account-navigation-my-credit-cards-link" remove="true"/>
<referenceBlock name="customer-account-navigation-newsletter-subscriptions-link" remove="true"/>
<referenceBlock name="customer-account-navigation-delimiter-2" remove="true"/>
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="wishlist_sidebar" remove="true"/>
<referenceBlock name="customer-account-navigation-account-link">
<arguments><argument name="sortOrder" xsi:type="number">300</argument></arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-orders-link">
<arguments><argument name="sortOrder" xsi:type="number">290</argument></arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-product-reviews-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">My Reviews</argument>
<argument name="sortOrder" xsi:type="number">280</argument>
</arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-wish-list-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">My Favorite</argument>
<argument name="sortOrder" xsi:type="number">275</argument>
</arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-coupons-link">
<arguments><argument name="sortOrder" xsi:type="number">270</argument></arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-delimiter-1">
<arguments><argument name="sortOrder" xsi:type="number">260</argument></arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-address-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Manage Address Book</argument>
<argument name="sortOrder" xsi:type="number">250</argument>
</arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-account-edit-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">Account Settings</argument>
<argument name="sortOrder" xsi:type="number">240</argument>
</arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-messages">
<arguments>
<argument name="label" xsi:type="string" translate="true">Message</argument>
<argument name="sortOrder" xsi:type="number">230</argument>
</arguments>
</referenceBlock>
<referenceBlock name="customer-account-navigation-reward">
<arguments>
<argument name="label" xsi:type="string" translate="true">Points Redemption</argument>
<argument name="sortOrder" xsi:type="number">220</argument>
</arguments>
</referenceBlock>
</body>
</page>
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<head>
<css src="Esun_Customer::css/account-dashboard.css"/>
</head>
<body>
<referenceBlock name="page.main.title" remove="true"/>
<referenceBlock name="customer_account_dashboard_info" remove="true"/>
<referenceBlock name="customer_account_dashboard_address" remove="true"/>
<referenceBlock name="customer_account_dashboard_top" remove="true"/>
<referenceBlock name="catalog.compare.sidebar" remove="true"/>
<referenceBlock name="wishlist_sidebar" remove="true"/>
<referenceContainer name="content">
<block class="Esun\Customer\Block\Account\Dashboard" name="esun.customer.dashboard"
template="Esun_Customer::account/dashboard.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head><css src="Esun_Customer::css/account-dashboard.css"/></head>
<body>
<referenceBlock name="page.main.title" remove="true"/>
<referenceBlock name="sales.order.history" remove="true"/>
<referenceContainer name="content">
<block class="Esun\Customer\Block\Order\History" name="esun.sales.order.history"
template="Esun_Customer::order/history.phtml" cacheable="false" before="customer.account.link.back"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head><css src="Esun_Customer::css/account-dashboard.css"/></head>
<body>
<referenceBlock name="page.main.title" remove="true"/>
<referenceBlock name="order.comments" remove="true"/>
<referenceBlock name="sales.order.info.links" remove="true"/>
<referenceBlock name="sales.order.view" remove="true"/>
<referenceBlock name="sales.order.info" remove="true"/>
<referenceContainer name="content">
<block class="Esun\Customer\Block\Order\Detail" name="esun.sales.order.detail"
template="Esun_Customer::order/detail.phtml" cacheable="false" before="-"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,18 @@
var config = {
config: {
mixins: {
'Magento_Customer/js/customer-data': {
'Esun_Customer/js/customer-data-init-mixin': true
},
'Magento_Ui/js/form/element/region': {
'Esun_Customer/js/checkout/region-mixin': true
},
'Amasty_CheckoutCore/js/form/element/region': {
'Esun_Customer/js/checkout/region-mixin': true
},
'Magento_Checkout/js/model/address-converter': {
'Esun_Customer/js/checkout/address-converter-mixin': true
}
}
}
};
@@ -0,0 +1,55 @@
<?php
/** @var \Esun\Customer\Block\Account\Dashboard $block */
/** @var \Magento\Framework\Escaper $escaper */
$counts = $block->getCounts();
$order = $block->getLatestPending();
?>
<div class="esun-account-dashboard">
<section class="esun-account-welcome">
<i class="esun-account-avatar iconfont icon-member6" aria-hidden="true"></i>
<div><h1><?= $escaper->escapeHtml(__('Welcome, %1', $block->getCustomerName())) ?></h1>
<strong><?= $escaper->escapeHtml(__('Points: %1', $block->getPoints())) ?></strong></div>
<a class="action primary" href="<?= $escaper->escapeUrl($block->getUrl('reward/account')) ?>"><?= $escaper->escapeHtml(__('Points Center')) ?></a>
</section>
<section class="esun-account-panel esun-account-orders">
<header><h2><?= $escaper->escapeHtml(__('My Orders')) ?></h2>
<a href="<?= $escaper->escapeUrl($block->getUrl('sales/order/history')) ?>"><?= $escaper->escapeHtml(__('View All')) ?></a></header>
<nav class="esun-order-statuses" aria-label="<?= $escaper->escapeHtmlAttr(__('Order status')) ?>">
<a href="<?= $escaper->escapeUrl($block->getUrl('sales/order/history', ['status' => 'pending'])) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_payment1" aria-hidden="true"></i><?php if ($counts['pending']): ?><b><?= (int)$counts['pending'] ?></b><?php endif; ?></span><span><?= $escaper->escapeHtml(__('Awaiting Payment')) ?></span></a>
<a href="<?= $escaper->escapeUrl($block->getUrl('sales/order/history', ['status' => 'processing'])) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_shipped1" aria-hidden="true"></i><?php if ($counts['processing']): ?><b><?= (int)$counts['processing'] ?></b><?php endif; ?></span><span><?= $escaper->escapeHtml(__('Awaiting Shipping')) ?></span></a>
<a href="<?= $escaper->escapeUrl($block->getUrl('sales/order/history', ['status' => 'shipped'])) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_shipped3" aria-hidden="true"></i><?php if ($counts['shipped']): ?><b><?= (int)$counts['shipped'] ?></b><?php endif; ?></span><span><?= $escaper->escapeHtml(__('Shipped')) ?></span></a>
<a href="<?= $escaper->escapeUrl($block->getUrl('esun_review/customer/awaiting')) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_review1" aria-hidden="true"></i><?php if ($counts['awaiting_review']): ?><b><?= (int)$counts['awaiting_review'] ?></b><?php endif; ?></span><span><?= $escaper->escapeHtml(__('Awaiting Review')) ?></span></a>
</nav>
<?php if ($order): ?>
<article class="esun-recent-order">
<header><span><?= $escaper->escapeHtml(__('Date: %1', $block->formatDate($order->getCreatedAt(), \IntlDateFormatter::MEDIUM, true))) ?></span>
<span><?= $escaper->escapeHtml(__('Order Number: %1', $order->getIncrementId())) ?></span></header>
<div class="esun-recent-order__body"><div class="esun-order-thumbnails">
<?php foreach ($order->getAllVisibleItems() as $item): ?>
<img src="<?= $escaper->escapeUrl($block->getOrderItemImageUrl($item)) ?>" alt="<?= $escaper->escapeHtmlAttr($item->getName()) ?>" loading="lazy">
<?php endforeach; ?>
</div><strong><?= /* @noEscape */ $order->formatPrice($order->getGrandTotal()) ?></strong>
<span><?= $escaper->escapeHtml($order->getStatusLabel()) ?></span>
<a href="<?= $escaper->escapeUrl($block->getUrl('sales/order/view', ['order_id' => $order->getId()])) ?>"><?= $escaper->escapeHtml(__('Order Details')) ?></a></div>
</article>
<?php else: ?><p class="esun-empty-note"><?= $escaper->escapeHtml(__('There are no orders awaiting payment.')) ?></p><?php endif; ?>
</section>
<div class="esun-account-card-grid">
<section class="esun-account-panel esun-account-services">
<article class="esun-service-card">
<a class="esun-service-card__link" href="<?= $escaper->escapeUrl($block->getUrl('customer-coupon/account/index')) ?>"><i class="iconfont icon-coupon1" aria-hidden="true"></i><span><?= $escaper->escapeHtml(__('My Coupons')) ?></span></a>
<?php $coupons = $block->getAvailableCoupons(); if ($coupons): foreach ($coupons as $coupon): ?>
<div class="esun-dashboard-row"><strong><?= $escaper->escapeHtml($coupon['discount_label']) ?></strong><span><?= $escaper->escapeHtml($coupon['code']) ?></span></div>
<?php endforeach; else: ?><p class="esun-empty-note"><?= $escaper->escapeHtml(__('You have no available coupons.')) ?></p><?php endif; ?>
</article>
<?= $block->getChildHtml('messages') ?>
</section>
<section class="esun-account-panel esun-wishlist-card"><header><h2><?= $escaper->escapeHtml(__('Wish List')) ?></h2><a href="<?= $escaper->escapeUrl($block->getUrl('wishlist')) ?>"><?= $escaper->escapeHtml(__('View All')) ?></a></header>
<div class="esun-dashboard-products"><?php $wishlist = $block->getWishlistItems(); if ($wishlist): foreach ($wishlist as $item): $product = $item->getProduct(); ?>
<a href="<?= $escaper->escapeUrl($product->getProductUrl()) ?>"><img src="<?= $escaper->escapeUrl($block->getProductImageUrl($product)) ?>" alt="<?= $escaper->escapeHtmlAttr($product->getName()) ?>"><span><?= $escaper->escapeHtml($product->getName()) ?></span></a>
<?php endforeach; else: ?><div class="esun-wishlist-empty"><i class="iconfont icon-favorite4" aria-hidden="true"></i><p><?= $escaper->escapeHtml(__('Your wish list is empty.')) ?></p></div><?php endif; ?></div>
</section>
</div>
</div>
@@ -0,0 +1,98 @@
<?php
/** @var \Esun\Customer\Block\Order\Detail $block */
/** @var \Magento\Framework\Escaper $escaper */
$order = $block->getOrder();
$currentStep = $block->getCurrentStepIndex();
$shippingAddress = $order->getShippingAddress();
$discountAmount = (float)$order->getDiscountAmount();
$rewardDiscount = (float)$order->getData('reward_discount_amount');
?>
<div class="esun-order-detail">
<section class="esun-order-detail__panel esun-order-detail__overview">
<h1><?= $escaper->escapeHtml(__('Order Number %1', $order->getIncrementId())) ?></h1>
<div class="esun-order-progress">
<?php foreach ($block->getSteps() as $index => $step): ?>
<div class="esun-order-progress__step <?= $index <= $currentStep ? 'is-reached' : '' ?> <?= $index === $currentStep ? 'is-current' : '' ?>">
<div class="esun-order-progress__track"><i class="iconfont <?= $escaper->escapeHtmlAttr($step['icon']) ?>" aria-hidden="true"></i></div>
<strong><?= $escaper->escapeHtml($step['label']) ?></strong>
<?php if ($index === $currentStep): ?>
<time><?= $escaper->escapeHtml($block->formatDate($block->getCurrentStepDate(), \IntlDateFormatter::MEDIUM, true)) ?></time>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<div class="esun-order-detail__status-bar">
<strong><?= $escaper->escapeHtml($order->getStatusLabel()) ?></strong>
<?php if ($block->canRepay($order)): ?>
<form method="post" action="<?= $escaper->escapeUrl($block->getRepayUrl($order)) ?>">
<?= $block->getBlockHtml('formkey') ?>
<button class="action primary" type="submit"><?= $escaper->escapeHtml(__('Pay Now')) ?></button>
</form>
<?php elseif ($block->canConfirmReceipt($order)): ?>
<form method="post" action="<?= $escaper->escapeUrl($block->getReceiveUrl()) ?>">
<?= $block->getBlockHtml('formkey') ?>
<input type="hidden" name="order_id" value="<?= (int)$order->getId() ?>">
<button class="action primary" type="submit"><?= $escaper->escapeHtml(__('Confirm Receipt')) ?></button>
</form>
<?php endif; ?>
</div>
</section>
<?= /* @noEscape */ $block->getChildHtml('seventeen_track') ?>
<section class="esun-order-detail__panel esun-order-information">
<h2><?= $escaper->escapeHtml(__('Order Information')) ?></h2>
<dl>
<dt><?= $escaper->escapeHtml(__('Order Date:')) ?></dt>
<dd><?= $escaper->escapeHtml($block->formatDate($order->getCreatedAt(), \IntlDateFormatter::LONG, false)) ?></dd>
<dt><?= $escaper->escapeHtml(__('Payment Method:')) ?></dt>
<dd><?= $escaper->escapeHtml($block->getPaymentMethodTitle()) ?></dd>
<?php if ($shippingAddress): ?>
<dt><?= $escaper->escapeHtml(__('Shipped To:')) ?></dt>
<dd><address><?= /* @noEscape */ $block->getFormattedAddress($shippingAddress) ?></address></dd>
<?php endif; ?>
</dl>
</section>
<section class="esun-order-detail__panel esun-order-summary">
<h2><?= $escaper->escapeHtml(__('Order Summary')) ?></h2>
<?php if (!$order->getIsVirtual()): ?>
<div class="esun-order-summary__shipping">
<span><?= $escaper->escapeHtml(__('Shipping Method: %1', $order->getShippingDescription() ?: __('No shipping information available'))) ?></span>
<span><?= $escaper->escapeHtml(__('Shipping:')) ?> <?= /* @noEscape */ $order->formatPrice($order->getShippingAmount()) ?></span>
</div>
<?php endif; ?>
<div class="esun-order-summary__table">
<div class="esun-order-summary__head">
<span><?= $escaper->escapeHtml(__('Item')) ?></span>
<span><?= $escaper->escapeHtml(__('Price')) ?></span>
<span><?= $escaper->escapeHtml(__('Quantity')) ?></span>
<span><?= $escaper->escapeHtml(__('Subtotal')) ?></span>
</div>
<?php foreach ($order->getAllVisibleItems() as $item): ?>
<div class="esun-order-summary__item">
<div class="esun-order-summary__product">
<img src="<?= $escaper->escapeUrl($block->getItemImageUrl($item)) ?>" alt="<?= $escaper->escapeHtmlAttr($item->getName()) ?>" loading="lazy">
<div><strong><?= $escaper->escapeHtml($item->getName()) ?></strong>
<?php foreach ((array)($item->getProductOptions()['attributes_info'] ?? []) as $option): ?>
<p><?= $escaper->escapeHtml($option['label'] . ': ' . $option['value']) ?></p>
<?php endforeach; ?>
</div>
</div>
<span data-label="<?= $escaper->escapeHtmlAttr(__('Price')) ?>"><?= /* @noEscape */ $order->formatPrice($item->getPrice()) ?></span>
<span data-label="<?= $escaper->escapeHtmlAttr(__('Quantity')) ?>">x<?= $escaper->escapeHtml(rtrim(rtrim(number_format((float)$item->getQtyOrdered(), 2, '.', ''), '0'), '.')) ?></span>
<span data-label="<?= $escaper->escapeHtmlAttr(__('Subtotal')) ?>"><?= /* @noEscape */ $order->formatPrice($item->getRowTotal()) ?></span>
</div>
<?php endforeach; ?>
</div>
<div class="esun-order-summary__totals">
<div><span><?= $escaper->escapeHtml(__('Subtotal:')) ?></span><span><?= /* @noEscape */ $order->formatPrice($order->getSubtotal()) ?></span></div>
<div><span><?= $escaper->escapeHtml(__('Shipping:')) ?></span><span><?= /* @noEscape */ $order->formatPrice($order->getShippingAmount()) ?></span></div>
<?php if ($discountAmount): ?><div><span><?= $escaper->escapeHtml(__('Discount:')) ?></span><span><?= /* @noEscape */ $order->formatPrice($discountAmount) ?></span></div><?php endif; ?>
<?php if ($rewardDiscount): ?><div><span><?= $escaper->escapeHtml(__('Points Discount:')) ?></span><span><?= /* @noEscape */ $order->formatPrice(-abs($rewardDiscount)) ?></span></div><?php endif; ?>
<?php if ((float)$order->getTaxAmount()): ?><div><span><?= $escaper->escapeHtml(__('Tax:')) ?></span><span><?= /* @noEscape */ $order->formatPrice($order->getTaxAmount()) ?></span></div><?php endif; ?>
<?php if ((int)$order->getData('reward_points_earned')): ?><div><span><?= $escaper->escapeHtml(__('Points Earned:')) ?></span><span><?= (int)$order->getData('reward_points_earned') ?></span></div><?php endif; ?>
<div class="grand-total"><strong><?= $escaper->escapeHtml(__('Grand Total:')) ?></strong><strong><?= /* @noEscape */ $order->formatPrice($order->getGrandTotal()) ?></strong></div>
</div>
</section>
</div>
@@ -0,0 +1,63 @@
<?php
/** @var \Esun\Customer\Block\Order\History $block */
/** @var \Magento\Framework\Escaper $escaper */
$orders = $block->getOrders(); $counts = $block->getCounts();
/** @var \Esun\CustomerMessage\ViewModel\OrderUnread|null $messageUnread */
$messageUnread = $block->getData('message_unread_view_model');
$orderUnreadCounts = [];
if ($orders && $messageUnread) {
$orderUnreadCounts = $messageUnread->getUnreadCounts(
array_map('intval', $orders->getColumnValues('entity_id'))
);
}
?>
<div class="esun-order-history">
<h1><?= $escaper->escapeHtml(__('My Orders')) ?></h1>
<nav class="esun-order-statuses esun-order-statuses--history">
<a class="<?= $block->getCurrentStatus() === 'pending' ? 'is-active' : '' ?>" href="<?= $escaper->escapeUrl($block->getUrl('sales/order/history', ['status'=>'pending'])) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_payment1" aria-hidden="true"></i><?php if($counts['pending']):?><b><?= (int)$counts['pending'] ?></b><?php endif;?></span><span><?= $escaper->escapeHtml(__('Awaiting Payment')) ?></span></a>
<a class="<?= $block->getCurrentStatus() === 'processing' ? 'is-active' : '' ?>" href="<?= $escaper->escapeUrl($block->getUrl('sales/order/history', ['status'=>'processing'])) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_shipped1" aria-hidden="true"></i><?php if($counts['processing']):?><b><?= (int)$counts['processing'] ?></b><?php endif;?></span><span><?= $escaper->escapeHtml(__('Awaiting Shipping')) ?></span></a>
<a class="<?= $block->getCurrentStatus() === 'shipped' ? 'is-active' : '' ?>" href="<?= $escaper->escapeUrl($block->getUrl('sales/order/history', ['status'=>'shipped'])) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_shipped3" aria-hidden="true"></i><?php if($counts['shipped']):?><b><?= (int)$counts['shipped'] ?></b><?php endif;?></span><span><?= $escaper->escapeHtml(__('Shipped')) ?></span></a>
<a href="<?= $escaper->escapeUrl($block->getUrl('esun_review/customer/awaiting')) ?>"><span class="esun-status-icon-wrap"><i class="esun-status-icon iconfont icon-order_review1" aria-hidden="true"></i><?php if($counts['awaiting_review']):?><b><?= (int)$counts['awaiting_review'] ?></b><?php endif;?></span><span><?= $escaper->escapeHtml(__('Awaiting Review')) ?></span></a>
</nav>
<form class="esun-order-filters" method="get" action="<?= $escaper->escapeUrl($block->getUrl('sales/order/history')) ?>">
<label><span class="label"><?= $escaper->escapeHtml(__('Search orders')) ?></span><input type="search" name="q" value="<?= $escaper->escapeHtmlAttr($block->getSearchQuery()) ?>" placeholder="<?= $escaper->escapeHtmlAttr(__('Product Name/Order No.')) ?>"></label>
<label><span class="label"><?= $escaper->escapeHtml(__('Order Status')) ?></span><select name="status">
<option value=""><?= $escaper->escapeHtml(__('All Orders')) ?></option>
<?php foreach (['pending'=>__('Awaiting Payment'),'processing'=>__('Awaiting Shipping'),'shipped'=>__('Shipped'),'received'=>__('Received')] as $value=>$label): ?><option value="<?= $escaper->escapeHtmlAttr($value) ?>" <?= $block->getCurrentStatus()===$value?'selected':'' ?>><?= $escaper->escapeHtml($label) ?></option><?php endforeach; ?>
</select></label><button class="action primary" type="submit"><?= $escaper->escapeHtml(__('Search')) ?></button>
</form>
<?php if ($orders && $orders->getSize()): foreach ($orders as $order): ?>
<article class="esun-order-card"><header><span><?= $escaper->escapeHtml(__('Date: %1', $block->formatDate($order->getCreatedAt(), \IntlDateFormatter::MEDIUM, false))) ?></span><span><?= $escaper->escapeHtml(__('Order Number:')) ?> <a class="esun-order-number-link" href="<?= $escaper->escapeUrl($block->getViewUrl($order)) ?>"><?= $escaper->escapeHtml($order->getIncrementId()) ?></a></span></header>
<div class="esun-order-card__content"><div class="esun-order-card__items">
<?php foreach ($order->getAllVisibleItems() as $index=>$item): ?><div class="esun-order-item"><div class="esun-order-item__visual"><img src="<?= $escaper->escapeUrl($block->getItemImageUrl($item)) ?>" alt="<?= $escaper->escapeHtmlAttr($item->getName()) ?>"><span class="esun-item-number"><?= $index+1 ?></span></div><div><h3><?= $escaper->escapeHtml($item->getName()) ?></h3>
<?php foreach ((array)($item->getProductOptions()['attributes_info'] ?? []) as $option): ?><p><?= $escaper->escapeHtml($option['label'].': '.$option['value']) ?></p><?php endforeach; ?>
<strong><?= /* @noEscape */ $order->formatPrice($item->getPrice()) ?></strong></div></div><?php endforeach; ?>
</div><div class="esun-order-card__summary"><strong class="esun-order-card__grand-total"><?= /* @noEscape */ $order->formatPrice($order->getGrandTotal()) ?></strong><span class="esun-order-card__status"><?= $escaper->escapeHtml($order->getStatusLabel()) ?></span><div class="esun-order-card__actions">
<?php if ($block->canRepay($order)): ?><form method="post" action="<?= $escaper->escapeUrl($block->getRepayUrl($order)) ?>"><?= $block->getBlockHtml('formkey') ?><button class="action primary esun-order-pay" type="submit"><?= $escaper->escapeHtml(__('Pay Now')) ?></button></form><?php endif; ?>
<?php if ((string)$order->getStatus()==='shipped'): ?><form method="post" action="<?= $escaper->escapeUrl($block->getUrl('esun_customer/order/receive')) ?>"><?= $block->getBlockHtml('formkey') ?><input type="hidden" name="order_id" value="<?= (int)$order->getId() ?>"><button class="action primary" type="submit"><?= $escaper->escapeHtml(__('Confirm Receipt')) ?></button></form><?php endif; ?>
<?php $unreadCount = $orderUnreadCounts[(int)$order->getId()] ?? 0; ?>
<details class="esun-order-more"><summary><span><?= $escaper->escapeHtml(__('View More')) ?></span><?php if ($unreadCount): ?><b class="esun-unread-badge" aria-label="<?= $escaper->escapeHtmlAttr(__('%1 unread messages', $unreadCount)) ?>"><?= (int)$unreadCount ?></b><?php endif; ?><i aria-hidden="true"></i></summary><div class="esun-order-more__menu">
<a href="#" data-post='<?= /* @noEscape */ $block->getBuyAgainPostData($order) ?>'><?= $escaper->escapeHtml(__('Buy Again')) ?></a>
<a class="esun-order-contact-link" href="<?= $escaper->escapeUrl($block->getUrl('customer-message/order/contact', ['order_id' => (int)$order->getId()])) ?>"><span><?= $escaper->escapeHtml(__('Contact')) ?></span><?php if ($unreadCount): ?><b class="esun-unread-badge" aria-label="<?= $escaper->escapeHtmlAttr(__('%1 unread messages', $unreadCount)) ?>"><?= (int)$unreadCount ?></b><?php endif; ?></a>
<?php if ($block->canCancel($order)): ?><form method="post" action="<?= $escaper->escapeUrl($block->getCancelUrl($order)) ?>"><?= $block->getBlockHtml('formkey') ?><button type="submit"><?= $escaper->escapeHtml(__('Cancel Order')) ?></button></form><?php endif; ?>
</div></details></div></div></div>
</article>
<?php endforeach; echo $block->getPagerHtml(); else: ?><div class="message info empty"><span><?= $escaper->escapeHtml(__('No orders matched your filters.')) ?></span></div><?php endif; ?>
</div>
<script>
require(['jquery'], function ($) {
'use strict';
if (!window.matchMedia('(hover: hover) and (pointer: fine)').matches) {
return;
}
$('.esun-order-more')
.on('mouseenter', function () {
this.open = true;
})
.on('mouseleave', function () {
this.open = false;
});
});
</script>
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,24 @@
define([
'jquery'
], function ($) {
'use strict';
return function (config, element) {
var $book = $(element);
var $tabs = $book.find('[data-address-tab]');
var $panels = $book.find('[data-address-panel]');
$tabs.on('click', function () {
var $tab = $(this);
var target = $tab.attr('data-address-tab');
$tabs.removeClass('is-active').attr('aria-selected', 'false');
$tab.addClass('is-active').attr('aria-selected', 'true');
$panels.removeClass('is-active').prop('hidden', true);
$panels.filter('[data-address-panel="' + target + '"]')
.addClass('is-active')
.prop('hidden', false);
});
};
});
@@ -0,0 +1,89 @@
define([
'jquery',
'mage/utils/wrapper',
'Magento_Customer/js/customer-data',
'uiRegistry'
], function ($, wrapper, customerData, registry) {
'use strict';
var directoryData = customerData.get('directory-data');
/**
* Resolve a region from customer-data or the checkout provider dictionary.
*
* The provider dictionary is rendered with the checkout page and is
* available before the asynchronous customer-data section has loaded.
*
* @param {Object} addressData
* @returns {Object|null}
*/
function getRegion(addressData) {
var countries = directoryData() || {},
country = countries[addressData.country_id],
provider,
options,
option;
if (country && country.regions) {
option = country.regions[addressData.region_id];
if (option) {
return {
code: option.code,
name: option.name
};
}
}
provider = registry.get('checkoutProvider');
options = provider && provider.dictionaries && provider.dictionaries.region_id;
if (!options && provider && typeof provider.get === 'function') {
options = provider.get('dictionaries.region_id');
}
if (!Array.isArray(options)) {
return null;
}
options.some(function (item) {
if (String(item.value) === String(addressData.region_id) &&
(!item.country_id || item.country_id === addressData.country_id)
) {
option = item;
return true;
}
return false;
});
return option ? {
code: addressData.region_code || '',
name: option.label || option.title
} : null;
}
return function (addressConverter) {
addressConverter.formAddressDataToQuoteAddress = wrapper.wrapSuper(
addressConverter.formAddressDataToQuoteAddress,
function (formData) {
var addressData = $.extend(true, {}, formData),
region;
if (addressData.region_id && !addressData.region) {
region = getRegion(addressData);
if (region) {
addressData.region = region.name;
addressData.region_code = region.code;
}
}
return this._super(addressData);
}
);
return addressConverter;
};
});
@@ -0,0 +1,79 @@
define([], function () {
'use strict';
return function (Region) {
return Region.extend({
/**
* Keep the text region value in sync with the selected region ID.
*
* Magento normally resolves the name later from the asynchronous
* directory-data customer section. When that section has not
* finished loading, a newly-created checkout address has a valid
* regionId but an empty region label, so its address card omits the
* state until the page is reloaded.
*
* @param {*} value
* @returns {Object}
*/
onUpdate: function (value) {
var result = this._super();
this.syncRegionName(value);
return result;
},
/**
* Synchronize addresses restored before their country regions have
* finished loading (most visible when editing a second address).
*
* @param {Array} options
* @returns {Object}
*/
setOptions: function (options) {
var result = this._super(options);
this.syncRegionName(this.value());
return result;
},
/**
* Copy the selected option label to the text region data scope.
*
* @param {*} value
*/
syncRegionName: function (value) {
var option = this.getOption(value),
regionScope = this.customEntry;
if (!regionScope && this.dataScope) {
regionScope = this.dataScope.replace(/region_id$/, 'region');
}
if (option && regionScope && this.source) {
this.source.set(regionScope, option.label);
}
},
/**
* Restore the region selector when switching from a country whose
* regions are hidden to one (such as US) that has region options.
*/
hideRegion: function (option) {
var hasVisibleRegions;
if (!option) {
return;
}
hasVisibleRegions = option.is_region_visible !== false && this.options().length > 1;
this.setVisible(hasVisibleRegions);
if (this.customEntry) {
this.toggleInput(!hasVisibleRegions && option.is_region_visible !== false);
}
}
});
};
});
@@ -0,0 +1,136 @@
define([
'jquery'
], function ($) {
'use strict';
return function (customerData) {
var initialized = false,
initPromise,
guardedMethods = [
'reload',
'set',
'invalidate',
'onAjaxComplete'
],
emptyArrayMethods = [
'getExpiredSectionNames',
'getExpiredKeys'
];
if (!customerData || customerData._esunCustomerDataInitGuard) {
return customerData;
}
customerData._esunCustomerDataInitGuard = true;
initPromise = typeof customerData.getInitCustomerData === 'function' ?
customerData.getInitCustomerData() :
null;
if (initPromise && typeof initPromise.done === 'function') {
initPromise.done(function () {
initialized = true;
});
} else {
initialized = true;
}
function resolveDeferred(deferred, result) {
if (result && typeof result.done === 'function') {
result.done(function () {
deferred.resolve.apply(deferred, arguments);
});
if (typeof result.fail === 'function') {
result.fail(function () {
deferred.reject.apply(deferred, arguments);
});
}
return;
}
deferred.resolve(result);
}
function runAfterInit(callback) {
var deferred = $.Deferred();
if (initialized) {
resolveDeferred(deferred, callback());
return deferred.promise();
}
if (!initPromise || typeof initPromise.done !== 'function') {
initialized = true;
resolveDeferred(deferred, callback());
return deferred.promise();
}
initPromise.done(function () {
initialized = true;
resolveDeferred(deferred, callback());
});
if (typeof initPromise.fail === 'function') {
initPromise.fail(function () {
deferred.reject.apply(deferred, arguments);
});
}
return deferred.promise();
}
guardedMethods.forEach(function (methodName) {
var originalMethod = customerData[methodName];
if (typeof originalMethod !== 'function') {
return;
}
customerData[methodName] = function () {
var context = this,
args = arguments;
if (initialized) {
return originalMethod.apply(context, args);
}
return runAfterInit(function () {
return originalMethod.apply(context, args);
});
};
});
emptyArrayMethods.forEach(function (methodName) {
var originalMethod = customerData[methodName];
if (typeof originalMethod !== 'function') {
return;
}
customerData[methodName] = function () {
if (!initialized) {
return [];
}
return originalMethod.apply(this, arguments);
};
});
if (typeof customerData.needReload === 'function') {
customerData.needReload = function (originalMethod) {
return function () {
if (!initialized) {
return false;
}
return originalMethod.apply(this, arguments);
};
}(customerData.needReload);
}
return customerData;
};
});