init
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user