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,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[];}}}