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,38 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Block\Account;
use Esun\LegacyOrder\Model\ResourceModel\Order\Collection;
use Esun\LegacyOrder\Model\ResourceModel\Order\CollectionFactory;
use Magento\Customer\Model\Session;
use Magento\Framework\View\Element\Template;
class History extends Template
{
private ?Collection $orders = null;
public function __construct(
Template\Context $context,
private readonly CollectionFactory $collectionFactory,
private readonly Session $customerSession,
array $data = []
) {
parent::__construct($context, $data);
}
public function getOrders(): Collection
{
if ($this->orders === null) {
$this->orders = $this->collectionFactory->create()
->addFieldToFilter('customer_id', (int)$this->customerSession->getCustomerId())
->setOrder('ordered_at', 'DESC');
}
return $this->orders;
}
public function getViewUrl(int $legacyOrderId): string
{
return $this->getUrl('legacy_order/account/view', ['id' => $legacyOrderId]);
}
}
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Block\Account;
use Magento\Customer\Block\Account\SortLinkInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\App\DefaultPathInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\View\Element\Html\Link\Current;
use Magento\Framework\View\Element\Template\Context;
class NavigationLink extends Current implements SortLinkInterface
{
private ?bool $hasLegacyOrders = null;
public function __construct(
Context $context,
DefaultPathInterface $defaultPath,
private readonly Session $customerSession,
private readonly ResourceConnection $resource,
array $data = []
) {
parent::__construct($context, $defaultPath, $data);
}
public function getSortOrder(): int
{
return (int)$this->getData(self::SORT_ORDER);
}
public function isCurrent(): bool
{
if (
$this->getRequest()->getModuleName() === 'legacy_order'
&& $this->getRequest()->getControllerName() === 'account'
) {
return true;
}
return parent::isCurrent();
}
protected function _toHtml(): string
{
return $this->hasLegacyOrders() ? parent::_toHtml() : '';
}
private function hasLegacyOrders(): bool
{
if ($this->hasLegacyOrders !== null) {
return $this->hasLegacyOrders;
}
$customerId = (int)$this->customerSession->getCustomerId();
if ($customerId <= 0) {
return $this->hasLegacyOrders = false;
}
$connection = $this->resource->getConnection();
return $this->hasLegacyOrders = (bool)$connection->fetchOne(
$connection->select()
->from($this->resource->getTableName('esun_legacy_order'), ['legacy_order_id'])
->where('customer_id = ?', $customerId)
->limit(1)
);
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Block\Account;
use Magento\Customer\Model\Session;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Template;
class OrderView extends Template
{
/** @var array<string, mixed>|null */
private ?array $order = null;
public function __construct(
Template\Context $context,
private readonly Session $customerSession,
private readonly ResourceConnection $resource,
private readonly Json $json,
array $data = []
) {
parent::__construct($context, $data);
}
/** @return array<string, mixed> */
public function getOrder(): array
{
if ($this->order !== null) {
return $this->order;
}
$connection = $this->resource->getConnection();
return $this->order = $connection->fetchRow(
$connection->select()
->from($this->resource->getTableName('esun_legacy_order'))
->where('legacy_order_id = ?', (int)$this->getRequest()->getParam('id'))
->where('customer_id = ?', (int)$this->customerSession->getCustomerId())
) ?: [];
}
/** @return array<int, array<string, mixed>> */
public function getItems(): array
{
$order = $this->getOrder();
if (!$order) {
return [];
}
$connection = $this->resource->getConnection();
return $connection->fetchAll(
$connection->select()
->from($this->resource->getTableName('esun_legacy_order_item'))
->where('legacy_order_id = ?', (int)$order['legacy_order_id'])
->order('line_number ASC')
);
}
/** @return array<string, mixed> */
public function decodeAddress(?string $value): array
{
try {
return $value ? (array)$this->json->unserialize($value) : [];
} catch (\Throwable) {
return [];
}
}
}
@@ -0,0 +1,107 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Block\Adminhtml\Customer\Edit\Tab;
use Magento\Backend\Block\Template;
use Magento\Customer\Controller\RegistryConstants;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Registry;
use Magento\Ui\Component\Layout\Tabs\TabInterface;
class LegacyOrders extends Template implements TabInterface
{
protected $_template = 'Esun_LegacyOrder::customer/tab/legacy_orders.phtml';
/** @var array<int, array<string, mixed>>|null */
private ?array $legacyOrders = null;
public function __construct(
Template\Context $context,
private readonly Registry $registry,
private readonly ResourceConnection $resource,
array $data = []
) {
parent::__construct($context, $data);
}
public function getTabLabel()
{
return __('Legacy Orders');
}
public function getTabTitle()
{
return __('Legacy Orders');
}
public function getTabClass(): string
{
return '';
}
public function getTabUrl(): string
{
return '';
}
public function isAjaxLoaded(): bool
{
return false;
}
public function canShowTab(): bool
{
return $this->getCustomerId() > 0;
}
public function isHidden(): bool
{
return false;
}
public function getAfter(): string
{
return 'orders';
}
public function getCustomerId(): int
{
return (int)$this->registry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
}
/** @return array<int, array<string, mixed>> */
public function getLegacyOrders(): array
{
if ($this->legacyOrders !== null) {
return $this->legacyOrders;
}
$customerId = $this->getCustomerId();
if ($customerId <= 0) {
return $this->legacyOrders = [];
}
$connection = $this->resource->getConnection();
$select = $connection->select()
->from($this->resource->getTableName('esun_legacy_order'), [
'legacy_order_id',
'source_order_number',
'ordered_at',
'order_status',
'payment_status',
'shipping_status',
'grand_total',
'currency',
])
->where('customer_id = ?', $customerId)
->order('ordered_at DESC');
return $this->legacyOrders = $connection->fetchAll($select);
}
public function getLegacyOrderUrl(int $legacyOrderId): string
{
return $this->getUrl('esun_legacy_order/order/view', ['id' => $legacyOrderId]);
}
}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Block\Adminhtml\Import;
use Magento\Backend\Block\Template;use Magento\Store\Model\System\Store;
class Form extends Template {protected $_template='Esun_LegacyOrder::import/form.phtml';public function __construct(Template\Context$c,private readonly Store$stores,array$d=[]){parent::__construct($c,$d);}public function getWebsites():array{return$this->stores->getWebsiteValuesForForm(false,true);}public function hasValidatedFile():bool{return(bool)$this->_backendSession->getLegacyOrderImport();}}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Block\Adminhtml\Order;
use Magento\Backend\Block\Template;use Magento\Framework\App\ResourceConnection;use Magento\Framework\Serialize\Serializer\Json;
class View extends Template {protected $_template='Esun_LegacyOrder::order/view.phtml';private?array$order=null;public function __construct(Template\Context$c,private readonly ResourceConnection$r,private readonly Json$j,array$d=[]){parent::__construct($c,$d);}public function getOrder():array{if($this->order!==null)return$this->order;$db=$this->r->getConnection();return$this->order=$db->fetchRow($db->select()->from($this->r->getTableName('esun_legacy_order'))->where('legacy_order_id=?',(int)$this->getRequest()->getParam('id')))?:[];}public function getItems():array{$o=$this->getOrder();if(!$o)return[];$db=$this->r->getConnection();return$db->fetchAll($db->select()->from($this->r->getTableName('esun_legacy_order_item'))->where('legacy_order_id=?',(int)$o['legacy_order_id'])->order('line_number'));}public function decode(?string$v):array{try{return$v?(array)$this->j->unserialize($v):[];}catch(\Throwable){return[];}}}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Account;
use Magento\Customer\Controller\AbstractAccount;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\View\Result\PageFactory;
class Index extends AbstractAccount implements HttpGetActionInterface
{
public function __construct(
Context $context,
private readonly PageFactory $pageFactory
) {
parent::__construct($context);
}
public function execute()
{
$page = $this->pageFactory->create();
$page->getConfig()->getTitle()->set(__('Historical Orders'));
return $page;
}
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Account;
use Magento\Customer\Controller\AbstractAccount;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\View\Result\PageFactory;
class View extends AbstractAccount implements HttpGetActionInterface
{
public function __construct(
Context $context,
private readonly PageFactory $pageFactory,
private readonly Session $customerSession,
private readonly ResourceConnection $resource
) {
parent::__construct($context);
}
public function execute()
{
$legacyOrderId = (int)$this->getRequest()->getParam('id');
$customerId = (int)$this->customerSession->getCustomerId();
$connection = $this->resource->getConnection();
$exists = $connection->fetchOne(
$connection->select()
->from($this->resource->getTableName('esun_legacy_order'), ['legacy_order_id'])
->where('legacy_order_id = ?', $legacyOrderId)
->where('customer_id = ?', $customerId)
);
if (!$exists) {
$this->messageManager->addErrorMessage(__('The historical order could not be found.'));
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)
->setPath('legacy_order/account/index');
}
$page = $this->pageFactory->create();
$page->getConfig()->getTitle()->set(__('Historical Order'));
return $page;
}
}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Import;
use Magento\Backend\App\Action;use Magento\Framework\View\Result\PageFactory;
class Index extends Action { public const ADMIN_RESOURCE='Esun_LegacyOrder::import';public function __construct(Action\Context $c,private readonly PageFactory $pages){parent::__construct($c);}public function execute(){$p=$this->pages->create();$p->setActiveMenu('Esun_LegacyOrder::orders');$p->getConfig()->getTitle()->prepend(__('Import Legacy Orders'));return$p;} }
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Import;
use Esun\LegacyOrder\Model\LegacyOrderImporter;use Magento\Backend\App\Action;use Magento\Framework\Controller\ResultFactory;
class Run extends Action {public const ADMIN_RESOURCE='Esun_LegacyOrder::import';public function __construct(Action\Context$c,private readonly LegacyOrderImporter$importer){parent::__construct($c);}public function execute(){$d=(array)$this->_getSession()->getLegacyOrderImport();try{if(empty($d['path']))throw new \RuntimeException('Validate a CSV file first.');$s=$this->importer->process($d['path'],(string)$d['source_code'],(int)$d['website_id'],(string)$d['currency'],true);if($s['errors'])throw new \RuntimeException(implode('; ',$s['errors']));$this->messageManager->addSuccessMessage(__("Imported %1 orders (%2 created, %3 updated), %4 items. Linked: %5; unlinked: %6.",$s['orders'],$s['created'],$s['updated'],$s['items'],$s['linked'],$s['unlinked']));$this->_getSession()->unsLegacyOrderImport();return$this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('esun_legacy_order/order/index');}catch(\Throwable$e){$this->messageManager->addErrorMessage($e->getMessage());return$this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index');}}}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Import;
use Esun\LegacyOrder\Model\LegacyOrderImporter;use Magento\Backend\App\Action;use Magento\Framework\App\Filesystem\DirectoryList;use Magento\Framework\Controller\ResultFactory;use Magento\Framework\Filesystem;use Magento\MediaStorage\Model\File\UploaderFactory;
class Validate extends Action {public const ADMIN_RESOURCE='Esun_LegacyOrder::import';public function __construct(Action\Context$c,private readonly UploaderFactory$uploaders,private readonly Filesystem$fs,private readonly LegacyOrderImporter$importer){parent::__construct($c);}public function execute(){try{$this->_getSession()->unsLegacyOrderImport();$dir=$this->fs->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);$dir->create('legacy_order');$u=$this->uploaders->create(['fileId'=>'csv_file']);$u->setAllowedExtensions(['csv']);$u->setAllowRenameFiles(true);$r=$u->save($dir->getAbsolutePath('legacy_order'));if(!$r)throw new \RuntimeException('Upload failed');$path=$r['path'].'/'.$r['file'];$stats=$this->importer->process($path,(string)$this->getRequest()->getParam('source_code'),(int)$this->getRequest()->getParam('website_id'),(string)$this->getRequest()->getParam('currency'),false);if(!$stats['errors']){$this->_getSession()->setLegacyOrderImport(['path'=>$path,'source_code'=>$this->getRequest()->getParam('source_code'),'website_id'=>$this->getRequest()->getParam('website_id'),'currency'=>$this->getRequest()->getParam('currency')]);$this->messageManager->addSuccessMessage(__("Validation passed: %1 orders, %2 items, %3 linked, %4 unlinked.",$stats['orders'],$stats['items'],$stats['linked'],$stats['unlinked']));}else{$this->messageManager->addErrorMessage(__('Validation failed; import is disabled until all errors are fixed.'));}foreach($stats['warnings'] as$w)$this->messageManager->addWarningMessage($w);foreach($stats['errors'] as$e)$this->messageManager->addErrorMessage($e);}catch(\Throwable$e){$this->messageManager->addErrorMessage($e->getMessage());}return$this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index');}}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Magento\Backend\App\Action;use Magento\Framework\View\Result\PageFactory;
class Index extends Action { public const ADMIN_RESOURCE='Esun_LegacyOrder::orders';public function __construct(Action\Context $c,private readonly PageFactory $pages){parent::__construct($c);}public function execute(){$p=$this->pages->create();$p->setActiveMenu('Esun_LegacyOrder::orders');$p->getConfig()->getTitle()->prepend(__('Legacy Orders'));return$p;} }
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Magento\Backend\App\Action;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;
class Link extends Action implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Esun_LegacyOrder::orders';
public function __construct(Action\Context $context, private readonly ResourceConnection $resource)
{
parent::__construct($context);
}
public function execute()
{
$orderId = (int)$this->getRequest()->getParam('id');
$query = trim((string)$this->getRequest()->getParam('customer'));
try {
if ($orderId <= 0 || $query === '') { throw new \RuntimeException('Enter a customer ID or email.'); }
$db=$this->resource->getConnection();$orders=$this->resource->getTableName('esun_legacy_order');$customers=$this->resource->getTableName('customer_entity');
$order=$db->fetchRow($db->select()->from($orders)->where('legacy_order_id=?',$orderId));
if(!$order)throw new \RuntimeException('Legacy order was not found.');
$select=$db->select()->from($customers,['entity_id','website_id','email'])->where('website_id=?',(int)$order['website_id']);
if(ctype_digit($query))$select->where('entity_id=?',(int)$query);else$select->where('LOWER(TRIM(email))=?',strtolower($query));
$matches=$db->fetchAll($select);
if(count($matches)===0)throw new \RuntimeException('No customer matched in the legacy order website.');
if(count($matches)>1)throw new \RuntimeException('More than one customer matched; use the customer ID.');
$customer=$matches[0];$db->update($orders,['customer_id'=>(int)$customer['entity_id'],'link_status'=>'linked'],['legacy_order_id=?'=>$orderId]);
$this->messageManager->addSuccessMessage(__('Legacy order linked to customer #%1 (%2).',$customer['entity_id'],$customer['email']));
}catch(\Throwable$e){$this->messageManager->addErrorMessage($e->getMessage());}
return$this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/view',['id'=>$orderId]);
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Esun\LegacyOrder\Model\ResourceModel\Order\CollectionFactory;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
class MassDelete extends Action
{
public const ADMIN_RESOURCE = 'Esun_LegacyOrder::orders';
public function __construct(
Action\Context $context,
private readonly Filter $filter,
private readonly CollectionFactory $collections
) {
parent::__construct($context);
}
public function execute()
{
try {
$collection = $this->filter->getCollection($this->collections->create());
$deleted = 0;
foreach ($collection as $order) {
$order->delete();
$deleted++;
}
$this->messageManager->addSuccessMessage(__('%1 legacy order(s) were deleted.', $deleted));
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage(__('Unable to delete legacy orders: %1', $exception->getMessage()));
}
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index');
}
}
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Esun\LegacyOrder\Model\ResourceModel\Order\CollectionFactory;
use Magento\Backend\App\Action;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
class MassLink extends Action implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Esun_LegacyOrder::orders';
public function __construct(
Action\Context $context,
private readonly Filter $filter,
private readonly CollectionFactory $collectionFactory,
private readonly ResourceConnection $resource
) {
parent::__construct($context);
}
public function execute()
{
$query = trim((string)$this->getRequest()->getParam('customer'));
if ($query === '') {
$this->messageManager->addErrorMessage(__('Enter a customer ID or email.'));
return $this->redirectToGrid();
}
try {
$collection = $this->filter->getCollection($this->collectionFactory->create());
$connection = $this->resource->getConnection();
$ordersTable = $this->resource->getTableName('esun_legacy_order');
$customersTable = $this->resource->getTableName('customer_entity');
$linked = 0;
$skipped = 0;
foreach ($collection as $order) {
$select = $connection->select()
->from($customersTable, ['entity_id', 'email'])
->where('website_id = ?', (int)$order->getData('website_id'));
if (ctype_digit($query)) {
$select->where('entity_id = ?', (int)$query);
} else {
$select->where('LOWER(TRIM(email)) = ?', strtolower($query));
}
$customers = $connection->fetchAll($select);
if (count($customers) !== 1) {
$skipped++;
continue;
}
$connection->update(
$ordersTable,
['customer_id' => (int)$customers[0]['entity_id'], 'link_status' => 'linked'],
['legacy_order_id = ?' => (int)$order->getId()]
);
$linked++;
}
if ($linked > 0) {
$this->messageManager->addSuccessMessage(__('%1 legacy order(s) were linked.', $linked));
}
if ($skipped > 0) {
$this->messageManager->addWarningMessage(
__('%1 order(s) were skipped because the customer did not uniquely match the order website.', $skipped)
);
}
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $this->redirectToGrid();
}
private function redirectToGrid()
{
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)
->setPath('*/*/index');
}
}
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Esun\LegacyOrder\Model\ResourceModel\Order\CollectionFactory;
use Magento\Backend\App\Action;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
class MassUnlink extends Action implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Esun_LegacyOrder::orders';
public function __construct(
Action\Context $context,
private readonly Filter $filter,
private readonly CollectionFactory $collectionFactory,
private readonly ResourceConnection $resource
) {
parent::__construct($context);
}
public function execute()
{
try {
$collection = $this->filter->getCollection($this->collectionFactory->create());
$ids = array_map('intval', $collection->getAllIds());
$updated = 0;
if ($ids) {
$updated = $this->resource->getConnection()->update(
$this->resource->getTableName('esun_legacy_order'),
['customer_id' => null, 'link_status' => 'unlinked'],
['legacy_order_id IN (?)' => $ids, 'customer_id IS NOT NULL']
);
}
$this->messageManager->addSuccessMessage(
__('%1 legacy order(s) were unbound from customers.', $updated)
);
$alreadyUnlinked = count($ids) - $updated;
if ($alreadyUnlinked > 0) {
$this->messageManager->addNoticeMessage(
__('%1 selected order(s) were already unbound.', $alreadyUnlinked)
);
}
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index');
}
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Esun\LegacyOrder\Block\Adminhtml\Order\View as ViewBlock;
use Magento\Backend\App\Action;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\View\LayoutFactory;
class Modal extends Action implements HttpGetActionInterface
{
public const ADMIN_RESOURCE = 'Esun_LegacyOrder::orders';
public function __construct(
Action\Context $context,
private readonly LayoutFactory $layoutFactory
) {
parent::__construct($context);
}
public function execute()
{
$layout = $this->layoutFactory->create();
$html = $layout->createBlock(ViewBlock::class)
->setData('modal', true)
->toHtml();
return $this->resultFactory->create(ResultFactory::TYPE_RAW)
->setHeader('Content-Type', 'text/html; charset=UTF-8', true)
->setContents($html);
}
}
@@ -0,0 +1,2 @@
<?php
declare(strict_types=1);namespace Esun\LegacyOrder\Controller\Adminhtml\Order;use Esun\LegacyOrder\Model\LegacyOrderImporter;use Magento\Backend\App\Action;use Magento\Framework\Controller\ResultFactory;class Relink extends Action{public const ADMIN_RESOURCE='Esun_LegacyOrder::orders';public function __construct(Action\Context$c,private readonly LegacyOrderImporter$i){parent::__construct($c);}public function execute(){$s=$this->i->relink();$this->messageManager->addSuccessMessage(__("Relink completed: %1 linked, %2 remain unlinked.",$s['linked'],$s['unlinked']));return$this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index');}}
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Magento\Backend\App\Action;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultFactory;
class Unlink extends Action implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Esun_LegacyOrder::orders';
public function __construct(Action\Context $context, private readonly ResourceConnection $resource){parent::__construct($context);}
public function execute()
{
$id=(int)$this->getRequest()->getParam('id');
try{if($id<=0)throw new \RuntimeException('Invalid legacy order.');$db=$this->resource->getConnection();$db->update($this->resource->getTableName('esun_legacy_order'),['customer_id'=>null,'link_status'=>'unlinked'],['legacy_order_id=?'=>$id]);$this->messageManager->addSuccessMessage(__('Customer link was removed.'));}catch(\Throwable$e){$this->messageManager->addErrorMessage($e->getMessage());}
return$this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/view',['id'=>$id]);
}
}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Controller\Adminhtml\Order;
use Magento\Backend\App\Action;use Magento\Framework\Controller\ResultFactory;use Magento\Framework\View\Result\PageFactory;
class View extends Action { public const ADMIN_RESOURCE='Esun_LegacyOrder::orders';public function __construct(Action\Context $c,private readonly PageFactory $pages){parent::__construct($c);}public function execute(){if((int)$this->getRequest()->getParam('id')<=0)return$this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('*/*/index');$p=$this->pages->create();$p->setActiveMenu('Esun_LegacyOrder::orders');$p->getConfig()->getTitle()->prepend(__('Legacy Order'));return$p;} }
@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Model;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Model\StoreManagerInterface;
class LegacyOrderImporter
{
private const REQUIRED = ['订单号','邮箱','产品总价','订单总额','产品单价','产品数量','产品SKU','创建时间'];
public function __construct(private readonly ResourceConnection $resource, private readonly Json $json, private readonly StoreManagerInterface $stores) {}
/** @return array{rows:int,orders:int,items:int,linked:int,unlinked:int,created:int,updated:int,errors:array<int,string>,warnings:array<int,string>} */
public function process(string $path, string $sourceCode, int $websiteId, string $currency, bool $commit): array
{
$sourceCode = trim($sourceCode); $currency = strtoupper(trim($currency));
if ($sourceCode === '' || !preg_match('/^[a-z0-9_-]{2,64}$/i', $sourceCode)) throw new LocalizedException(__('Source code must contain only letters, numbers, underscore or hyphen.'));
if (!preg_match('/^[A-Z]{3}$/', $currency)) throw new LocalizedException(__('Currency must be a 3-letter ISO code.'));
if ((int)$this->stores->getWebsite($websiteId)->getId() <= 0) throw new LocalizedException(__('Select a valid website.'));
if (!is_file($path) || !is_readable($path)) throw new LocalizedException(__('CSV file is not readable.'));
[$headers,$rows] = $this->read($path);
$missing = array_diff(self::REQUIRED, $headers);
if ($missing) throw new LocalizedException(__('Missing required columns: %1', implode(', ', $missing)));
$groups=[]; $errors=[]; $warnings=[];
foreach ($rows as $line=>$values) {
if (count($values)!==count($headers)) { $errors[]="Line $line: column count mismatch"; continue; }
$row=[]; foreach($headers as $i=>$header) $row[$header]=$values[$i];
$number=$this->clean($row['订单号']??'');
if($number===''){ $errors[]="Line $line: missing order number"; continue; }
$email=strtolower($this->clean($row['邮箱']??'')); $sku=$this->clean($row['产品SKU']??'');
if(!filter_var($email,FILTER_VALIDATE_EMAIL)){ $errors[]="Line $line: invalid email"; continue; }
if($sku===''){ $errors[]="Line $line: missing SKU"; continue; }
$row['_line']=$line; $row['_email']=$email; $row['_sku']=$sku;
$groups[$number][]=$row;
}
$stats=['rows'=>count($rows),'orders'=>count($groups),'items'=>0,'linked'=>0,'unlinked'=>0,'created'=>0,'updated'=>0,'errors'=>$errors,'warnings'=>[]];
foreach($groups as $number=>$items){
$stats['items']+=count($items); $head=$this->findHeaderRow($items);
$emails=array_unique(array_column($items,'_email'));
if(count($emails)!==1){$stats['errors'][]="Order $number: mixed customer emails";continue;}
try{$normalized=$this->normalizeOrder($number,$head,$items,$sourceCode,$websiteId,$currency);}catch(\Throwable $e){$stats['errors'][]="Order $number: ".$e->getMessage();continue;}
if($normalized['order']['customer_id'])$stats['linked']++;else{$stats['unlinked']++;$warnings[]="Order $number: customer not linked";}
if($commit){$exists=$this->save($normalized['order'],$normalized['items']);$stats[$exists?'updated':'created']++;}
}
$stats['warnings']=$warnings; return $stats;
}
public function relink(?int $websiteId = null): array
{
$db=$this->resource->getConnection();$table=$this->resource->getTableName('esun_legacy_order');
$select=$db->select()->from($table,['legacy_order_id','customer_email','website_id'])->where('customer_id IS NULL');
if($websiteId!==null)$select->where('website_id=?',$websiteId);
$linked=0;$unlinked=0;foreach($db->fetchAll($select) as$row){$customers=$this->findCustomers(strtolower(trim((string)$row['customer_email'])),(int)$row['website_id']);if(count($customers)===1){$db->update($table,['customer_id'=>(int)$customers[0]['entity_id'],'link_status'=>'linked'],['legacy_order_id=?'=>(int)$row['legacy_order_id']]);$linked++;}else{$db->update($table,['link_status'=>count($customers)>1?'conflict':'unlinked'],['legacy_order_id=?'=>(int)$row['legacy_order_id']]);$unlinked++;}}return['linked'=>$linked,'unlinked'=>$unlinked];
}
private function read(string $path): array
{
$h=fopen($path,'rb'); if(!$h)throw new LocalizedException(__('Unable to open CSV.'));
try{$headers=fgetcsv($h,null,',','"','\\');if($headers===false)throw new LocalizedException(__('CSV is empty.'));
$seen=[];foreach($headers as $i=>$name){$name=trim((string)$name,"\xEF\xBB\xBF \t\r\n");$seen[$name]=($seen[$name]??0)+1;$headers[$i]=$seen[$name]>1?$name.'_'.$seen[$name]:$name;}
$rows=[];$line=1;while(($row=fgetcsv($h,null,',','"','\\'))!==false){$line++;if(count($row)===1&&trim((string)$row[0])==='')continue;$rows[$line]=$row;}return[$headers,$rows];
}finally{fclose($h);}
}
private function findHeaderRow(array $items): array { foreach($items as $r)if($this->clean($r['产品总价']??'')!=='')return$r; throw new LocalizedException(__('missing order summary row')); }
private function normalizeOrder(string $number,array $h,array $items,string $source,int $website,string $currency): array
{
$email=$h['_email'];$customers=$this->findCustomers($email,$website);$customerId=count($customers)===1?(int)$customers[0]['entity_id']:null;
$ship=$this->address($h,'收货');$bill=$this->address($h,'账单');$batch=gmdate('YmdHis');
$order=['source_code'=>$source,'source_order_number'=>$number,'source_order_id'=>$this->clean($h['订单 ID']??''),'customer_id'=>$customerId,'website_id'=>$website,'customer_email'=>$email,'link_status'=>$customerId?'linked':(count($customers)>1?'conflict':'unlinked'),'currency'=>$currency,'product_total'=>$this->money($h['产品总价']??''),'discount_amount'=>$this->money($h['折扣']??''),'coupon'=>$this->nullable($h['优惠券']??''),'shipping_amount'=>$this->money($h['运费']??''),'tax_amount'=>$this->money($h['税费']??''),'grand_total'=>$this->money($h['订单总额']??''),'fee_amount'=>$this->money($h['手续费']??''),'payment_status'=>$this->nullable($h['付款状态']??''),'order_status'=>$this->nullable($h['订单状态']??''),'shipping_status'=>$this->nullable($h['发货状态']??''),'payment_method'=>$this->nullable($h['付款方式']??''),'payment_transaction_id'=>$this->nullable($h['支付流水号']??''),'shipping_method'=>$this->nullable($h['配送信息']??''),'carrier'=>$this->nullable($h['物流商']??''),'tracking_number'=>$this->nullable($h['运单号']??''),'weight'=>$this->number($h['重量']??''),'ordered_at'=>$this->date($h['创建时间']??''),'paid_at'=>$this->date($h['付款时间']??''),'shipping_address'=>$this->json->serialize($ship),'billing_address'=>$this->json->serialize($bill),'customer_note'=>$this->nullable($h['顾客备注']??''),'refund_reason'=>$this->nullable($h['退款原因']??''),'cancel_reason'=>$this->nullable($h['取消原因']??''),'source_data'=>$this->json->serialize($h),'import_batch'=>$batch];
$out=[];foreach($items as $r){$qty=$this->number($r['产品数量']??'');$price=$this->money($r['产品单价']??'');$out[]=['line_number'=>(int)$r['_line'],'sku'=>$r['_sku'],'product_name'=>$this->productName($r['_sku']),'qty'=>$qty,'price'=>$price,'row_total'=>$qty*$price,'source_data'=>$this->json->serialize($r)];}
return['order'=>$order,'items'=>$out];
}
private function save(array $order,array $items): bool
{
$db=$this->resource->getConnection();$ot=$this->resource->getTableName('esun_legacy_order');$it=$this->resource->getTableName('esun_legacy_order_item');
$id=$db->fetchOne($db->select()->from($ot,['legacy_order_id'])->where('source_code=?',$order['source_code'])->where('source_order_number=?',$order['source_order_number']));$exists=(bool)$id;
$db->beginTransaction();try{if($id){$db->update($ot,$order,['legacy_order_id=?'=>(int)$id]);}else{$db->insert($ot,$order);$id=$db->lastInsertId($ot);}$db->delete($it,['legacy_order_id=?'=>(int)$id]);foreach($items as $item){$item['legacy_order_id']=(int)$id;$db->insert($it,$item);}$db->commit();return$exists;}catch(\Throwable$e){if($db->getTransactionLevel()>0)$db->rollBack();throw$e;}
}
private function findCustomers(string $email,int $website): array{$db=$this->resource->getConnection();return$db->fetchAll($db->select()->from($this->resource->getTableName('customer_entity'),['entity_id'])->where('website_id=?',$website)->where('LOWER(TRIM(email))=?',$email));}
private function productName(string $sku): ?string{$db=$this->resource->getConnection();$id=$db->fetchOne($db->select()->from($this->resource->getTableName('catalog_product_entity'),['entity_id'])->where('sku=?',$sku));return$id?'':null;}
private function address(array $r,string $p):array{return['name'=>$this->clean($r[$p.'姓名']??''),'street'=>$this->clean($r[$p.'街道']??''),'unit'=>$this->clean($r[$p.'寓所']??''),'country'=>$this->clean($r[$p.'国家']??''),'region'=>$this->clean($r[$p.'省份']??''),'city'=>$this->clean($r[$p.'城市']??''),'postcode'=>$this->clean($r[$p.'邮编']??''),'telephone'=>$this->clean($r[$p.'电话']??'')];}
private function clean(mixed $v):string{return trim(str_replace(["\xEF\xBB\xBF","\t"],'',(string)$v));}
private function nullable(mixed $v):?string{$v=$this->clean($v);return$v===''||strtoupper($v)==='N/A'?null:$v;}
private function money(mixed $v):float{$v=preg_replace('/[^0-9.\-]/','',$this->clean($v));return$v===''?0.0:(float)$v;}
private function number(mixed $v):float{$v=str_replace(',','',$this->clean($v));return is_numeric($v)?(float)$v:0.0;}
private function date(mixed $v):?string{$v=$this->nullable($v);if(!$v)return null;$t=strtotime($v);return$t?date('Y-m-d H:i:s',$t):null;}
}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Model;
use Magento\Framework\Model\AbstractModel;
class Order extends AbstractModel { protected function _construct(): void { $this->_init(ResourceModel\Order::class); } }
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class Order extends AbstractDb { protected function _construct(): void { $this->_init('esun_legacy_order', 'legacy_order_id'); } }
@@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Model\ResourceModel\Order;
use Esun\LegacyOrder\Model\Order as Model;
use Esun\LegacyOrder\Model\ResourceModel\Order as Resource;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
class Collection extends AbstractCollection { protected function _construct(): void { $this->_init(Model::class, Resource::class); } }
@@ -0,0 +1,2 @@
<?php
declare(strict_types=1);namespace Esun\LegacyOrder\Model\Source;use Magento\Framework\Data\OptionSourceInterface;class LinkStatus implements OptionSourceInterface{public function toOptionArray():array{return[['value'=>'linked','label'=>__('Linked')],['value'=>'unlinked','label'=>__('Unlinked')],['value'=>'conflict','label'=>__('Conflict')]];}}
@@ -0,0 +1,5 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Ui\Component\Listing\Column;
use Magento\Framework\UrlInterface;use Magento\Ui\Component\Listing\Columns\Column;
class Actions extends Column {public function __construct(\Magento\Framework\View\Element\UiComponent\ContextInterface$c,\Magento\Framework\View\Element\UiComponentFactory$f,private readonly UrlInterface$urls,array$components=[],array$data=[]){parent::__construct($c,$f,$components,$data);}public function prepareDataSource(array$d):array{if(isset($d['data']['items']))foreach($d['data']['items'] as&$i)if(isset($i['legacy_order_id']))$i[$this->getData('name')]['view']=['href'=>$this->urls->getUrl('esun_legacy_order/order/modal',['id'=>$i['legacy_order_id']]),'label'=>__('View'),'modal'=>true];return$d;}}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Esun\LegacyOrder\Ui\Component\Listing\Column;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\Listing\Columns\Column;
class WebsiteName extends Column
{
/** @var array<int, string> */
private array $websiteNames = [];
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
private readonly StoreManagerInterface $storeManager,
array $components = [],
array $data = []
) {
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource): array
{
if (!isset($dataSource['data']['items'])) {
return $dataSource;
}
$fieldName = $this->getData('name');
foreach ($dataSource['data']['items'] as &$item) {
$websiteId = (int)($item['website_id'] ?? 0);
if (!isset($this->websiteNames[$websiteId])) {
try {
$this->websiteNames[$websiteId] = (string)$this->storeManager
->getWebsite($websiteId)
->getName();
} catch (\Throwable) {
$this->websiteNames[$websiteId] = (string)__('Unknown Website');
}
}
$item[$fieldName] = $this->websiteNames[$websiteId];
}
unset($item);
return $dataSource;
}
}
+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd"><acl><resources><resource id="Magento_Backend::admin"><resource id="Magento_Sales::sales"><resource id="Esun_LegacyOrder::orders" title="Legacy Orders" sortOrder="90"><resource id="Esun_LegacyOrder::import" title="Import Legacy Orders" sortOrder="10"/></resource></resource></resource></resources></acl></config>
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd"><menu><add id="Esun_LegacyOrder::orders" title="Legacy Orders" module="Esun_LegacyOrder" sortOrder="90" parent="Magento_Sales::sales" action="esun_legacy_order/order/index" resource="Esun_LegacyOrder::orders"/></menu></config>
@@ -0,0 +1,2 @@
<?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="admin"><route id="esun_legacy_order" frontName="esun_legacy_order"><module name="Esun_LegacyOrder" before="Magento_Backend"/></route></router></config>
@@ -0,0 +1,62 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="esun_legacy_order" resource="default" engine="innodb" comment="Legacy Orders">
<column xsi:type="int" name="legacy_order_id" unsigned="true" nullable="false" identity="true" comment="Legacy Order ID"/>
<column xsi:type="varchar" name="source_code" nullable="false" length="64" comment="Source Code"/>
<column xsi:type="varchar" name="source_order_number" nullable="false" length="64" comment="Source Order Number"/>
<column xsi:type="varchar" name="source_order_id" nullable="true" length="64" comment="Source Internal Order ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="true" comment="Customer ID"/>
<column xsi:type="smallint" name="website_id" unsigned="true" nullable="false" comment="Website ID"/>
<column xsi:type="varchar" name="customer_email" nullable="false" length="255" comment="Customer Email"/>
<column xsi:type="varchar" name="link_status" nullable="false" length="32" default="unlinked" comment="Customer Link Status"/>
<column xsi:type="varchar" name="currency" nullable="false" length="3" default="USD" comment="Currency"/>
<column xsi:type="decimal" name="product_total" precision="20" scale="4" nullable="false" default="0" comment="Product Total"/>
<column xsi:type="decimal" name="discount_amount" precision="20" scale="4" nullable="false" default="0" comment="Discount"/>
<column xsi:type="varchar" name="coupon" nullable="true" length="255" comment="Coupon"/>
<column xsi:type="decimal" name="shipping_amount" precision="20" scale="4" nullable="false" default="0" comment="Shipping"/>
<column xsi:type="decimal" name="tax_amount" precision="20" scale="4" nullable="false" default="0" comment="Tax"/>
<column xsi:type="decimal" name="grand_total" precision="20" scale="4" nullable="false" default="0" comment="Grand Total"/>
<column xsi:type="decimal" name="fee_amount" precision="20" scale="4" nullable="false" default="0" comment="Fee"/>
<column xsi:type="varchar" name="payment_status" nullable="true" length="64" comment="Payment Status"/>
<column xsi:type="varchar" name="order_status" nullable="true" length="64" comment="Order Status"/>
<column xsi:type="varchar" name="shipping_status" nullable="true" length="64" comment="Shipping Status"/>
<column xsi:type="varchar" name="payment_method" nullable="true" length="128" comment="Payment Method"/>
<column xsi:type="varchar" name="payment_transaction_id" nullable="true" length="255" comment="Payment Transaction"/>
<column xsi:type="varchar" name="shipping_method" nullable="true" length="255" comment="Shipping Method"/>
<column xsi:type="varchar" name="carrier" nullable="true" length="128" comment="Carrier"/>
<column xsi:type="varchar" name="tracking_number" nullable="true" length="255" comment="Tracking Number"/>
<column xsi:type="decimal" name="weight" precision="20" scale="4" nullable="false" default="0" comment="Weight"/>
<column xsi:type="timestamp" name="ordered_at" nullable="true" comment="Order Date"/>
<column xsi:type="timestamp" name="paid_at" nullable="true" comment="Payment Date"/>
<column xsi:type="text" name="shipping_address" nullable="true" comment="Shipping Address JSON"/>
<column xsi:type="text" name="billing_address" nullable="true" comment="Billing Address JSON"/>
<column xsi:type="text" name="customer_note" nullable="true" comment="Customer Note"/>
<column xsi:type="text" name="refund_reason" nullable="true" comment="Refund Reason"/>
<column xsi:type="text" name="cancel_reason" nullable="true" comment="Cancel Reason"/>
<column xsi:type="text" name="source_data" nullable="true" comment="Source Data JSON"/>
<column xsi:type="varchar" name="import_batch" nullable="true" length="64" comment="Import Batch"/>
<column xsi:type="timestamp" name="created_at" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<column xsi:type="timestamp" name="updated_at" nullable="false" default="CURRENT_TIMESTAMP" on_update="true" comment="Updated At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="legacy_order_id"/></constraint>
<constraint xsi:type="unique" referenceId="ESUN_LEGACY_ORDER_SOURCE_NUMBER_UNQ"><column name="source_code"/><column name="source_order_number"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_LEGACY_ORDER_CUSTOMER_FK" table="esun_legacy_order" column="customer_id" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="SET NULL"/>
<index referenceId="ESUN_LEGACY_ORDER_CUSTOMER_WEBSITE" indexType="btree"><column name="customer_id"/><column name="website_id"/></index>
<index referenceId="ESUN_LEGACY_ORDER_EMAIL" indexType="btree"><column name="customer_email"/></index>
<index referenceId="ESUN_LEGACY_ORDER_ORDERED_AT" indexType="btree"><column name="ordered_at"/></index>
</table>
<table name="esun_legacy_order_item" resource="default" engine="innodb" comment="Legacy Order Items">
<column xsi:type="int" name="item_id" unsigned="true" nullable="false" identity="true" comment="Item ID"/>
<column xsi:type="int" name="legacy_order_id" unsigned="true" nullable="false" comment="Legacy Order ID"/>
<column xsi:type="int" name="line_number" unsigned="true" nullable="false" comment="Source Line"/>
<column xsi:type="varchar" name="sku" nullable="false" length="255" comment="SKU"/>
<column xsi:type="varchar" name="product_name" nullable="true" length="255" comment="Product Name Snapshot"/>
<column xsi:type="decimal" name="qty" precision="12" scale="4" nullable="false" default="0" comment="Quantity"/>
<column xsi:type="decimal" name="price" precision="20" scale="4" nullable="false" default="0" comment="Unit Price"/>
<column xsi:type="decimal" name="row_total" precision="20" scale="4" nullable="false" default="0" comment="Row Total"/>
<column xsi:type="text" name="source_data" nullable="true" comment="Source Row JSON"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="item_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_LEGACY_ITEM_ORDER_FK" table="esun_legacy_order_item" column="legacy_order_id" referenceTable="esun_legacy_order" referenceColumn="legacy_order_id" onDelete="CASCADE"/>
<constraint xsi:type="unique" referenceId="ESUN_LEGACY_ITEM_ORDER_LINE_UNQ"><column name="legacy_order_id"/><column name="line_number"/></constraint>
<index referenceId="ESUN_LEGACY_ITEM_SKU" indexType="btree"><column name="sku"/></index>
</table>
</schema>
@@ -0,0 +1 @@
{"esun_legacy_order":{"column":{"legacy_order_id":true,"source_code":true,"source_order_number":true,"source_order_id":true,"customer_id":true,"website_id":true,"customer_email":true,"link_status":true,"currency":true,"product_total":true,"discount_amount":true,"coupon":true,"shipping_amount":true,"tax_amount":true,"grand_total":true,"fee_amount":true,"payment_status":true,"order_status":true,"shipping_status":true,"payment_method":true,"payment_transaction_id":true,"shipping_method":true,"carrier":true,"tracking_number":true,"weight":true,"ordered_at":true,"paid_at":true,"shipping_address":true,"billing_address":true,"customer_note":true,"refund_reason":true,"cancel_reason":true,"source_data":true,"import_batch":true,"created_at":true,"updated_at":true},"constraint":{"PRIMARY":true,"ESUN_LEGACY_ORDER_SOURCE_NUMBER_UNQ":true,"ESUN_LEGACY_ORDER_CUSTOMER_FK":true},"index":{"ESUN_LEGACY_ORDER_CUSTOMER_WEBSITE":true,"ESUN_LEGACY_ORDER_EMAIL":true,"ESUN_LEGACY_ORDER_ORDERED_AT":true}},"esun_legacy_order_item":{"column":{"item_id":true,"legacy_order_id":true,"line_number":true,"sku":true,"product_name":true,"qty":true,"price":true,"row_total":true,"source_data":true},"constraint":{"PRIMARY":true,"ESUN_LEGACY_ITEM_ORDER_FK":true,"ESUN_LEGACY_ITEM_ORDER_LINE_UNQ":true},"index":{"ESUN_LEGACY_ITEM_SKU":true}}}
+5
View File
@@ -0,0 +1,5 @@
<?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\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"><arguments><argument name="collections" xsi:type="array"><item name="esun_legacy_order_listing_data_source" xsi:type="string">EsunLegacyOrderGridCollection</item></argument></arguments></type>
<virtualType name="EsunLegacyOrderGridCollection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult"><arguments><argument name="mainTable" xsi:type="string">esun_legacy_order</argument><argument name="resourceModel" xsi:type="string">Esun\LegacyOrder\Model\ResourceModel\Order</argument></arguments></virtualType>
</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="legacy_order" frontName="legacy_order">
<module name="Esun_LegacyOrder"/>
</route>
</router>
</config>
+4
View File
@@ -0,0 +1,4 @@
<?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_LegacyOrder"><sequence><module name="Magento_Backend"/><module name="Magento_Customer"/><module name="Magento_Store"/><module name="Magento_Ui"/></sequence></module>
</config>
@@ -0,0 +1,5 @@
"This order is from the old website and is for historical reference only.","此订单来自旧网站,仅供历史记录查询。"
"Historical Orders","历史订单"
"Historical Order","历史订单"
"Back to Historical Orders","返回历史订单"
"No historical orders were found.","未找到历史订单。"
1 This order is from the old website and is for historical reference only. 此订单来自旧网站,仅供历史记录查询。
2 Historical Orders 历史订单
3 Historical Order 历史订单
4 Back to Historical Orders 返回历史订单
5 No historical orders were found. 未找到历史订单。
@@ -0,0 +1,4 @@
<?php
declare(strict_types=1);
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Esun_LegacyOrder', __DIR__);
@@ -0,0 +1 @@
<?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"><body><referenceContainer name="content"><block class="Esun\LegacyOrder\Block\Adminhtml\Import\Form" name="legacy.order.import"/></referenceContainer></body></page>
@@ -0,0 +1,6 @@
<?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_LegacyOrder::css/order-view.css"/></head>
<body><referenceContainer name="content"><uiComponent name="esun_legacy_order_listing"/></referenceContainer></body>
</page>
@@ -0,0 +1,12 @@
<?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_LegacyOrder::css/order-view.css"/>
</head>
<body>
<referenceContainer name="content">
<block class="Esun\LegacyOrder\Block\Adminhtml\Order\View" name="legacy.order.view"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,45 @@
<?php
/** @var \Esun\LegacyOrder\Block\Adminhtml\Customer\Edit\Tab\LegacyOrders $block */
$orders = $block->getLegacyOrders();
?>
<div class="admin__page-section">
<div class="admin__page-section-title">
<span class="title"><?= $block->escapeHtml(__('Legacy Orders')) ?></span>
</div>
<div class="admin__page-section-content">
<?php if (!$orders): ?>
<div class="message message-info info">
<div><?= $block->escapeHtml(__('No legacy orders are linked to this customer.')) ?></div>
</div>
<?php else: ?>
<div class="admin__data-grid-wrap">
<table class="data-grid">
<thead>
<tr>
<th class="data-grid-th"><?= $block->escapeHtml(__('Legacy Order #')) ?></th>
<th class="data-grid-th"><?= $block->escapeHtml(__('Order Date')) ?></th>
<th class="data-grid-th"><?= $block->escapeHtml(__('Order Status')) ?></th>
<th class="data-grid-th"><?= $block->escapeHtml(__('Payment Status')) ?></th>
<th class="data-grid-th"><?= $block->escapeHtml(__('Shipping Status')) ?></th>
<th class="data-grid-th"><?= $block->escapeHtml(__('Grand Total')) ?></th>
<th class="data-grid-th"><?= $block->escapeHtml(__('Action')) ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr class="data-row">
<td><a href="<?= $block->escapeUrl($block->getLegacyOrderUrl((int)$order['legacy_order_id'])) ?>"><?= $block->escapeHtml($order['source_order_number']) ?></a></td>
<td><?= $block->escapeHtml($order['ordered_at'] ?: '-') ?></td>
<td><?= $block->escapeHtml($order['order_status'] ?: '-') ?></td>
<td><?= $block->escapeHtml($order['payment_status'] ?: '-') ?></td>
<td><?= $block->escapeHtml($order['shipping_status'] ?: '-') ?></td>
<td><?= $block->escapeHtml(($order['currency'] ?: '') . ' ' . $order['grand_total']) ?></td>
<td><a href="<?= $block->escapeUrl($block->getLegacyOrderUrl((int)$order['legacy_order_id'])) ?>"><?= $block->escapeHtml(__('View')) ?></a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
@@ -0,0 +1,2 @@
<?php /** @var \Esun\LegacyOrder\Block\Adminhtml\Import\Form $block */ ?>
<div class="admin__fieldset-wrapper-content"><form action="<?= $block->escapeUrl($block->getUrl('esun_legacy_order/import/validate')) ?>" method="post" enctype="multipart/form-data"><input name="form_key" type="hidden" value="<?= $block->escapeHtmlAttr($block->getFormKey()) ?>"/><fieldset class="admin__fieldset"><div class="admin__field required"><label class="admin__field-label"><span><?= $block->escapeHtml(__('CSV File')) ?></span></label><div class="admin__field-control"><input class="admin__control-file" type="file" name="csv_file" accept=".csv" required/></div></div><div class="admin__field required"><label class="admin__field-label"><span><?= $block->escapeHtml(__('Source Code')) ?></span></label><div class="admin__field-control"><input class="admin__control-text" name="source_code" value="old_us_site" required/><div class="note"><?= $block->escapeHtml(__('Used with the legacy order number as the unique key.')) ?></div></div></div><div class="admin__field required"><label class="admin__field-label"><span><?= $block->escapeHtml(__('Target Website')) ?></span></label><div class="admin__field-control"><select class="admin__control-select" name="website_id" required><?php foreach($block->getWebsites() as $w): ?><option value="<?= $block->escapeHtmlAttr($w['value']) ?>"><?= $block->escapeHtml($w['label']) ?></option><?php endforeach; ?></select></div></div><div class="admin__field required"><label class="admin__field-label"><span><?= $block->escapeHtml(__('Currency')) ?></span></label><div class="admin__field-control"><input class="admin__control-text" name="currency" value="USD" maxlength="3" required/></div></div><div class="admin__actions"><button class="action-primary" type="submit"><span><?= $block->escapeHtml(__('Check Data')) ?></span></button></div></fieldset></form><?php if($block->hasValidatedFile()): ?><form action="<?= $block->escapeUrl($block->getUrl('esun_legacy_order/import/run')) ?>" method="post"><input name="form_key" type="hidden" value="<?= $block->escapeHtmlAttr($block->getFormKey()) ?>"/><button class="action-primary" type="submit"><span><?= $block->escapeHtml(__('Import Validated File')) ?></span></button></form><?php endif; ?></div>
@@ -0,0 +1,39 @@
<?php /** @var \Esun\LegacyOrder\Block\Adminhtml\Order\View $block */ $o=$block->getOrder();$isModal=(bool)$block->getData('modal'); ?>
<?php if(!$o): ?><div class="message error"><?= $block->escapeHtml(__('Legacy order not found.')) ?></div><?php else: $ship=$block->decode($o['shipping_address']);$bill=$block->decode($o['billing_address']);$items=$block->getItems();$money=static fn($value):string=>number_format((float)$value,2,'.',',');$discount=abs((float)($o['discount_amount']??0));$coupon=trim((string)($o['coupon']??''));$hasDiscount=$discount>0.0001||$coupon!== ''; ?>
<?php if(!$isModal): ?><div class="page-main-actions"><a class="action-default" href="<?= $block->escapeUrl($block->getUrl('esun_legacy_order/order/index')) ?>"><?= $block->escapeHtml(__('Back')) ?></a></div><?php endif; ?>
<div class="admin__page-section legacy-order-summary">
<div class="legacy-order-summary__header"><div><span><?= $block->escapeHtml(__('Historical record')) ?></span><h2><?= $block->escapeHtml(__('Legacy Order #%1',$o['source_order_number'])) ?></h2></div><div class="legacy-order-summary__total"><span><?= $block->escapeHtml(__('Grand Total')) ?></span><strong><?= $block->escapeHtml($o['currency'].' '.$money($o['grand_total'])) ?></strong></div></div>
<div class="legacy-order-summary__grid">
<div><span><?= $block->escapeHtml(__('Customer Email')) ?></span><strong><?= $block->escapeHtml($o['customer_email']) ?></strong></div>
<div><span><?= $block->escapeHtml(__('Customer Link')) ?></span><strong class="legacy-order-summary__link-status"><?= $block->escapeHtml(ucfirst((string)$o['link_status'])) ?><?= $o['customer_id']?' (#'.(int)$o['customer_id'].')':'' ?></strong></div>
<div><span><?= $block->escapeHtml(__('Order Date')) ?></span><strong><?= $block->escapeHtml($o['ordered_at']?:'-') ?></strong></div>
<div><span><?= $block->escapeHtml(__('Website ID')) ?></span><strong><?= (int)$o['website_id'] ?></strong></div>
</div>
<div class="legacy-order-summary__statuses"><?php foreach([[__('Payment Status'),$o['payment_status']],[__('Order Status'),$o['order_status']],[__('Shipping Status'),$o['shipping_status']]] as$status): ?><div><span><?= $block->escapeHtml($status[0]) ?></span><strong><?= $block->escapeHtml($status[1]?:'-') ?></strong></div><?php endforeach; ?></div>
</div>
<?php if(!$isModal): ?><div class="admin__page-section legacy-order-panel legacy-order-customer-link"><div class="admin__page-section-title"><span class="title"><?= $block->escapeHtml(__('Customer Link')) ?></span></div><div class="legacy-order-customer-link__actions"><form class="legacy-order-customer-link__form" method="post" action="<?= $block->escapeUrl($block->getUrl('esun_legacy_order/order/link')) ?>"><input type="hidden" name="form_key" value="<?= $block->escapeHtmlAttr($block->getFormKey()) ?>"/><input type="hidden" name="id" value="<?= (int)$o['legacy_order_id'] ?>"/><div><label for="legacy-customer-link"><?= $block->escapeHtml(__('Customer ID or Email')) ?></label><input id="legacy-customer-link" class="admin__control-text" type="text" name="customer" placeholder="<?= $block->escapeHtmlAttr(__('Customer ID or email in Website ID %1',$o['website_id'])) ?>" required/></div><button class="action-primary" type="submit"><?= $block->escapeHtml(__('Link Customer')) ?></button></form><?php if($o['customer_id']): ?><form method="post" action="<?= $block->escapeUrl($block->getUrl('esun_legacy_order/order/unlink')) ?>"><input type="hidden" name="form_key" value="<?= $block->escapeHtmlAttr($block->getFormKey()) ?>"/><input type="hidden" name="id" value="<?= (int)$o['legacy_order_id'] ?>"/><button class="action-secondary" type="submit" onclick="return confirm('<?= $block->escapeJs(__('Remove this customer link?')) ?>')"><?= $block->escapeHtml(__('Unlink Customer')) ?></button></form><?php endif; ?></div></div><?php endif; ?>
<div class="admin__page-section legacy-order-panel legacy-order-items"><div class="admin__page-section-title"><span class="title"><?= $block->escapeHtml(__('Items')) ?></span><span class="legacy-order-items__count"><?= count($items) ?></span></div><div class="legacy-order-items__table"><table class="data-table admin__table-primary"><thead><tr><th>SKU</th><th><?= $block->escapeHtml(__('Price')) ?></th><th><?= $block->escapeHtml(__('Qty')) ?></th><th><?= $block->escapeHtml(__('Subtotal')) ?></th></tr></thead><tbody><?php foreach($items as$i): ?><tr><td><strong><?= $block->escapeHtml($i['sku']) ?></strong></td><td><?= $block->escapeHtml($o['currency'].' '.$money($i['price'])) ?></td><td><span class="legacy-order-items__qty"><?= (int)round((float)$i['qty']) ?></span></td><td><strong><?= $block->escapeHtml($o['currency'].' '.$money($i['row_total'])) ?></strong></td></tr><?php endforeach; ?></tbody></table></div></div>
<div class="admin__page-section legacy-order-panel legacy-order-totals"><div class="admin__page-section-title"><span class="title"><?= $block->escapeHtml(__('Order Totals')) ?></span></div><table class="admin__table-secondary"><tr><th><?= $block->escapeHtml(__('Product Subtotal')) ?></th><td><?= $block->escapeHtml($o['currency'].' '.$money($o['product_total'])) ?></td></tr><?php if($hasDiscount): ?><tr class="legacy-order-totals__discount"><th><?= $block->escapeHtml(__('Discount')) ?><?php if($coupon!==''): ?> <small><?= $block->escapeHtml(__('Coupon: %1',$coupon)) ?></small><?php endif; ?></th><td>-<?= $block->escapeHtml($o['currency'].' '.$money($discount)) ?></td></tr><?php endif; ?><?php if((float)$o['shipping_amount']!==0.0): ?><tr><th><?= $block->escapeHtml(__('Shipping')) ?></th><td><?= $block->escapeHtml($o['currency'].' '.$money($o['shipping_amount'])) ?></td></tr><?php endif; ?><?php if((float)$o['tax_amount']!==0.0): ?><tr><th><?= $block->escapeHtml(__('Tax')) ?></th><td><?= $block->escapeHtml($o['currency'].' '.$money($o['tax_amount'])) ?></td></tr><?php endif; ?><?php if((float)$o['fee_amount']!==0.0): ?><tr><th><?= $block->escapeHtml(__('Fee')) ?></th><td><?= $block->escapeHtml($o['currency'].' '.$money($o['fee_amount'])) ?></td></tr><?php endif; ?><tr class="legacy-order-totals__grand"><th><?= $block->escapeHtml(__('Grand Total')) ?></th><td><?= $block->escapeHtml($o['currency'].' '.$money($o['grand_total'])) ?></td></tr></table></div>
<div class="admin__page-section legacy-order-information">
<div class="admin__page-section-title"><span class="title"><?= $block->escapeHtml(__('Order Information')) ?></span></div>
<div class="legacy-order-information__grid">
<?php foreach([[__('Shipping Address'),$ship],[__('Billing Address'),$bill]] as$addressBlock): $label=$addressBlock[0];$a=$addressBlock[1]; ?>
<section class="legacy-order-information__card">
<h3><?= $block->escapeHtml($label) ?></h3>
<address><?= /* @noEscape */ nl2br($block->escapeHtml(implode("\n",array_filter([$a['name']??'',trim(($a['street']??'').' '.($a['unit']??'')),trim(($a['city']??'').' '.($a['region']??'').' '.($a['postcode']??'')),$a['country']??'',$a['telephone']??''])))) ?></address>
</section>
<?php endforeach; ?>
<section class="legacy-order-information__card">
<h3><?= $block->escapeHtml(__('Shipping Method')) ?></h3>
<p><?= $block->escapeHtml($o['shipping_method']?:'-') ?></p>
<?php if(!empty($o['carrier'])): ?><small><?= $block->escapeHtml(__('Carrier: %1',$o['carrier'])) ?></small><?php endif; ?>
<?php if(!empty($o['tracking_number'])): ?><small><?= $block->escapeHtml(__('Tracking Number: %1',$o['tracking_number'])) ?></small><?php endif; ?>
</section>
<section class="legacy-order-information__card">
<h3><?= $block->escapeHtml(__('Payment Method')) ?></h3>
<p><?= $block->escapeHtml($o['payment_method']?:'-') ?></p>
<?php if(!empty($o['payment_transaction_id'])): ?><small><?= $block->escapeHtml(__('Transaction: %1',$o['payment_transaction_id'])) ?></small><?php endif; ?>
</section>
</div>
</div>
<?php endif; ?>
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array"><item name="js_config" xsi:type="array"><item name="provider" xsi:type="string">esun_legacy_order_listing.esun_legacy_order_listing_data_source</item></item></argument>
<settings><buttons><button name="relink"><url path="esun_legacy_order/order/relink"/><class>secondary</class><label translate="true">Relink Customers</label></button><button name="import"><url path="esun_legacy_order/import/index"/><class>primary</class><label translate="true">Import Legacy Orders</label></button></buttons><spinner>legacy_order_columns</spinner><deps><dep>esun_legacy_order_listing.esun_legacy_order_listing_data_source</dep></deps></settings>
<dataSource name="esun_legacy_order_listing_data_source" component="Magento_Ui/js/grid/provider"><settings><storageConfig><param name="indexField" xsi:type="string">legacy_order_id</param></storageConfig><updateUrl path="mui/index/render"/></settings><aclResource>Esun_LegacyOrder::orders</aclResource><dataProvider class="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider" name="esun_legacy_order_listing_data_source"><settings><requestFieldName>id</requestFieldName><primaryFieldName>legacy_order_id</primaryFieldName></settings></dataProvider></dataSource>
<listingToolbar name="listing_top"><settings><sticky>true</sticky></settings><bookmark name="bookmarks"/><columnsControls name="columns_controls"/><filters name="listing_filters"/><massaction name="listing_massaction" component="Esun_LegacyOrder/js/grid/massactions"><action name="bind_customer"><settings><url path="esun_legacy_order/order/massLink"/><type>bind_customer</type><label translate="true">Bind Customer</label></settings></action><action name="unbind_customer"><settings><confirm><message translate="true">Unbind the selected legacy orders from their customers? The historical order data will not be deleted.</message><title translate="true">Unbind Customer</title></confirm><url path="esun_legacy_order/order/massUnlink"/><type>unbind_customer</type><label translate="true">Unbind Customer</label></settings></action><action name="delete"><settings><confirm><message translate="true">Delete the selected legacy orders? Their archived item rows will also be deleted.</message><title translate="true">Delete Legacy Orders</title></confirm><url path="esun_legacy_order/order/massDelete"/><type>delete</type><label translate="true">Delete</label></settings></action></massaction><paging name="listing_paging"/></listingToolbar>
<columns name="legacy_order_columns">
<selectionsColumn name="ids" sortOrder="0"><settings><indexField>legacy_order_id</indexField></settings></selectionsColumn>
<column name="legacy_order_id" sortOrder="10"><settings><filter>textRange</filter><label>ID</label><sorting>desc</sorting></settings></column>
<column name="source_order_number"><settings><filter>text</filter><label translate="true">Legacy Order #</label></settings></column>
<column name="source_code"><settings><filter>text</filter><label translate="true">Source</label></settings></column>
<column name="customer_email"><settings><filter>text</filter><label translate="true">Customer Email</label></settings></column>
<column name="website_id"><settings><filter>textRange</filter><label translate="true">Website ID</label></settings></column>
<column name="website_name" class="Esun\LegacyOrder\Ui\Component\Listing\Column\WebsiteName"><settings><label translate="true">Website Name</label><sortable>false</sortable></settings></column>
<column name="link_status"><settings><filter>select</filter><options class="Esun\LegacyOrder\Model\Source\LinkStatus"/><label translate="true">Customer Link</label></settings></column>
<column name="payment_status"><settings><filter>text</filter><label translate="true">Payment Status</label></settings></column>
<column name="order_status"><settings><filter>text</filter><label translate="true">Order Status</label></settings></column>
<column name="grand_total"><settings><filter>textRange</filter><dataType>text</dataType><label translate="true">Grand Total</label></settings></column>
<column name="currency"><settings><filter>text</filter><label translate="true">Currency</label></settings></column>
<column name="ordered_at" class="Magento\Ui\Component\Listing\Columns\Date"><settings><filter>dateRange</filter><dataType>date</dataType><label translate="true">Order Date</label></settings></column>
<actionsColumn name="actions" class="Esun\LegacyOrder\Ui\Component\Listing\Column\Actions" component="Esun_LegacyOrder/js/grid/columns/actions"><settings><indexField>legacy_order_id</indexField></settings></actionsColumn>
</columns>
</listing>
@@ -0,0 +1,329 @@
.legacy-order-bind-customer-modal .modal-inner-wrap {
max-width: 560px;
}
.legacy-order-bind-customer-modal .admin__control-text {
margin-top: 8px;
width: 100%;
}
.legacy-order-bind-customer-modal .note {
color: #777;
margin-top: 10px;
}
.legacy-order-view-modal .modal-inner-wrap {
max-width: 1100px;
width: 80%;
}
.legacy-order-view-modal .modal-content {
background: #f5f6f7;
padding: 20px 24px 28px;
}
.legacy-order-modal-loading {
color: #777;
padding: 60px 20px;
text-align: center;
}
.legacy-order-summary {
background: linear-gradient(135deg, #282d32 0%, #3b4248 100%);
border-radius: 8px;
box-shadow: 0 8px 24px rgba(25, 31, 36, .14);
color: #fff;
overflow: hidden;
margin-bottom: 16px;
padding: 20px 24px;
}
.legacy-order-summary__header {
align-items: center;
display: flex;
justify-content: space-between;
margin-bottom: 16px;
}
.legacy-order-summary__header > div:first-child > span,
.legacy-order-summary__total > span {
color: #ffb175;
display: block;
font-size: 12px;
font-weight: 600;
letter-spacing: .08em;
text-transform: uppercase;
}
.legacy-order-summary__header h2 {
color: #fff;
font-size: 22px;
margin: 5px 0 0;
}
.legacy-order-summary__total {
text-align: right;
}
.legacy-order-summary__total strong {
display: block;
font-size: 22px;
margin-top: 4px;
}
.legacy-order-summary__grid,
.legacy-order-summary__statuses {
display: grid;
gap: 8px;
}
.legacy-order-summary__grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.legacy-order-summary__statuses {
grid-template-columns: repeat(3, minmax(0, 1fr));
margin-top: 8px;
}
.legacy-order-summary__grid > div,
.legacy-order-summary__statuses > div {
background: rgba(255, 255, 255, .08);
border: 1px solid rgba(255, 255, 255, .1);
border-radius: 6px;
min-width: 0;
padding: 10px 12px;
}
.legacy-order-summary__grid span,
.legacy-order-summary__statuses span {
color: rgba(255, 255, 255, .6);
display: block;
font-size: 11px;
margin-bottom: 6px;
text-transform: uppercase;
}
.legacy-order-summary__grid strong,
.legacy-order-summary__statuses strong {
color: #fff;
display: block;
font-size: 14px;
overflow-wrap: anywhere;
}
.legacy-order-summary__link-status {
color: #82dcaa !important;
}
.legacy-order-panel {
background: #fff;
border-radius: 6px;
box-shadow: 0 3px 14px rgba(25, 31, 36, .05);
box-sizing: border-box;
margin-bottom: 16px;
padding: 16px 20px 18px;
}
.legacy-order-panel > .admin__page-section-title {
align-items: center;
border-bottom: 1px solid #e5e5e5;
display: flex;
margin-bottom: 13px;
padding-bottom: 10px;
}
.legacy-order-customer-link__actions,
.legacy-order-customer-link__form {
align-items: flex-end;
display: flex;
gap: 12px;
}
.legacy-order-customer-link__form {
flex: 1;
}
.legacy-order-customer-link__form > div {
flex: 1;
}
.legacy-order-customer-link__form label {
display: block;
font-weight: 600;
margin-bottom: 5px;
}
.legacy-order-customer-link__form input {
height: 38px;
width: 100%;
}
.legacy-order-customer-link__form button,
.legacy-order-customer-link__actions > form button {
min-height: 38px;
white-space: nowrap;
}
.legacy-order-items__count {
align-items: center;
background: #fff0e8;
border-radius: 50%;
color: #eb5202;
display: inline-flex;
font-size: 12px;
font-weight: 700;
height: 25px;
justify-content: center;
margin-left: 10px;
width: 25px;
}
.legacy-order-items table thead th {
background: #f7f8f8;
color: #777;
font-size: 12px;
text-transform: uppercase;
}
.legacy-order-items table td,
.legacy-order-items table th {
padding: 9px 12px;
vertical-align: middle;
}
.legacy-order-items table th:nth-child(n+2),
.legacy-order-items table td:nth-child(n+2) {
text-align: right;
}
.legacy-order-items__qty {
background: #f0f1f1;
border-radius: 14px;
display: inline-block;
min-width: 22px;
padding: 3px 8px;
text-align: center;
}
.legacy-order-totals table {
margin-left: auto;
max-width: 480px;
}
.legacy-order-totals th,
.legacy-order-totals td {
padding: 5px 10px;
text-align: right;
}
.legacy-order-totals__discount th,
.legacy-order-totals__discount td {
color: #16894b;
}
.legacy-order-totals__discount small {
background: #eaf8f0;
border-radius: 3px;
margin-left: 6px;
padding: 2px 6px;
}
.legacy-order-totals__grand th,
.legacy-order-totals__grand td {
border-top: 2px solid #333;
color: #222;
font-size: 18px;
font-weight: 700;
padding-top: 10px;
}
.legacy-order-information {
background: #fff;
border-radius: 6px;
box-sizing: border-box;
margin-bottom: 16px;
padding: 16px 20px 20px;
}
.legacy-order-information .admin__page-section-title {
border-bottom: 1px solid #e3e3e3;
margin-bottom: 14px;
padding-bottom: 10px;
}
.legacy-order-information__grid {
display: grid;
gap: 12px;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.legacy-order-information__card {
background: #f7f8f8;
border: 1px solid #e2e4e4;
border-radius: 8px;
box-sizing: border-box;
min-height: 120px;
padding: 16px 18px;
}
.legacy-order-information__card h3 {
color: #262626;
font-size: 16px;
font-weight: 600;
margin: 0 0 9px;
}
.legacy-order-information__card address,
.legacy-order-information__card p {
color: #666;
font-size: 14px;
font-style: normal;
line-height: 1.45;
margin: 0;
}
.legacy-order-information__card small {
color: #999;
display: block;
font-size: 13px;
margin-top: 5px;
overflow-wrap: anywhere;
}
@media (max-width: 900px) {
.legacy-order-view-modal .modal-inner-wrap {
width: 94%;
}
.legacy-order-summary__grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.legacy-order-customer-link__actions,
.legacy-order-customer-link__form {
align-items: stretch;
flex-direction: column;
}
.legacy-order-information__grid {
grid-template-columns: 1fr;
}
}
@media (max-width: 600px) {
.legacy-order-summary__header {
align-items: flex-start;
flex-direction: column;
gap: 18px;
}
.legacy-order-summary__total {
text-align: left;
}
.legacy-order-summary__grid,
.legacy-order-summary__statuses {
grid-template-columns: 1fr;
}
}
@@ -0,0 +1,50 @@
define([
'jquery',
'Magento_Ui/js/grid/columns/actions',
'Magento_Ui/js/modal/modal',
'mage/translate'
], function ($, Actions, modal, $t) {
'use strict';
return Actions.extend({
getActionHandler: function (action) {
if (action.modal) {
return this.openLegacyOrderModal.bind(this, action);
}
return this._super(action);
},
openLegacyOrderModal: function (action) {
var $dialog = $('#legacy-order-view-modal');
if (!$dialog.length) {
$dialog = $('<div id="legacy-order-view-modal"/>').appendTo('body');
modal({
type: 'popup',
title: $t('Legacy Order Details'),
responsive: true,
innerScroll: true,
modalClass: 'legacy-order-view-modal',
buttons: []
}, $dialog);
}
$dialog.html('<div class="legacy-order-modal-loading">' + $t('Loading...') + '</div>');
$dialog.modal('openModal');
$.ajax({
url: action.href,
type: 'GET',
dataType: 'html',
showLoader: true
}).done(function (html) {
$dialog.html(html);
}).fail(function () {
$dialog.html('<div class="message message-error error"><div>' +
$t('Unable to load the legacy order details.') +
'</div></div>');
});
}
});
});
@@ -0,0 +1,98 @@
define([
'jquery',
'Magento_Ui/js/grid/massactions',
'Magento_Ui/js/modal/modal',
'Magento_Ui/js/modal/alert',
'mageUtils',
'mage/translate'
], function ($, Massactions, modal, alert, utils, $t) {
'use strict';
return Massactions.extend({
applyAction: function (actionIndex) {
if (actionIndex === 'bind_customer') {
this.openBindCustomerModal();
this.close();
return this;
}
return this._super(actionIndex);
},
openBindCustomerModal: function () {
var data = this.getSelections(),
action = this.getAction('bind_customer'),
$dialog = $('#legacy-order-bind-customer-modal'),
self = this;
if (!data || !data.total) {
alert({content: this.noItemsMsg});
return;
}
if (!$dialog.length) {
$dialog = $(
'<div id="legacy-order-bind-customer-modal">' +
'<label class="admin__field-label" for="legacy-order-mass-customer"><span>' +
$t('Customer ID or Email') +
'</span></label>' +
'<input id="legacy-order-mass-customer" class="admin__control-text" type="text" />' +
'<p class="note">' +
$t('All selected orders will be linked to the matching customer in each order website.') +
'</p></div>'
).appendTo('body');
modal({
type: 'popup',
title: $t('Bind Customer'),
responsive: true,
modalClass: 'legacy-order-bind-customer-modal',
buttons: [{
text: $t('Cancel'),
class: 'action-secondary',
click: function () {
this.closeModal();
}
}, {
text: $t('Bind Customer'),
class: 'action-primary',
click: function () {
self.submitCustomerBinding(
$dialog.data('action'),
$dialog.data('selections'),
$dialog,
this
);
}
}]
}, $dialog);
}
$dialog.data('action', action).data('selections', data);
$dialog.find('input').val('');
$dialog.modal('openModal');
window.setTimeout(function () {
$dialog.find('input').trigger('focus');
}, 100);
},
submitCustomerBinding: function (action, data, $dialog, modalInstance) {
var customer = $.trim($dialog.find('input').val()),
itemsType,
params = {};
if (!customer) {
alert({content: $t('Enter a customer ID or email.')});
return;
}
itemsType = data.excludeMode ? 'excluded' : 'selected';
params[itemsType] = Array.isArray(data[itemsType]) && data[itemsType].length ?
data[itemsType] : false;
$.extend(params, data.params || {});
params.customer = customer;
modalInstance.closeModal();
utils.submit({url: action.url, data: params});
}
});
});
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<htmlContent name="customer_edit_tab_legacy_orders_content">
<block class="Esun\LegacyOrder\Block\Adminhtml\Customer\Edit\Tab\LegacyOrders"
name="customer_edit_tab_legacy_orders"
after="orders"/>
</htmlContent>
</form>
@@ -0,0 +1,19 @@
<?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_LegacyOrder::css/legacy-orders.css"/>
</head>
<body>
<referenceBlock name="customer_account_navigation">
<block class="Esun\LegacyOrder\Block\Account\NavigationLink"
name="customer-account-navigation-legacy-orders">
<arguments>
<argument name="path" xsi:type="string">legacy_order/account/index</argument>
<argument name="label" xsi:type="string" translate="true">Historical Orders</argument>
<argument name="sortOrder" xsi:type="number">225</argument>
</arguments>
</block>
</referenceBlock>
</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">
<update handle="customer_account"/>
<body>
<referenceContainer name="content">
<block class="Esun\LegacyOrder\Block\Account\History"
name="legacy.order.history"
template="Esun_LegacyOrder::account/history.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">
<update handle="customer_account"/>
<body>
<referenceContainer name="content">
<block class="Esun\LegacyOrder\Block\Account\OrderView"
name="legacy.order.view"
template="Esun_LegacyOrder::account/view.phtml"
cacheable="false"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,44 @@
<?php
/** @var \Esun\LegacyOrder\Block\Account\History $block */
/** @var \Magento\Framework\Escaper $escaper */
$orders = $block->getOrders();
?>
<div class="legacy-orders">
<div class="message info legacy-orders__notice">
<span><?= $escaper->escapeHtml(__('This order is from the old website and is for historical reference only.')) ?></span>
</div>
<?php if (!$orders->getSize()): ?>
<div class="message info empty">
<span><?= $escaper->escapeHtml(__('No historical orders were found.')) ?></span>
</div>
<?php else: ?>
<div class="table-wrapper orders-history">
<table class="data table table-order-items history">
<caption class="table-caption"><?= $escaper->escapeHtml(__('Historical Orders')) ?></caption>
<thead>
<tr>
<th scope="col" class="col id"><?= $escaper->escapeHtml(__('Order #')) ?></th>
<th scope="col" class="col date"><?= $escaper->escapeHtml(__('Date')) ?></th>
<th scope="col" class="col status"><?= $escaper->escapeHtml(__('Status')) ?></th>
<th scope="col" class="col total"><?= $escaper->escapeHtml(__('Order Total')) ?></th>
<th scope="col" class="col actions"><?= $escaper->escapeHtml(__('Action')) ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Order #')) ?>" class="col id"><?= $escaper->escapeHtml($order->getData('source_order_number')) ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Date')) ?>" class="col date"><?= $escaper->escapeHtml($order->getData('ordered_at') ?: '-') ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Status')) ?>" class="col status"><?= $escaper->escapeHtml($order->getData('order_status') ?: '-') ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Order Total')) ?>" class="col total"><?= $escaper->escapeHtml(trim((string)$order->getData('currency') . ' ' . number_format((float)$order->getData('grand_total'), 2, '.', ','))) ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Action')) ?>" class="col actions">
<a class="action view" href="<?= $escaper->escapeUrl($block->getViewUrl((int)$order->getId())) ?>"><span><?= $escaper->escapeHtml(__('View')) ?></span></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
@@ -0,0 +1,119 @@
<?php
/** @var \Esun\LegacyOrder\Block\Account\OrderView $block */
/** @var \Magento\Framework\Escaper $escaper */
$order = $block->getOrder();
$items = $block->getItems();
$shipping = $block->decodeAddress($order['shipping_address'] ?? null);
$billing = $block->decodeAddress($order['billing_address'] ?? null);
$currency = (string)($order['currency'] ?? '');
$discountAmount = abs((float)($order['discount_amount'] ?? 0));
$couponCode = trim((string)($order['coupon'] ?? ''));
$hasDiscount = $discountAmount > 0.0001 || $couponCode !== '';
$formatMoney = static fn ($value): string => number_format((float)$value, 2, '.', ',');
$formatQty = static fn ($value): string => (string)(int)round((float)$value);
$formatAddress = static function (array $address): array {
return array_values(array_filter([
$address['name'] ?? '',
trim((string)($address['street'] ?? '') . ' ' . (string)($address['unit'] ?? '')),
trim((string)($address['city'] ?? '') . ' ' . (string)($address['region'] ?? '') . ' ' . (string)($address['postcode'] ?? '')),
$address['country'] ?? '',
$address['telephone'] ?? '',
], static fn ($value): bool => trim((string)$value) !== ''));
};
?>
<div class="legacy-order-view">
<div class="legacy-order-view__notice" role="note">
<span class="legacy-order-view__notice-icon" aria-hidden="true">i</span>
<span><?= $escaper->escapeHtml(__('This order is from the old website and is for historical reference only.')) ?></span>
</div>
<section class="legacy-order-view__hero">
<div>
<span class="legacy-order-view__eyebrow"><?= $escaper->escapeHtml(__('Historical record')) ?></span>
<h1><?= $escaper->escapeHtml(__('Order #%1', $order['source_order_number'] ?? '')) ?></h1>
<p><?= $escaper->escapeHtml(__('Placed on %1', $order['ordered_at'] ?: '-')) ?></p>
</div>
<div class="legacy-order-view__hero-total">
<span><?= $escaper->escapeHtml(__('Grand Total')) ?></span>
<strong><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($order['grand_total'] ?? 0))) ?></strong>
<a href="<?= $escaper->escapeUrl($block->getUrl('legacy_order/account/index')) ?>">
<span aria-hidden="true">←</span> <?= $escaper->escapeHtml(__('Back to Historical Orders')) ?>
</a>
</div>
</section>
<section class="legacy-order-view__status-grid" aria-label="<?= $escaper->escapeHtmlAttr(__('Order status summary')) ?>">
<?php foreach ([
[__('Order Status'), $order['order_status'] ?? null],
[__('Payment Status'), $order['payment_status'] ?? null],
[__('Shipping Status'), $order['shipping_status'] ?? null],
[__('Tracking Number'), $order['tracking_number'] ?? null],
] as [$label, $value]): ?>
<div class="legacy-order-view__status-card">
<span><?= $escaper->escapeHtml($label) ?></span>
<strong><?= $escaper->escapeHtml($value ?: '-') ?></strong>
</div>
<?php endforeach; ?>
</section>
<section class="legacy-order-view__panel legacy-order-view__items">
<header class="legacy-order-view__section-title">
<div><span><?= count($items) ?></span><h2><?= $escaper->escapeHtml(__('Items Ordered')) ?></h2></div>
</header>
<div class="table-wrapper order-items">
<table class="data table table-order-items">
<caption class="table-caption"><?= $escaper->escapeHtml(__('Items Ordered')) ?></caption>
<thead><tr><th class="col name"><?= $escaper->escapeHtml(__('Product')) ?></th><th class="col sku"><?= $escaper->escapeHtml(__('SKU')) ?></th><th class="col price"><?= $escaper->escapeHtml(__('Price')) ?></th><th class="col qty"><?= $escaper->escapeHtml(__('Qty')) ?></th><th class="col subtotal"><?= $escaper->escapeHtml(__('Subtotal')) ?></th></tr></thead>
<tbody>
<?php foreach ($items as $item): ?>
<tr>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Product')) ?>" class="col name"><strong><?= $escaper->escapeHtml($item['product_name'] ?: $item['sku']) ?></strong></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('SKU')) ?>" class="col sku"><?= $escaper->escapeHtml($item['sku']) ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Price')) ?>" class="col price"><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($item['price']))) ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Qty')) ?>" class="col qty"><span><?= $escaper->escapeHtml($formatQty($item['qty'])) ?></span></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Subtotal')) ?>" class="col subtotal"><strong><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($item['row_total']))) ?></strong></td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr><th colspan="4" scope="row"><?= $escaper->escapeHtml(__('Product Subtotal')) ?></th><td><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($order['product_total'] ?? 0))) ?></td></tr>
<?php if ($hasDiscount): ?>
<tr class="legacy-order-view__discount-row">
<th colspan="4" scope="row">
<?= $escaper->escapeHtml(__('Discount')) ?>
<?php if ($couponCode !== ''): ?><small><?= $escaper->escapeHtml(__('Coupon: %1', $couponCode)) ?></small><?php endif; ?>
</th>
<td>-<?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($discountAmount))) ?></td>
</tr>
<?php endif; ?>
<?php if ((float)($order['shipping_amount'] ?? 0) !== 0.0): ?><tr><th colspan="4" scope="row"><?= $escaper->escapeHtml(__('Shipping')) ?></th><td><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($order['shipping_amount']))) ?></td></tr><?php endif; ?>
<?php if ((float)($order['tax_amount'] ?? 0) !== 0.0): ?><tr><th colspan="4" scope="row"><?= $escaper->escapeHtml(__('Tax')) ?></th><td><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($order['tax_amount']))) ?></td></tr><?php endif; ?>
<?php if ((float)($order['fee_amount'] ?? 0) !== 0.0): ?><tr><th colspan="4" scope="row"><?= $escaper->escapeHtml(__('Fee')) ?></th><td><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($order['fee_amount']))) ?></td></tr><?php endif; ?>
<tr class="grand_total"><th colspan="4" scope="row"><?= $escaper->escapeHtml(__('Grand Total')) ?></th><td><strong><?= $escaper->escapeHtml(trim($currency . ' ' . $formatMoney($order['grand_total'] ?? 0))) ?></strong></td></tr>
</tfoot>
</table>
</div>
</section>
<section class="legacy-order-view__panel legacy-order-view__information">
<header class="legacy-order-view__section-title"><h2><?= $escaper->escapeHtml(__('Order Information')) ?></h2></header>
<div class="legacy-order-view__info-grid">
<?php foreach ([[__('Shipping Address'), $shipping], [__('Billing Address'), $billing]] as [$label, $address]): ?>
<article class="legacy-order-view__info-card">
<h3><?= $escaper->escapeHtml($label) ?></h3>
<address><?= /* @noEscape */ implode('<br>', array_map([$escaper, 'escapeHtml'], $formatAddress($address))) ?: $escaper->escapeHtml('-') ?></address>
</article>
<?php endforeach; ?>
<article class="legacy-order-view__info-card">
<h3><?= $escaper->escapeHtml(__('Shipping Method')) ?></h3>
<p><?= $escaper->escapeHtml($order['shipping_method'] ?: '-') ?></p>
<?php if (!empty($order['carrier'])): ?><small><?= $escaper->escapeHtml(__('Carrier: %1', $order['carrier'])) ?></small><?php endif; ?>
</article>
<article class="legacy-order-view__info-card">
<h3><?= $escaper->escapeHtml(__('Payment Method')) ?></h3>
<p><?= $escaper->escapeHtml($order['payment_method'] ?: '-') ?></p>
<?php if (!empty($order['payment_transaction_id'])): ?><small><?= $escaper->escapeHtml(__('Transaction: %1', $order['payment_transaction_id'])) ?></small><?php endif; ?>
</article>
</div>
</section>
</div>
@@ -0,0 +1,345 @@
.account.legacy-order-account-index.page-layout-2columns-left .column.main,
.account.legacy-order-account-view.page-layout-2columns-left .column.main {
background: transparent;
border-radius: 0;
padding: 0 !important;
}
.legacy-orders__notice,
.legacy-order-view__notice {
font-weight: 600;
margin-bottom: 24px;
}
.legacy-order-view {
color: #333;
}
.legacy-order-view__notice {
align-items: center;
background: #fff8ed;
border: 1px solid #f3d5a5;
border-radius: 8px;
color: #6f4a12;
display: flex;
gap: 12px;
padding: 15px 18px;
}
.legacy-order-view__notice-icon {
align-items: center;
background: #f28c00;
border-radius: 50%;
color: #fff;
display: inline-flex;
flex: 0 0 22px;
font-family: Georgia, serif;
font-size: 14px;
font-style: italic;
height: 22px;
justify-content: center;
}
.legacy-order-view__hero {
align-items: center;
background: linear-gradient(135deg, #282d32 0%, #3b4248 100%);
border-radius: 10px;
box-shadow: 0 10px 30px rgba(25, 31, 36, .12);
color: #fff;
display: flex;
justify-content: space-between;
margin-bottom: 20px;
min-height: 170px;
overflow: hidden;
padding: 34px 38px;
position: relative;
}
.legacy-order-view__hero::after {
border: 32px solid rgba(255, 255, 255, .04);
border-radius: 50%;
content: '';
height: 190px;
position: absolute;
right: -65px;
top: -85px;
width: 190px;
}
.legacy-order-view__eyebrow {
color: #ffb175;
display: block;
font-size: 13px;
font-weight: 700;
letter-spacing: .12em;
margin-bottom: 8px;
text-transform: uppercase;
}
.legacy-order-view__hero h1 {
color: #fff;
font-size: 32px;
font-weight: 600;
line-height: 1.2;
margin: 0 0 10px;
}
.legacy-order-view__hero p {
color: rgba(255, 255, 255, .7);
margin: 0;
}
.legacy-order-view__hero-total {
align-items: flex-end;
display: flex;
flex-direction: column;
position: relative;
z-index: 1;
}
.legacy-order-view__hero-total > span {
color: rgba(255, 255, 255, .68);
font-size: 13px;
text-transform: uppercase;
}
.legacy-order-view__hero-total strong {
color: #fff;
font-size: 30px;
line-height: 1.3;
margin: 4px 0 16px;
}
.legacy-order-view__hero-total a {
color: #ffb175;
font-size: 14px;
text-decoration: none;
}
.legacy-order-view__status-grid {
display: grid;
gap: 14px;
grid-template-columns: repeat(4, minmax(0, 1fr));
margin-bottom: 24px;
}
.legacy-order-view__status-card {
background: #fff;
border: 1px solid #e7e7e7;
border-radius: 8px;
box-shadow: 0 3px 12px rgba(25, 31, 36, .04);
min-width: 0;
padding: 18px 20px;
}
.legacy-order-view__status-card span {
color: #8a8a8a;
display: block;
font-size: 12px;
letter-spacing: .04em;
margin-bottom: 7px;
text-transform: uppercase;
}
.legacy-order-view__status-card strong {
color: #303030;
display: block;
font-size: 16px;
overflow-wrap: anywhere;
}
.legacy-order-view__panel {
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 18px rgba(25, 31, 36, .05);
margin-top: 24px;
padding: 28px 30px;
}
.legacy-order-view__section-title {
align-items: center;
border-bottom: 1px solid #ececec;
display: flex;
justify-content: space-between;
margin-bottom: 8px;
padding-bottom: 18px;
}
.legacy-order-view__section-title > div {
align-items: center;
display: flex;
gap: 11px;
}
.legacy-order-view__section-title > div > span {
align-items: center;
background: #fff0e8;
border-radius: 50%;
color: #ff5a16;
display: inline-flex;
font-size: 13px;
font-weight: 700;
height: 28px;
justify-content: center;
width: 28px;
}
.legacy-order-view__section-title h2 {
color: #222;
font-size: 22px;
font-weight: 600;
margin: 0;
}
.legacy-order-view .table-wrapper {
margin: 0;
}
.legacy-order-view .data.table > thead > tr > th {
background: #f7f8f8;
color: #777;
font-size: 12px;
letter-spacing: .04em;
padding: 15px 16px;
text-transform: uppercase;
}
.legacy-order-view .data.table > tbody > tr > td {
padding: 19px 16px;
vertical-align: middle;
}
.legacy-order-view .data.table .col.price,
.legacy-order-view .data.table .col.subtotal,
.legacy-order-view .data.table tfoot td {
text-align: right;
white-space: nowrap;
}
.legacy-order-view .data.table .col.qty {
text-align: center;
}
.legacy-order-view .data.table .col.qty span {
background: #f2f3f3;
border-radius: 15px;
display: inline-block;
min-width: 24px;
padding: 3px 9px;
}
.legacy-order-view .data.table tfoot th,
.legacy-order-view .data.table tfoot td {
border-top: 0;
font-size: 14px;
padding: 8px 16px;
}
.legacy-order-view .data.table tfoot tr:first-child th,
.legacy-order-view .data.table tfoot tr:first-child td {
border-top: 1px solid #ddd;
padding-top: 18px;
}
.legacy-order-view .data.table tfoot th {
color: #666;
font-weight: 500;
text-align: right;
}
.legacy-order-view .data.table tfoot .legacy-order-view__discount-row th,
.legacy-order-view .data.table tfoot .legacy-order-view__discount-row td {
color: #16894b;
}
.legacy-order-view__discount-row small {
background: #eaf8f0;
border-radius: 4px;
display: inline-block;
font-size: 11px;
margin-left: 7px;
padding: 3px 7px;
}
.legacy-order-view .data.table tfoot .grand_total th,
.legacy-order-view .data.table tfoot .grand_total td {
border-top: 2px solid #333;
color: #222;
font-size: 18px;
padding-top: 16px;
}
.legacy-order-view__info-grid {
display: grid;
gap: 16px;
grid-template-columns: repeat(2, minmax(0, 1fr));
padding-top: 14px;
}
.legacy-order-view__info-card {
background: #f8f9f9;
border: 1px solid #eceeee;
border-radius: 8px;
min-height: 125px;
padding: 20px 22px;
}
.legacy-order-view__info-card h3 {
color: #222;
font-size: 15px;
font-weight: 600;
margin: 0 0 12px;
}
.legacy-order-view__info-card address,
.legacy-order-view__info-card p {
color: #666;
font-style: normal;
line-height: 1.7;
margin: 0;
}
.legacy-order-view__info-card small {
color: #999;
display: block;
margin-top: 8px;
overflow-wrap: anywhere;
}
@media (max-width: 900px) {
.legacy-order-view__status-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 767px) {
.legacy-order-view__hero {
align-items: flex-start;
flex-direction: column;
gap: 28px;
padding: 26px 22px;
}
.legacy-order-view__hero-total {
align-items: flex-start;
}
.legacy-order-view__hero h1 {
font-size: 25px;
}
.legacy-order-view__status-grid,
.legacy-order-view__info-grid {
grid-template-columns: 1fr;
}
.legacy-order-view__panel {
padding: 22px 18px;
}
.legacy-order-view .data.table .col.price,
.legacy-order-view .data.table .col.subtotal,
.legacy-order-view .data.table .col.qty {
text-align: right;
}
}